Skip to content

Commit

Permalink
Merge pull request #27 from Nlkomaru/version-2.0
Browse files Browse the repository at this point in the history
Added web linkage functionality.
  • Loading branch information
Nlkomaru authored Dec 6, 2022
2 parents ba82d3e + 45bf346 commit 21e3fc5
Show file tree
Hide file tree
Showing 69 changed files with 3,362 additions and 935 deletions.
96 changes: 68 additions & 28 deletions build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import net.minecrell.pluginyml.bukkit.BukkitPluginDescription.Permission.Default
import org.jetbrains.kotlin.gradle.tasks.KotlinCompile

plugins {
id("java")
Expand All @@ -25,8 +26,9 @@ repositories {
maven("https://repo.incendo.org/content/repositories/snapshots")
}

val cloudVersion = "1.6.2"
val cloudVersion = "1.7.1"
val exposedVersion = "0.38.2"
val ktorVersion = "2.1.0"
dependencies {
compileOnly("io.papermc.paper", "paper-api", "1.19-R0.1-SNAPSHOT")

Expand All @@ -43,28 +45,43 @@ dependencies {

implementation("com.github.stefvanschie.inventoryframework", "IF", "0.10.6")

implementation("mysql", "mysql-connector-java", "8.0.30")

implementation("io.ktor", "ktor-server-core", ktorVersion)
implementation("io.ktor", "ktor-server-netty", ktorVersion)
implementation("io.ktor", "ktor-server-content-negotiation", ktorVersion)
implementation("io.ktor", "ktor-serialization-kotlinx-json", ktorVersion)
implementation("io.ktor", "ktor-server-auth", ktorVersion)
implementation("io.ktor", "ktor-server-auth-jwt", ktorVersion)
implementation("io.ktor", "ktor-network-tls-certificates", ktorVersion)

implementation("ch.qos.logback", "logback-classic", "1.2.11")

implementation("org.jetbrains.exposed", "exposed-core", exposedVersion)
implementation("org.jetbrains.exposed", "exposed-dao", exposedVersion)
implementation("org.jetbrains.exposed", "exposed-jdbc", exposedVersion)
implementation("org.jetbrains.exposed", "exposed-java-time", exposedVersion)

implementation("org.jetbrains.kotlinx:kotlinx-datetime:0.4.0")
implementation("org.jetbrains.kotlinx", "kotlinx-datetime", "0.4.0")

implementation("org.jetbrains.kotlinx", "kotlinx-coroutines-core", "1.6.2")

implementation("com.github.shynixn.mccoroutine", "mccoroutine-bukkit-api", "2.2.0")
implementation("com.github.shynixn.mccoroutine", "mccoroutine-bukkit-core", "2.2.0")
implementation("org.jetbrains.kotlinx", "kotlinx-coroutines-core", "1.6.4")

implementation("org.jetbrains.kotlinx", "kotlinx-serialization-json", "1.3.3")
implementation("org.jetbrains.kotlinx", "kotlinx-serialization-hocon", "1.3.3")

implementation("com.github.shynixn.mccoroutine", "mccoroutine-bukkit-api", "2.7.0")
implementation("com.github.shynixn.mccoroutine", "mccoroutine-bukkit-core", "2.7.0")

implementation("com.google.api-client", "google-api-client", "1.35.1")
implementation("com.google.oauth-client", "google-oauth-client-jetty", "1.34.1")
implementation("com.google.apis", "google-api-services-sheets", "v4-rev20220606-1.32.1")

implementation("com.squareup.okhttp3", "okhttp", "4.10.0")

bukkitLibrary("com.google.code.gson", "gson", "2.8.7")

compileOnly("xyz.jpenilla", "squaremap-api", "1.1.8")
implementation(kotlin("stdlib-jdk8"))
}

java {
Expand Down Expand Up @@ -102,45 +119,68 @@ bukkit {

apiVersion = "1.19"
depend = listOf("Vault")
libraries = listOf("com.github.shynixn.mccoroutine:mccoroutine-bukkit-api:2.2.0", "com.github.shynixn.mccoroutine:mccoroutine-bukkit-core:2.2.0")
libraries = listOf("com.github.shynixn.mccoroutine:mccoroutine-bukkit-api:2.7.0", "com.github.shynixn.mccoroutine:mccoroutine-bukkit-core:2.7.0")


permissions {
register("RaceAssist.admin") {
default = Default.OP
children = listOf("raceassist.commands.audience.join",
"raceassist.commands.audience.leave",
"raceassist.commands.audience.list",
children = listOf("raceassist.commands.audience.leave",
"raceassist.commands.place.degree",
"raceassist.commands.bet.sheet",
"raceassist.commands.race.start",
"raceassist.commands.player.add",
"raceassist.commands.horse.ownerdelete",
"raceassist.commands.bet.can",
"raceassist.commands.bet.delete",
"raceassist.commands.setting.copy",
"raceassist.commands.player.remove",
"raceassist.commands.bet.list",
"raceassist.commands.bet.delete",
"raceassist.commands.setting.view",
"raceassist.commands.place.central",
"raceassist.commands.audience.list",
"raceassist.commands.setting.staff",
"raceassist.commands.setting.create",
"raceassist.commands.bet.open",
"raceassist.commands.bet.rate",
"raceassist.commands.bet.revert",
"raceassist.commands.bet.return",
"raceassist.commands.bet.remove",
"raceassist.commands.bet.sheet",
"raceassist.commands.place.reverse",
"raceassist.commands.place.central",
"raceassist.commands.place.degree",
"raceassist.commands.place.lap",
"raceassist.commands.bet.revert.jockey",
"raceassist.commands.reload",
"raceassist.commands.web",
"raceassist.commands.place.set",
"raceassist.commands.place.finish",
"raceassist.commands.player.add",
"raceassist.commands.player.remove",
"raceassist.commands.player.delete",
"raceassist.commands.player.list",
"raceassist.commands.race.start",
"raceassist.commands.race.debug",
"raceassist.commands.race.stop",
"raceassist.commands.setting.create",
"raceassist.commands.race.horse",
"raceassist.commands.bet.revert.row",
"raceassist.commands.place.finish",
"raceassist.commands.bet.return.jockey",
"raceassist.commands.setting.delete",
"raceassist.commands.setting.copy",
"raceassist.commands.setting.staff")
"raceassist.commands.race.stop",
"raceassist.commands.bet.unit",
"raceassist.commands.bet.revert.all",
"raceassist.commands.place.lap",
"raceassist.commands.bet.rate",
"raceassist.commands.player.replacement",
"raceassist.commands.audience.join",
"raceassist.command.help")
}
register("RaceAssist.user") {
default = Default.TRUE
children = listOf("raceassist.commands.audience.join", "raceassist.commands.audience.leave", "raceassist.commands.bet.open")
children = listOf(
"raceassist.commands.audience.join",
"raceassist.commands.audience.leave",
"raceassist.commands.bet.open",
"raceassist.commands.web",
"raceassist.commands.horse.ownerdelete",
)
}
}
}
val compileKotlin: KotlinCompile by tasks
compileKotlin.kotlinOptions {
jvmTarget = "1.8"
}
val compileTestKotlin: KotlinCompile by tasks
compileTestKotlin.kotlinOptions {
jvmTarget = "1.8"
}
110 changes: 96 additions & 14 deletions src/main/kotlin/dev/nikomaru/raceassist/RaceAssist.kt
Original file line number Diff line number Diff line change
Expand Up @@ -22,15 +22,16 @@ import cloud.commandframework.execution.AsynchronousCommandExecutionCoordinator
import cloud.commandframework.kotlin.coroutines.annotations.installCoroutineSupport
import cloud.commandframework.meta.SimpleCommandMeta
import cloud.commandframework.paper.PaperCommandManager
import com.github.shynixn.mccoroutine.bukkit.SuspendingJavaPlugin
import com.github.shynixn.mccoroutine.bukkit.registerSuspendingEvents
import com.github.shynixn.mccoroutine.bukkit.*
import dev.nikomaru.raceassist.api.VaultAPI
import dev.nikomaru.raceassist.bet.commands.*
import dev.nikomaru.raceassist.bet.event.BetGuiClickEvent
import dev.nikomaru.raceassist.data.database.BetList
import dev.nikomaru.raceassist.data.database.UserAuthData
import dev.nikomaru.raceassist.files.Config
import dev.nikomaru.raceassist.horse.commands.OwnerDeleteCommand
import dev.nikomaru.raceassist.horse.events.HorseBreedEvent
import dev.nikomaru.raceassist.horse.events.HorseKillEvent
import dev.nikomaru.raceassist.race.commands.HelpCommand
import dev.nikomaru.raceassist.race.commands.ReloadCommand
import dev.nikomaru.raceassist.race.commands.audience.*
Expand All @@ -39,15 +40,22 @@ import dev.nikomaru.raceassist.race.commands.player.*
import dev.nikomaru.raceassist.race.commands.race.*
import dev.nikomaru.raceassist.race.commands.setting.*
import dev.nikomaru.raceassist.race.event.*
import dev.nikomaru.raceassist.utils.CommandSuggestions
import dev.nikomaru.raceassist.utils.Lang
import dev.nikomaru.raceassist.utils.*
import dev.nikomaru.raceassist.utils.coroutines.async
import dev.nikomaru.raceassist.utils.coroutines.minecraft
import kotlinx.coroutines.withContext
import dev.nikomaru.raceassist.web.WebCommand
import dev.nikomaru.raceassist.web.api.WebAPI
import kotlinx.coroutines.*
import kotlinx.serialization.ExperimentalSerializationApi
import org.apache.commons.lang.StringUtils
import org.bukkit.command.CommandSender
import org.jetbrains.exposed.sql.SchemaUtils
import org.jetbrains.exposed.sql.*
import org.jetbrains.exposed.sql.transactions.transaction
import java.io.File
import java.io.InputStreamReader
import java.nio.charset.StandardCharsets
import java.nio.file.Files
import java.util.*

class RaceAssist : SuspendingJavaPlugin() {

Expand All @@ -59,17 +67,55 @@ class RaceAssist : SuspendingJavaPlugin() {
Config.load()
settingDatabase()
setCommand()
loadResources()
registerEvents()
withContext(minecraft) {
withContext(Dispatchers.minecraft) {
VaultAPI.setupEconomy()
}
settingWebAPI()
}

private fun settingWebAPI() {
if (Config.config.webAPI != null) {
if (Config.config.mySQL == null) {
plugin.logger.warning("MySQLが設定されていないため、WebAPIを起動できません。")
return
}
launch {
async(Dispatchers.async) {
WebAPI.startServer()
}
}
}
}

private suspend fun loadResources() {
withContext(Dispatchers.IO) {
val conf = Properties()
conf.load(InputStreamReader(this.javaClass.classLoader.getResourceAsStream("MapColorDefault.properties")!!, "UTF-8"))
Utils.mapColor = conf
}
}

private fun settingDatabase() {
org.jetbrains.exposed.sql.Database.connect(url = "jdbc:sqlite:${plugin.dataFolder}${File.separator}RaceAssist.db", driver = "org.sqlite.JDBC")
transaction {
SchemaUtils.create(BetList)
if (Config.config.mySQL != null) {
Class.forName("com.mysql.cj.jdbc.Driver")
Database.connect(url = "jdbc:mysql://${Config.config.mySQL!!.url}",
driver = "com.mysql.cj.jdbc.Driver",
user = Config.config.mySQL!!.username,
password = Config.config.mySQL!!.password)

transaction {
SchemaUtils.create(BetList, UserAuthData)
}
} else {
Database.connect(url = "jdbc:sqlite:${plugin.dataFolder}${File.separator}RaceAssist.db", driver = "org.sqlite.JDBC")

transaction {
SchemaUtils.create(BetList)
}
}

}

override fun onDisable() {
Expand All @@ -84,7 +130,7 @@ class RaceAssist : SuspendingJavaPlugin() {
java.util.function.Function.identity())


if (commandManager.queryCapability(CloudBukkitCapabilities.ASYNCHRONOUS_COMPLETION)) {
if (commandManager.hasCapability(CloudBukkitCapabilities.ASYNCHRONOUS_COMPLETION)) {
commandManager.registerAsynchronousCompletions()
}

Expand All @@ -100,11 +146,12 @@ class RaceAssist : SuspendingJavaPlugin() {
parse(AudienceListCommand())

parse(PlaceCentralCommand())
parse(PlaceCreateCommand())
parse(PlaceDegreeCommand())
parse(PlaceFinishCommand())
parse(PlaceLapCommand())
parse(PlaceReverseCommand())
parse(PlaceSetCommand())
parse(PlaceStaffCommand())

parse(PlayerAddCommand())
parse(PlayerDeleteCommand())
Expand All @@ -115,6 +162,7 @@ class RaceAssist : SuspendingJavaPlugin() {
parse(RaceStartCommand())
parse(RaceStopCommand())
parse(RaceDebugCommand())
parse(RaceHorseCommand())

parse(BetCanCommand())
parse(BetDeleteCommand())
Expand All @@ -123,19 +171,52 @@ class RaceAssist : SuspendingJavaPlugin() {
parse(BetRateCommand())
parse(BetRevertCommand())
parse(BetSheetCommand())
parse(BetReturnCommand())
parse(BetPayCommand())
parse(BetUnitCommand())

parse(SettingCopyCommand())
parse(SettingCreateCommand())
parse(SettingDeleteCommand())
parse(SettingCopyCommand())
parse(SettingLapCommand())
parse(SettingPlaceIdCommand())
parse(SettingReplacemcntCommand())
parse(SettingStaffCommand())
parse(SettingViewCommand())

parse(HelpCommand())
parse(ReloadCommand())

parse(OwnerDeleteCommand())

}
if (Config.config.webAPI != null) {
with(annotationParser) {
parse(WebCommand())
}
}

val debug = false
if (debug) {
val commandFile = File("D:\\Desktop\\commands.txt")
val commandList = mutableListOf<String>()
val permissionList = hashSetOf<String>()
commandManager.commands.stream().forEach { command ->
var string = ""
command.arguments.forEach {
val argment = when (it::class.java.simpleName) {
"CommandArgument" -> "<${it.name}>"
else -> it.name
}
string += "$argment "
}
string = StringUtils.removeEnd(string, " ")
commandList.add("` $string ` <br>")
permissionList.add("\"${command.commandPermission}\"")
commandList.add("permission: ` ${command.commandPermission} ` <br>")
commandList.add("")
}
println(permissionList)
Files.write(commandFile.toPath(), commandList, StandardCharsets.UTF_8)
}
}

Expand All @@ -145,6 +226,7 @@ class RaceAssist : SuspendingJavaPlugin() {
server.pluginManager.registerSuspendingEvents(SetCentralPointEvent(), this)
server.pluginManager.registerSuspendingEvents(BetGuiClickEvent(), this)
server.pluginManager.registerSuspendingEvents(HorseBreedEvent(), this)
server.pluginManager.registerSuspendingEvents(HorseKillEvent(), this)
}

companion object {
Expand Down
7 changes: 2 additions & 5 deletions src/main/kotlin/dev/nikomaru/raceassist/bet/BetUtils.kt
Original file line number Diff line number Diff line change
Expand Up @@ -104,18 +104,15 @@ object BetUtils {
}

//払い戻し
suspend fun returnBet(jockey: OfflinePlayer, raceId: String, sender: CommandSender, locale: Locale) {
suspend fun payDividend(jockey: OfflinePlayer, raceId: String, sender: CommandSender, locale: Locale) {
val odds = getOdds(raceId, jockey)
val eco = VaultAPI.getEconomy()

newSuspendedTransaction(Dispatchers.IO) {
BetList.select { (BetList.jockey eq jockey.name.toString()) and (BetList.raceId eq raceId) }.forEach {

val returnAmount = it[BetList.betting] * odds
val retunrPlayer = Bukkit.getOfflinePlayer(it[BetList.playerUUID].toUUID())

withContext(minecraft) {

withContext(Dispatchers.minecraft) {
eco.depositPlayer(retunrPlayer, returnAmount)
eco.withdrawPlayer(RaceSettingData.getOwner(raceId), returnAmount)
}
Expand Down
Loading

0 comments on commit 21e3fc5

Please sign in to comment.