From 1a4e5f89f95be97c89866dc6f570108109230f0d Mon Sep 17 00:00:00 2001 From: Nikomaru Date: Fri, 12 Aug 2022 22:10:41 +0900 Subject: [PATCH] Added functions such as saving race results for web app. --- .github/workflows/build_and_deploy.yml | 2 + build.gradle.kts | 69 ++--- .../dev/nikomaru/raceassist/RaceAssist.kt | 86 +++--- .../api/sheet/GoogleAuthorizeUtil.kt | 3 +- .../dev/nikomaru/raceassist/bet/BetUtils.kt | 118 ++++++++- .../nikomaru/raceassist/bet/GuiComponent.kt | 5 +- .../raceassist/bet/commands/BetCanCommand.kt | 25 +- .../bet/commands/BetDeleteCommand.kt | 16 +- .../raceassist/bet/commands/BetListCommand.kt | 41 ++- .../raceassist/bet/commands/BetOpenCommand.kt | 31 +-- .../raceassist/bet/commands/BetRateCommand.kt | 25 +- .../bet/commands/BetRemoveCommand.kt | 86 ------ .../bet/commands/BetReturnCommand.kt | 119 +-------- .../bet/commands/BetRevertCommand.kt | 134 +++++++--- .../bet/commands/BetSheetCommand.kt | 29 +- .../raceassist/bet/commands/BetUnitCommand.kt | 42 +++ .../raceassist/bet/event/BetGuiClickEvent.kt | 20 +- .../raceassist/bet/gui/BetChestGui.kt | 28 +- .../raceassist/data/database/BetListData.kt | 23 ++ .../raceassist/data/files/RaceUtils.kt | 29 +- .../dispatch/discord/DiscordWebhook.kt | 59 ----- .../dev/nikomaru/raceassist/files/Config.kt | 13 +- .../nikomaru/raceassist/files/ConfigData.kt | 12 +- .../horse/commands/OwnerDeleteCommand.kt | 4 +- .../raceassist/race/RaceResultData.kt | 60 +++++ .../raceassist/race/commands/HelpCommand.kt | 94 +------ .../raceassist/race/commands/ReloadCommand.kt | 37 +++ .../commands/audience/AudienceJoinCommand.kt | 4 +- .../commands/audience/AudienceLeaveCommand.kt | 4 +- .../commands/audience/AudienceListCommand.kt | 15 +- .../commands/place/PlaceCentralCommand.kt | 10 +- .../race/commands/place/PlaceDegreeCommand.kt | 10 +- .../race/commands/place/PlaceFinishCommand.kt | 6 +- .../race/commands/place/PlaceLapCommand.kt | 6 +- .../commands/place/PlaceReverseCommand.kt | 6 +- .../race/commands/place/PlaceSetCommand.kt | 14 +- .../race/commands/player/PlayerAddCommand.kt | 11 +- .../commands/player/PlayerDeleteCommand.kt | 11 +- .../race/commands/player/PlayerListCommand.kt | 6 +- .../commands/player/PlayerRemoveCommand.kt | 15 +- .../player/PlayerReplacementCommand.kt | 55 ++++ .../race/commands/race/RaceDebugCommand.kt | 18 +- .../race/commands/race/RaceStartCommand.kt | 248 ++++++++++++++---- .../race/commands/race/RaceStopCommand.kt | 8 +- .../commands/setting/SettingCopyCommand.kt | 2 +- .../commands/setting/SettingCreateCommand.kt | 4 +- .../commands/setting/SettingDeleteCommand.kt | 6 +- .../setting/SettingReplacemcntCommand.kt | 21 +- .../commands/setting/SettingStaffCommand.kt | 25 +- .../commands/setting/SettingViewCommand.kt | 56 ++++ .../race/event/SetCentralPointEvent.kt | 4 +- .../race/event/SetInsideCircuitEvent.kt | 4 +- .../race/event/SetOutsideCircuitEvent.kt | 4 +- .../raceassist/race/utils/InsideCircuit.kt | 4 +- .../raceassist/race/utils/OutsideCircuit.kt | 6 +- .../dev/nikomaru/raceassist/utils/Lang.kt | 2 +- .../utils/{CommandUtils.kt => Utils.kt} | 53 ++-- src/main/resources/lang/de_DE.properties | 113 -------- src/main/resources/lang/fr_FR.properties | 113 -------- src/main/resources/lang/ja_JP.properties | 20 +- src/main/resources/lang/ko_KR.properties | 113 -------- src/main/resources/lang/zh_CN.properties | 113 -------- src/main/resources/lang/zh_TW.properties | 113 -------- 63 files changed, 1036 insertions(+), 1397 deletions(-) delete mode 100644 src/main/kotlin/dev/nikomaru/raceassist/bet/commands/BetRemoveCommand.kt create mode 100644 src/main/kotlin/dev/nikomaru/raceassist/bet/commands/BetUnitCommand.kt create mode 100644 src/main/kotlin/dev/nikomaru/raceassist/data/database/BetListData.kt delete mode 100644 src/main/kotlin/dev/nikomaru/raceassist/dispatch/discord/DiscordWebhook.kt create mode 100644 src/main/kotlin/dev/nikomaru/raceassist/race/RaceResultData.kt create mode 100644 src/main/kotlin/dev/nikomaru/raceassist/race/commands/ReloadCommand.kt create mode 100644 src/main/kotlin/dev/nikomaru/raceassist/race/commands/player/PlayerReplacementCommand.kt create mode 100644 src/main/kotlin/dev/nikomaru/raceassist/race/commands/setting/SettingViewCommand.kt rename src/main/kotlin/dev/nikomaru/raceassist/utils/{CommandUtils.kt => Utils.kt} (76%) delete mode 100644 src/main/resources/lang/de_DE.properties delete mode 100644 src/main/resources/lang/fr_FR.properties delete mode 100644 src/main/resources/lang/ko_KR.properties delete mode 100644 src/main/resources/lang/zh_CN.properties delete mode 100644 src/main/resources/lang/zh_TW.properties diff --git a/.github/workflows/build_and_deploy.yml b/.github/workflows/build_and_deploy.yml index 440473f..c16d8b8 100644 --- a/.github/workflows/build_and_deploy.yml +++ b/.github/workflows/build_and_deploy.yml @@ -18,6 +18,8 @@ jobs: - uses: release-drafter/release-drafter@v5 id: release-drafter + with: + publish: true env: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} diff --git a/build.gradle.kts b/build.gradle.kts index 43bce78..87852fb 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -41,11 +41,15 @@ dependencies { implementation("cloud.commandframework", "cloud-kotlin-coroutines-annotations", cloudVersion) implementation("cloud.commandframework", "cloud-kotlin-coroutines", cloudVersion) + implementation("com.github.stefvanschie.inventoryframework", "IF", "0.10.6") + 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-coroutines-core", "1.6.2") implementation("com.github.shynixn.mccoroutine", "mccoroutine-bukkit-api", "2.2.0") @@ -58,6 +62,8 @@ dependencies { 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") } @@ -76,12 +82,13 @@ tasks { shadowJar { relocate("cloud.commandframework", "dev.nikomaru.receassist.shaded.cloud") relocate("io.leangen.geantyref", "dev.nikomaru.receassist.shaded.typetoken") + relocate("com.github.stefvanschie.inventoryframework", "dev.nikomaru.receassist.inventoryframework") } build { dependsOn(shadowJar) } runServer { - minecraftVersion("1.19") + minecraftVersion("1.19.2") } } @@ -101,39 +108,39 @@ bukkit { permissions { register("RaceAssist.admin") { default = Default.OP - children = listOf("RaceAssist.commands.audience.join", - "RaceAssist.commands.audience.leave", - "RaceAssist.commands.audience.list", - "RaceAssist.commands.bet.can", - "RaceAssist.commands.bet.delete", - "RaceAssist.commands.bet.list", - "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.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.setting.delete", - "RaceAssist.commands.setting.copy", - "RaceAssist.commands.setting.staff") + children = listOf("raceassist.commands.audience.join", + "raceassist.commands.audience.leave", + "raceassist.commands.audience.list", + "raceassist.commands.bet.can", + "raceassist.commands.bet.delete", + "raceassist.commands.bet.list", + "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.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.setting.delete", + "raceassist.commands.setting.copy", + "raceassist.commands.setting.staff") } 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") } } } \ No newline at end of file diff --git a/src/main/kotlin/dev/nikomaru/raceassist/RaceAssist.kt b/src/main/kotlin/dev/nikomaru/raceassist/RaceAssist.kt index 11105a5..bbed6a6 100644 --- a/src/main/kotlin/dev/nikomaru/raceassist/RaceAssist.kt +++ b/src/main/kotlin/dev/nikomaru/raceassist/RaceAssist.kt @@ -32,6 +32,7 @@ import dev.nikomaru.raceassist.files.Config import dev.nikomaru.raceassist.horse.commands.OwnerDeleteCommand import dev.nikomaru.raceassist.horse.events.HorseBreedEvent import dev.nikomaru.raceassist.race.commands.HelpCommand +import dev.nikomaru.raceassist.race.commands.ReloadCommand import dev.nikomaru.raceassist.race.commands.audience.* import dev.nikomaru.raceassist.race.commands.place.* import dev.nikomaru.raceassist.race.commands.player.* @@ -91,46 +92,51 @@ class RaceAssist : SuspendingJavaPlugin() { SimpleCommandMeta.empty() }.installCoroutineSupport() - annotationParser.parse(CommandSuggestions()) - - annotationParser.parse(AudienceJoinCommand()) - annotationParser.parse(AudienceLeaveCommand()) - annotationParser.parse(AudienceListCommand()) - - annotationParser.parse(PlaceCentralCommand()) - annotationParser.parse(PlaceDegreeCommand()) - annotationParser.parse(PlaceFinishCommand()) - annotationParser.parse(PlaceLapCommand()) - annotationParser.parse(PlaceReverseCommand()) - annotationParser.parse(PlaceSetCommand()) - - annotationParser.parse(PlayerAddCommand()) - annotationParser.parse(PlayerDeleteCommand()) - annotationParser.parse(PlayerListCommand()) - annotationParser.parse(PlayerRemoveCommand()) - - annotationParser.parse(RaceStartCommand()) - annotationParser.parse(RaceStopCommand()) - annotationParser.parse(RaceDebugCommand()) - - annotationParser.parse(BetCanCommand()) - annotationParser.parse(BetDeleteCommand()) - annotationParser.parse(BetListCommand()) - annotationParser.parse(BetOpenCommand()) - annotationParser.parse(BetRateCommand()) - annotationParser.parse(BetRevertCommand()) - annotationParser.parse(BetSheetCommand()) - annotationParser.parse(BetRemoveCommand()) - annotationParser.parse(BetReturnCommand()) - - annotationParser.parse(SettingCreateCommand()) - annotationParser.parse(SettingDeleteCommand()) - annotationParser.parse(SettingCopyCommand()) - annotationParser.parse(SettingStaffCommand()) - - annotationParser.parse(HelpCommand()) - - annotationParser.parse(OwnerDeleteCommand()) + with(annotationParser) { + parse(CommandSuggestions()) + + parse(AudienceJoinCommand()) + parse(AudienceLeaveCommand()) + parse(AudienceListCommand()) + + parse(PlaceCentralCommand()) + parse(PlaceDegreeCommand()) + parse(PlaceFinishCommand()) + parse(PlaceLapCommand()) + parse(PlaceReverseCommand()) + parse(PlaceSetCommand()) + + parse(PlayerAddCommand()) + parse(PlayerDeleteCommand()) + parse(PlayerListCommand()) + parse(PlayerRemoveCommand()) + parse(PlayerReplacementCommand()) + + parse(RaceStartCommand()) + parse(RaceStopCommand()) + parse(RaceDebugCommand()) + + parse(BetCanCommand()) + parse(BetDeleteCommand()) + parse(BetListCommand()) + parse(BetOpenCommand()) + parse(BetRateCommand()) + parse(BetRevertCommand()) + parse(BetSheetCommand()) + parse(BetReturnCommand()) + parse(BetUnitCommand()) + + parse(SettingCreateCommand()) + parse(SettingDeleteCommand()) + parse(SettingCopyCommand()) + parse(SettingStaffCommand()) + parse(SettingViewCommand()) + + parse(HelpCommand()) + parse(ReloadCommand()) + + parse(OwnerDeleteCommand()) + } } private fun registerEvents() { diff --git a/src/main/kotlin/dev/nikomaru/raceassist/api/sheet/GoogleAuthorizeUtil.kt b/src/main/kotlin/dev/nikomaru/raceassist/api/sheet/GoogleAuthorizeUtil.kt index ea2d634..72f3d1b 100644 --- a/src/main/kotlin/dev/nikomaru/raceassist/api/sheet/GoogleAuthorizeUtil.kt +++ b/src/main/kotlin/dev/nikomaru/raceassist/api/sheet/GoogleAuthorizeUtil.kt @@ -27,6 +27,7 @@ import com.google.api.client.json.gson.GsonFactory import com.google.api.client.util.store.FileDataStoreFactory import com.google.api.services.sheets.v4.SheetsScopes import dev.nikomaru.raceassist.RaceAssist.Companion.plugin +import dev.nikomaru.raceassist.files.Config import java.io.* import java.security.GeneralSecurityException @@ -49,6 +50,6 @@ object GoogleAuthorizeUtil { val flow: GoogleAuthorizationCodeFlow = GoogleAuthorizationCodeFlow.Builder(GoogleNetHttpTransport.newTrustedTransport(), GsonFactory.getDefaultInstance(), clientSecrets, scopes) .setDataStoreFactory(FileDataStoreFactory(tokensDirectoryPath)).setAccessType("offline").build() - return AuthorizationCodeInstalledApp(flow, LocalServerReceiver.Builder().setPort(8888).build()).authorize("user") + return AuthorizationCodeInstalledApp(flow, LocalServerReceiver.Builder().setPort(Config.config.spreadSheet.port).build()).authorize("user") } } \ No newline at end of file diff --git a/src/main/kotlin/dev/nikomaru/raceassist/bet/BetUtils.kt b/src/main/kotlin/dev/nikomaru/raceassist/bet/BetUtils.kt index 5721903..ec9100c 100644 --- a/src/main/kotlin/dev/nikomaru/raceassist/bet/BetUtils.kt +++ b/src/main/kotlin/dev/nikomaru/raceassist/bet/BetUtils.kt @@ -17,4 +17,120 @@ package dev.nikomaru.raceassist.bet -object BetUtils {} \ No newline at end of file +import dev.nikomaru.raceassist.api.VaultAPI +import dev.nikomaru.raceassist.bet.data.TempBetData +import dev.nikomaru.raceassist.bet.gui.BetChestGui +import dev.nikomaru.raceassist.data.database.BetList +import dev.nikomaru.raceassist.data.database.BetListData +import dev.nikomaru.raceassist.data.files.BetSettingData +import dev.nikomaru.raceassist.data.files.RaceSettingData +import dev.nikomaru.raceassist.utils.Lang +import dev.nikomaru.raceassist.utils.Utils.locale +import dev.nikomaru.raceassist.utils.Utils.toUUID +import dev.nikomaru.raceassist.utils.coroutines.minecraft +import kotlinx.coroutines.Dispatchers +import kotlinx.coroutines.withContext +import org.bukkit.Bukkit +import org.bukkit.OfflinePlayer +import org.bukkit.command.CommandSender +import org.bukkit.entity.Player +import org.jetbrains.exposed.sql.* +import org.jetbrains.exposed.sql.transactions.experimental.newSuspendedTransaction +import java.math.RoundingMode +import java.util.* + +object BetUtils { + + val TempBetDatas = ArrayList() + + suspend fun deleteBetData(raceId: String) { + newSuspendedTransaction(Dispatchers.IO) { + BetList.deleteWhere { BetList.raceId eq raceId } + } + } + + fun removeTempBetData(player: Player) { + val removeList = arrayListOf() + TempBetDatas.stream().filter { it.player == player }.forEach { removeList.add(it) } + removeList.forEach { TempBetDatas.remove(it) } + } + + fun initializeTempBetData(raceId: String, sender: Player) { + BetChestGui.AllPlayers[raceId]?.forEach { jockey -> + TempBetDatas.add(TempBetData(raceId, sender, jockey, 0)) + } + } + + suspend fun listBetData(raceId: String): ArrayList { + val list = arrayListOf() + newSuspendedTransaction(Dispatchers.IO) { + BetList.select { BetList.raceId eq raceId }.forEach { + list.add(BetListData(it[BetList.rowNum], + it[BetList.timeStamp], + it[BetList.playerUUID].toUUID(), + it[BetList.jockeyUUID].toUUID(), + it[BetList.betting])) + } + } + return list + } + + suspend fun getBetSum(raceId: String) = newSuspendedTransaction(Dispatchers.IO) { + BetList.select { BetList.raceId eq raceId }.sumOf { + it[BetList.betting] + } + } + + suspend fun getJockeyBetSum(raceId: String, jockey: OfflinePlayer) = newSuspendedTransaction(Dispatchers.IO) { + BetList.select { (BetList.jockeyUUID eq jockey.uniqueId.toString()) and (BetList.raceId eq raceId) }.sumOf { it[BetList.betting] } + } + + suspend fun getRowBet(raceId: String, row: Int) = newSuspendedTransaction(Dispatchers.IO) { + BetList.select { (BetList.rowNum eq row) and (BetList.raceId eq raceId) }.sumOf { it[BetList.betting] } + } + + suspend fun playerCanPay(raceId: String, amount: Int, executor: CommandSender): Boolean { + val eco = VaultAPI.getEconomy() + val owner = RaceSettingData.getOwner(raceId) + val can = eco.getBalance(owner) >= amount + if (!can) { + val locale = executor.locale() + executor.sendMessage(Lang.getComponent("no-have-money", locale)) + if (owner is Player) { + owner.sendMessage(Lang.getComponent("no-have-money-owner", owner.locale())) + } + } + return can + } + + //払い戻し + suspend fun returnBet(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) { + + eco.depositPlayer(retunrPlayer, returnAmount) + eco.withdrawPlayer(RaceSettingData.getOwner(raceId), returnAmount) + } + sender.sendMessage(Lang.getComponent("paid-bet-creator", locale, retunrPlayer.name, returnAmount)) + retunrPlayer.player?.sendMessage(Lang.getComponent("paid-bet-player", locale, raceId, retunrPlayer.name, jockey.name, returnAmount)) + } + BetList.deleteWhere { BetList.raceId eq raceId } + } + } + + suspend fun getOdds(raceId: String, jockey: OfflinePlayer): Double { + val sum = getBetSum(raceId) + val jockeySum = if (getJockeyBetSum(raceId, jockey) == 0) 0.0001 else getJockeyBetSum(raceId, jockey).toDouble() + val rate = BetSettingData.getReturnPercent(raceId).toDouble() / 100 + return ((sum * rate) / jockeySum).toBigDecimal().setScale(2, RoundingMode.DOWN).toDouble() + } + +} \ No newline at end of file diff --git a/src/main/kotlin/dev/nikomaru/raceassist/bet/GuiComponent.kt b/src/main/kotlin/dev/nikomaru/raceassist/bet/GuiComponent.kt index 03421e8..1875c84 100644 --- a/src/main/kotlin/dev/nikomaru/raceassist/bet/GuiComponent.kt +++ b/src/main/kotlin/dev/nikomaru/raceassist/bet/GuiComponent.kt @@ -17,6 +17,7 @@ package dev.nikomaru.raceassist.bet +import com.github.stefvanschie.inventoryframework.gui.GuiItem import dev.nikomaru.raceassist.data.files.BetSettingData import dev.nikomaru.raceassist.utils.Lang import net.kyori.adventure.text.Component @@ -90,7 +91,7 @@ object GuiComponent { fun noBet(locale: Locale): ItemStack { val noBet = ItemStack(Material.BARRIER) val noBetMeta: ItemMeta = noBet.itemMeta - noBetMeta.displayName(Lang.getComponent("gui-no-one-betting", locale)) + noBetMeta.displayName(Lang.getComponent("no-one-betting", locale)) noBet.itemMeta = noBetMeta return noBet } @@ -111,5 +112,7 @@ object GuiComponent { return noHaveMoney } + val noDataGrass = GuiItem(ItemStack(Material.GRAY_STAINED_GLASS_PANE)) + } diff --git a/src/main/kotlin/dev/nikomaru/raceassist/bet/commands/BetCanCommand.kt b/src/main/kotlin/dev/nikomaru/raceassist/bet/commands/BetCanCommand.kt index bfd1a67..d77521c 100644 --- a/src/main/kotlin/dev/nikomaru/raceassist/bet/commands/BetCanCommand.kt +++ b/src/main/kotlin/dev/nikomaru/raceassist/bet/commands/BetCanCommand.kt @@ -19,40 +19,35 @@ package dev.nikomaru.raceassist.bet.commands import cloud.commandframework.annotations.* import dev.nikomaru.raceassist.data.files.BetSettingData -import dev.nikomaru.raceassist.utils.CommandUtils import dev.nikomaru.raceassist.utils.Lang +import dev.nikomaru.raceassist.utils.Utils +import dev.nikomaru.raceassist.utils.Utils.locale import org.bukkit.command.CommandSender -import org.bukkit.entity.Player -import java.util.* @CommandMethod("ra|RaceAssist bet") class BetCanCommand { - @CommandPermission("RaceAssist.commands.bet.can") + @CommandPermission("raceassist.commands.bet.can") @CommandMethod("can ") + @CommandDescription("そのレースに対しての賭けることが可能か設定します") suspend fun setCanBet(sender: CommandSender, @Argument(value = "raceId", suggestions = "raceId") raceId: String, @Argument(value = "type", suggestions = "betType") type: String) { - if (CommandUtils.returnRaceSetting(raceId, sender)) return + if (Utils.returnCanRaceSetting(raceId, sender)) return if (type == "on") { setCanBet(raceId, sender) } else if (type == "off") { setCannotBet(raceId, sender) } - } private suspend fun setCanBet(raceId: String, sender: CommandSender) { BetSettingData.setAvailable(raceId, true) - val locale = if (sender is Player) sender.locale() else Locale.getDefault() - sender.sendMessage(Lang.getComponent("can-bet-this-raceid", locale, raceId)) + sender.sendMessage(Lang.getComponent("can-bet-this-raceid", sender.locale(), raceId)) } - companion object { - suspend fun setCannotBet(raceId: String, sender: CommandSender) { - BetSettingData.setAvailable(raceId, false) - - val locale = if (sender is Player) sender.locale() else Locale.getDefault() - sender.sendMessage(Lang.getComponent("cannot-bet-this-raceid", locale, raceId)) - } + private suspend fun setCannotBet(raceId: String, sender: CommandSender) { + BetSettingData.setAvailable(raceId, false) + sender.sendMessage(Lang.getComponent("cannot-bet-this-raceid", sender.locale(), raceId)) } + } \ No newline at end of file diff --git a/src/main/kotlin/dev/nikomaru/raceassist/bet/commands/BetDeleteCommand.kt b/src/main/kotlin/dev/nikomaru/raceassist/bet/commands/BetDeleteCommand.kt index d8e38f6..62a1249 100644 --- a/src/main/kotlin/dev/nikomaru/raceassist/bet/commands/BetDeleteCommand.kt +++ b/src/main/kotlin/dev/nikomaru/raceassist/bet/commands/BetDeleteCommand.kt @@ -18,29 +18,25 @@ package dev.nikomaru.raceassist.bet.commands import cloud.commandframework.annotations.* -import dev.nikomaru.raceassist.data.database.BetList -import dev.nikomaru.raceassist.utils.CommandUtils +import dev.nikomaru.raceassist.bet.BetUtils import dev.nikomaru.raceassist.utils.Lang -import kotlinx.coroutines.Dispatchers +import dev.nikomaru.raceassist.utils.Utils import org.bukkit.command.CommandSender import org.bukkit.entity.Player -import org.jetbrains.exposed.sql.deleteWhere -import org.jetbrains.exposed.sql.transactions.experimental.newSuspendedTransaction @CommandMethod("ra|RaceAssist bet") class BetDeleteCommand { - @CommandPermission("RaceAssist.commands.bet.delete") + @CommandPermission("raceassist.commands.bet.delete") @CommandMethod("delete ") @Confirmation + @CommandDescription("レースに対して駆けられているものを削除します") suspend fun delete(sender: CommandSender, @Argument(value = "raceId", suggestions = "raceId") raceId: String) { if (sender !is Player) { sender.sendMessage("Only the player can do this.") return } - if (CommandUtils.returnRaceSetting(raceId, sender)) return - newSuspendedTransaction(Dispatchers.IO) { - BetList.deleteWhere { BetList.raceId eq raceId } - } + if (Utils.returnCanRaceSetting(raceId, sender)) return + BetUtils.deleteBetData(raceId) sender.sendMessage(Lang.getComponent("bet-remove-race", sender.locale(), raceId)) } diff --git a/src/main/kotlin/dev/nikomaru/raceassist/bet/commands/BetListCommand.kt b/src/main/kotlin/dev/nikomaru/raceassist/bet/commands/BetListCommand.kt index a549aa6..d481f82 100644 --- a/src/main/kotlin/dev/nikomaru/raceassist/bet/commands/BetListCommand.kt +++ b/src/main/kotlin/dev/nikomaru/raceassist/bet/commands/BetListCommand.kt @@ -18,37 +18,30 @@ package dev.nikomaru.raceassist.bet.commands import cloud.commandframework.annotations.* -import dev.nikomaru.raceassist.data.database.BetList -import dev.nikomaru.raceassist.utils.CommandUtils +import dev.nikomaru.raceassist.bet.BetUtils import dev.nikomaru.raceassist.utils.Lang -import kotlinx.coroutines.Dispatchers +import dev.nikomaru.raceassist.utils.Utils +import dev.nikomaru.raceassist.utils.Utils.locale +import org.bukkit.Bukkit import org.bukkit.command.CommandSender -import org.bukkit.entity.Player -import org.jetbrains.exposed.sql.select -import org.jetbrains.exposed.sql.transactions.experimental.newSuspendedTransaction -import java.util.* @CommandMethod("ra|RaceAssist bet") class BetListCommand { - @CommandPermission("RaceAssist.commands.bet.list") + @CommandPermission("raceassist.commands.bet.list") @CommandMethod("list ") + @CommandDescription("現在賭けられている一覧を表示します") suspend fun list(sender: CommandSender, @Argument(value = "raceId", suggestions = "raceId") raceId: String) { - - val locale = if (sender is Player) sender.locale() else Locale.getDefault() - - if (CommandUtils.returnRaceSetting(raceId, sender)) return - newSuspendedTransaction(Dispatchers.IO) { - BetList.select { BetList.raceId eq raceId }.forEach { - sender.sendMessage(Lang.getComponent("bet-list-detail-message", - locale, - it[BetList.rowNum], - it[BetList.timeStamp], - it[BetList.playerName], - it[BetList.jockey], - it[BetList.betting])) - } + val locale = sender.locale() + if (Utils.returnCanRaceSetting(raceId, sender)) return + val list = BetUtils.listBetData(raceId) + if (list.isEmpty()) { + sender.sendMessage(Lang.getComponent("no-one-betting", locale)) + return + } + list.forEach { + val jockeyName = Bukkit.getOfflinePlayer(it.jockeyUUID).name + val betPlayerName = Bukkit.getOfflinePlayer(it.playerUUID).name + sender.sendMessage(Lang.getComponent("bet-list-detail-message", locale, it.rowNum, it.timeStamp, betPlayerName, jockeyName, it.betting)) } - } - } \ No newline at end of file diff --git a/src/main/kotlin/dev/nikomaru/raceassist/bet/commands/BetOpenCommand.kt b/src/main/kotlin/dev/nikomaru/raceassist/bet/commands/BetOpenCommand.kt index 6d89fd5..df15c73 100644 --- a/src/main/kotlin/dev/nikomaru/raceassist/bet/commands/BetOpenCommand.kt +++ b/src/main/kotlin/dev/nikomaru/raceassist/bet/commands/BetOpenCommand.kt @@ -18,7 +18,7 @@ package dev.nikomaru.raceassist.bet.commands import cloud.commandframework.annotations.* -import dev.nikomaru.raceassist.bet.data.TempBetData +import dev.nikomaru.raceassist.bet.BetUtils import dev.nikomaru.raceassist.bet.gui.BetChestGui import dev.nikomaru.raceassist.data.files.BetSettingData import dev.nikomaru.raceassist.data.files.RaceSettingData @@ -30,44 +30,27 @@ import org.bukkit.entity.Player @CommandMethod("ra|RaceAssist bet") class BetOpenCommand { - @CommandPermission("RaceAssist.commands.bet.open") + @CommandPermission("raceassist.commands.bet.open") @CommandMethod("open ") + @CommandDescription("賭けるためのGUIを表示します") suspend fun openVending(sender: CommandSender, @Argument(value = "raceId", suggestions = "raceId") raceId: String) { if (sender !is Player) { sender.sendMessage("Only the player can do this.") return } - if (!RaceSettingData.existsRace(raceId)) { sender.sendMessage(Lang.getComponent("no-exist-this-raceid-race", sender.locale())) return } - val vending = BetChestGui() - val canBet = BetSettingData.getAvailable(raceId) - if (!canBet) { + if (!BetSettingData.getAvailable(raceId)) { sender.sendMessage(Lang.getComponent("now-cannot-bet-race", sender.locale())) return } - - val iterator = TempBetDatas.iterator() - while (iterator.hasNext()) { - val it = iterator.next() - if (it.player == sender) { - iterator.remove() - } - } + BetUtils.removeTempBetData(sender) withContext(minecraft) { - sender.openInventory(vending.getGUI(sender, raceId)) - } - - - BetChestGui.AllPlayers[raceId]?.forEach { jockey -> - TempBetDatas.add(TempBetData(raceId, sender, jockey, 0)) + sender.openInventory(BetChestGui().getGUI(sender, raceId)) } - + BetUtils.initializeTempBetData(raceId, sender) } - companion object { - val TempBetDatas = ArrayList() - } } \ No newline at end of file diff --git a/src/main/kotlin/dev/nikomaru/raceassist/bet/commands/BetRateCommand.kt b/src/main/kotlin/dev/nikomaru/raceassist/bet/commands/BetRateCommand.kt index db32d2b..50d62ee 100644 --- a/src/main/kotlin/dev/nikomaru/raceassist/bet/commands/BetRateCommand.kt +++ b/src/main/kotlin/dev/nikomaru/raceassist/bet/commands/BetRateCommand.kt @@ -20,33 +20,22 @@ package dev.nikomaru.raceassist.bet.commands import cloud.commandframework.annotations.* import cloud.commandframework.annotations.specifier.Range import dev.nikomaru.raceassist.data.files.BetSettingData -import dev.nikomaru.raceassist.utils.CommandUtils.returnRaceSetting import dev.nikomaru.raceassist.utils.Lang -import kotlinx.coroutines.Dispatchers +import dev.nikomaru.raceassist.utils.Utils.locale +import dev.nikomaru.raceassist.utils.Utils.returnCanRaceSetting import org.bukkit.command.CommandSender -import org.bukkit.entity.Player -import org.jetbrains.exposed.sql.transactions.experimental.newSuspendedTransaction -import java.util.* @CommandMethod("ra|RaceAssist bet") class BetRateCommand { - @CommandPermission("RaceAssist.commands.bet.rate") + @CommandPermission("raceassist.commands.bet.rate") @CommandMethod("rate ") + @CommandDescription("レースの賭けのレートを設定します") suspend fun setRate(sender: CommandSender, @Argument(value = "raceId", suggestions = "raceId") raceId: String, @Argument(value = "rate") @Range(min = "0", max = "100") rate: Int) { - val locale = if (sender is Player) sender.locale() else Locale.getDefault() - - if (returnRaceSetting(raceId, sender)) return - if (rate !in 1..100) { - sender.sendMessage(Lang.getComponent("set-rate-message-in1-100", locale)) - return - } - newSuspendedTransaction(Dispatchers.IO) { - BetSettingData.setReturnPercent(raceId, rate) - } - + val locale = sender.locale() + if (returnCanRaceSetting(raceId, sender)) return + BetSettingData.setReturnPercent(raceId, rate) sender.sendMessage(Lang.getComponent("change-bet-rate-message", locale, raceId, rate)) } - } \ No newline at end of file diff --git a/src/main/kotlin/dev/nikomaru/raceassist/bet/commands/BetRemoveCommand.kt b/src/main/kotlin/dev/nikomaru/raceassist/bet/commands/BetRemoveCommand.kt deleted file mode 100644 index b486a7d..0000000 --- a/src/main/kotlin/dev/nikomaru/raceassist/bet/commands/BetRemoveCommand.kt +++ /dev/null @@ -1,86 +0,0 @@ -/* - * Copyright © 2021-2022 Nikomaru - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ - -package dev.nikomaru.raceassist.bet.commands - -import cloud.commandframework.annotations.* -import dev.nikomaru.raceassist.api.VaultAPI -import dev.nikomaru.raceassist.data.database.BetList -import dev.nikomaru.raceassist.utils.CommandUtils.returnRaceSetting -import dev.nikomaru.raceassist.utils.Lang -import dev.nikomaru.raceassist.utils.coroutines.minecraft -import kotlinx.coroutines.Dispatchers -import kotlinx.coroutines.withContext -import net.milkbowl.vault.economy.Economy -import org.bukkit.Bukkit -import org.bukkit.command.CommandSender -import org.bukkit.entity.Player -import org.jetbrains.exposed.sql.* -import org.jetbrains.exposed.sql.transactions.experimental.newSuspendedTransaction -import java.util.* - -@CommandMethod("ra|RaceAssist bet") -class BetRemoveCommand { - @CommandPermission("RaceAssist.commands.bet.revert") - @CommandMethod("remove ") - suspend fun remove(sender: CommandSender, - @Argument(value = "raceId", suggestions = "raceId") raceId: String, - @Argument(value = "betId") betId: Int) { - if (sender !is Player) { - sender.sendMessage("Only the player can do this.") - return - } - val eco: Economy = VaultAPI.getEconomy() - - withContext(Dispatchers.IO) { - if (returnRaceSetting(raceId, sender)) return@withContext - if (eco.getBalance(sender) < getBetSum(raceId)) { - sender.sendMessage(Lang.getComponent("no-have-money", sender.locale())) - return@withContext - } - } - newSuspendedTransaction(Dispatchers.IO) { - BetList.select { (BetList.rowNum eq betId) and (BetList.raceId eq raceId) }.forEach { - val receiver = Bukkit.getOfflinePlayer(UUID.fromString(it[BetList.playerUUID].toString())) - withContext(minecraft) { - eco.withdrawPlayer(sender, it[BetList.betting].toDouble()) - eco.depositPlayer(receiver, it[BetList.betting].toDouble()) - } - sender.sendMessage(Lang.getComponent("bet-revert-return-message-owner", sender.locale(), receiver.name, it[BetList.betting])) - - if (receiver.isOnline) { - (receiver as Player).sendMessage(Lang.getComponent("bet-revert-return-message-player", - receiver.locale(), - sender.name, - it[BetList.raceId], - it[BetList.jockey], - it[BetList.betting])) - } - - } - - BetList.deleteWhere { (BetList.rowNum eq betId) and (BetList.raceId eq raceId) } - } - - } - - private suspend fun getBetSum(raceId: String) = newSuspendedTransaction(Dispatchers.IO) { - BetList.select { BetList.raceId eq raceId }.sumOf { - it[BetList.betting] - } - } -} \ No newline at end of file diff --git a/src/main/kotlin/dev/nikomaru/raceassist/bet/commands/BetReturnCommand.kt b/src/main/kotlin/dev/nikomaru/raceassist/bet/commands/BetReturnCommand.kt index b927977..f3c624f 100644 --- a/src/main/kotlin/dev/nikomaru/raceassist/bet/commands/BetReturnCommand.kt +++ b/src/main/kotlin/dev/nikomaru/raceassist/bet/commands/BetReturnCommand.kt @@ -18,122 +18,31 @@ package dev.nikomaru.raceassist.bet.commands import cloud.commandframework.annotations.* -import dev.nikomaru.raceassist.api.VaultAPI -import dev.nikomaru.raceassist.data.database.BetList -import dev.nikomaru.raceassist.data.database.BetList.jockey -import dev.nikomaru.raceassist.data.files.BetSettingData +import dev.nikomaru.raceassist.bet.BetUtils import dev.nikomaru.raceassist.data.files.RaceSettingData import dev.nikomaru.raceassist.utils.Lang -import dev.nikomaru.raceassist.utils.coroutines.minecraft -import kotlinx.coroutines.* +import dev.nikomaru.raceassist.utils.Utils.locale import org.bukkit.Bukkit -import org.bukkit.OfflinePlayer import org.bukkit.command.CommandSender -import org.bukkit.entity.Player -import org.jetbrains.exposed.sql.* -import org.jetbrains.exposed.sql.transactions.experimental.newSuspendedTransaction -import java.util.* -import kotlin.math.floor @CommandMethod("ra|RaceAssist bet") class BetReturnCommand { - @CommandPermission("RaceAssist.commands.bet.return") + + @CommandPermission("raceassist.commands.bet.return.jockey") @CommandMethod("return ") - suspend fun returnBet(sender: CommandSender, + @CommandDescription("払い戻し用のコマンド") + @Confirmation + suspend fun returnJockey(sender: CommandSender, @Argument(value = "raceId", suggestions = "raceId") raceId: String, @Argument(value = "playerName", suggestions = "playerName") playerName: String) { - val locale = if (sender is Player) sender.locale() else Locale.getDefault() - val player = Bukkit.getOfflinePlayerIfCached(playerName) ?: return sender.sendMessage(Lang.getComponent("player-add-not-exist", locale)) - - - if (!existPlayer(raceId, player)) { - sender.sendMessage(Lang.getComponent("player-not-jockey", locale, player.name)) + val locale = sender.locale() + val jockey = Bukkit.getOfflinePlayerIfCached(playerName) ?: return sender.sendMessage(Lang.getComponent("player-add-not-exist", locale)) + if (!RaceSettingData.getJockeys(raceId).contains(jockey)) { + sender.sendMessage(Lang.getComponent("player-not-jockey", locale, jockey.name)) return } - var sum = 0 - newSuspendedTransaction(Dispatchers.IO) { - BetList.select { BetList.raceId eq raceId }.forEach { - sum += it[BetList.betting] - } - } - val rate: Int = BetSettingData.getReturnPercent(raceId) - var jockeySum = 0 - newSuspendedTransaction(Dispatchers.IO) { - BetList.select { (BetList.jockeyUUID eq player.uniqueId.toString()) and (BetList.raceId eq raceId) }.forEach { - jockeySum += it[BetList.betting] - } - } - - val odds = floor(((sum * (rate.toDouble() / 100)) / jockeySum) * 100) / 100 - - if (canReturn[raceId] == true) { - payRefund(player, raceId, sender, locale) - } else { - canReturn[raceId] = true - newSuspendedTransaction(Dispatchers.IO) { - BetList.select { (jockey eq player.name.toString()) and (BetList.raceId eq raceId) }.forEach { - val returnAmount = it[BetList.betting] * odds - val retunrPlayer = Bukkit.getOfflinePlayer(UUID.fromString(it[BetList.playerUUID])) - sender.sendMessage(Lang.getComponent("pay-confirm-bet-player", - locale, - retunrPlayer.name, - player.name, - it[BetList.betting], - returnAmount)) - } - } - sender.sendMessage(Lang.getComponent("return-confirm-message", locale)) - delay(5000) - canReturn.remove(raceId) - } - - } - - private suspend fun existPlayer(raceId: String, player: OfflinePlayer): Boolean { - return RaceSettingData.getJockeys(raceId).contains(player) - } - - companion object { - val canReturn: HashMap = HashMap() - - suspend fun payRefund(player: OfflinePlayer, raceId: String, sender: CommandSender, locale: Locale) { - var sum = 0 - newSuspendedTransaction(Dispatchers.IO) { - BetList.select { BetList.raceId eq raceId }.forEach { - sum += it[BetList.betting] - } - } - - val rate: Int = BetSettingData.getReturnPercent(raceId) - var jockeySum = 0 - newSuspendedTransaction(Dispatchers.IO) { - BetList.select { (jockey eq player.name.toString()) and (BetList.raceId eq raceId) }.forEach { - jockeySum += it[BetList.betting] - } - } - - val odds = floor(((sum * (rate.toDouble() / 100)) / jockeySum) * 100) / 100 - - newSuspendedTransaction(Dispatchers.IO) { - BetList.select { (jockey eq player.name.toString()) and (BetList.raceId eq raceId) }.forEach { - val returnAmount = it[BetList.betting] * odds - val retunrPlayer = Bukkit.getOfflinePlayer(UUID.fromString(it[BetList.playerUUID])) - withContext(minecraft) { - val eco = VaultAPI.getEconomy() - eco.depositPlayer(retunrPlayer, returnAmount) - eco.withdrawPlayer(RaceSettingData.getOwner(raceId), returnAmount) - } - sender.sendMessage(Lang.getComponent("paid-bet-creator", locale, retunrPlayer.name, returnAmount)) - retunrPlayer.player?.sendMessage(Lang.getComponent("paid-bet-player", - locale, - raceId, - retunrPlayer.name, - player.name, - returnAmount)) - } - BetList.deleteWhere { BetList.raceId eq raceId } - } - sender.sendMessage(Lang.getComponent("finish-pay", locale)) - } + if (!BetUtils.playerCanPay(raceId, BetUtils.getBetSum(raceId), sender)) return + BetUtils.returnBet(jockey, raceId, sender, locale) + sender.sendMessage(Lang.getComponent("finish-pay", locale)) } } \ No newline at end of file diff --git a/src/main/kotlin/dev/nikomaru/raceassist/bet/commands/BetRevertCommand.kt b/src/main/kotlin/dev/nikomaru/raceassist/bet/commands/BetRevertCommand.kt index da62afd..694d41c 100644 --- a/src/main/kotlin/dev/nikomaru/raceassist/bet/commands/BetRevertCommand.kt +++ b/src/main/kotlin/dev/nikomaru/raceassist/bet/commands/BetRevertCommand.kt @@ -19,67 +19,123 @@ package dev.nikomaru.raceassist.bet.commands import cloud.commandframework.annotations.* import dev.nikomaru.raceassist.api.VaultAPI +import dev.nikomaru.raceassist.bet.BetUtils import dev.nikomaru.raceassist.data.database.BetList import dev.nikomaru.raceassist.data.files.RaceSettingData -import dev.nikomaru.raceassist.utils.CommandUtils.returnRaceSetting import dev.nikomaru.raceassist.utils.Lang +import dev.nikomaru.raceassist.utils.Utils +import dev.nikomaru.raceassist.utils.Utils.locale +import dev.nikomaru.raceassist.utils.Utils.toUUID import dev.nikomaru.raceassist.utils.coroutines.minecraft import kotlinx.coroutines.Dispatchers import kotlinx.coroutines.withContext -import net.milkbowl.vault.economy.Economy import org.bukkit.Bukkit +import org.bukkit.OfflinePlayer import org.bukkit.command.CommandSender import org.bukkit.entity.Player -import org.jetbrains.exposed.sql.deleteWhere -import org.jetbrains.exposed.sql.select +import org.jetbrains.exposed.sql.* import org.jetbrains.exposed.sql.transactions.experimental.newSuspendedTransaction -import java.util.* -@CommandMethod("ra|RaceAssist bet") +@CommandMethod("ra|RaceAssist bet revert") class BetRevertCommand { - @CommandPermission("RaceAssist.commands.bet.revert") - @CommandMethod("revert ") - suspend fun revert(sender: CommandSender, @Argument(value = "raceId", suggestions = "raceId") raceId: String) { - val eco: Economy = VaultAPI.getEconomy() - val owner = RaceSettingData.getOwner(raceId) - val locale = if (sender is Player) sender.locale() else Locale.getDefault() - withContext(Dispatchers.IO) { - if (returnRaceSetting(raceId, sender)) return@withContext - if (eco.getBalance(owner) < getBetSum(raceId)) { - sender.sendMessage(Lang.getComponent("no-have-money", locale)) - return@withContext - } - } + @CommandPermission("raceassist.commands.bet.revert.row") + @CommandMethod("row ") + @CommandDescription("そのレースの指定した番号の行のベットを返金します") + @Confirmation + suspend fun returnRow(sender: CommandSender, + @Argument(value = "raceId", suggestions = "raceId") raceId: String, + @Argument(value = "row") row: Int) { + if (Utils.returnCanRaceSetting(raceId, sender)) return + if (!BetUtils.playerCanPay(raceId, BetUtils.getRowBet(raceId, row), sender)) return + returnRowBet(row, raceId, sender) + sender.sendMessage(Lang.getComponent("bet-revert-complete-message", sender.locale())) + } + + @CommandPermission("raceassist.commands.bet.revert.jockey") + @CommandMethod("player ") + @CommandDescription("そのレースに対して特定のプレイヤーのものを返金します") + @Confirmation + suspend fun returnPlayer(sender: CommandSender, + @Argument(value = "raceId", suggestions = "raceId") raceId: String, + @Argument(value = "playerName", suggestions = "playerName") playerName: String) { + if (Utils.returnCanRaceSetting(raceId, sender)) return + val jockey = + Bukkit.getOfflinePlayerIfCached(playerName) ?: return sender.sendMessage(Lang.getComponent("player-add-not-exist", sender.locale())) + if (!RaceSettingData.getJockeys(raceId).contains(jockey)) { + sender.sendMessage(Lang.getComponent("player-not-jockey", sender.locale(), jockey.name)) + return + } + if (!BetUtils.playerCanPay(raceId, BetUtils.getJockeyBetSum(raceId, jockey), sender)) return + returnPlayerBet(raceId, jockey, sender) + sender.sendMessage(Lang.getComponent("bet-revert-complete-message", sender.locale())) + } + @CommandPermission("raceassist.commands.bet.revert.all") + @CommandMethod("all ") + @CommandDescription("そのレースに対して賭けられたものをすべて返金します") + @Confirmation + suspend fun returnAll(sender: CommandSender, @Argument(value = "raceId", suggestions = "raceId") raceId: String) { + if (Utils.returnCanRaceSetting(raceId, sender)) return + if (!BetUtils.playerCanPay(raceId, BetUtils.getBetSum(raceId), sender)) return + revertAllBet(raceId, sender) + sender.sendMessage(Lang.getComponent("bet-revert-complete-message", sender.locale())) + } + private suspend fun revertAllBet(raceId: String, executor: CommandSender) { + val owner = RaceSettingData.getOwner(raceId) newSuspendedTransaction(Dispatchers.IO) { - BetList.select { BetList.raceId eq raceId }.forEach { - val receiver = Bukkit.getOfflinePlayer(UUID.fromString(it[BetList.playerUUID])) - withContext(minecraft) { - eco.withdrawPlayer(owner, it[BetList.betting].toDouble()) - eco.depositPlayer(receiver, it[BetList.betting].toDouble()) - } - sender.sendMessage(Lang.getComponent("bet-revert-return-message-owner", locale, receiver.name, it[BetList.betting])) - if (receiver.isOnline) { - (receiver as Player).sendMessage(Lang.getComponent("bet-revert-return-message-player", - receiver.locale(), - owner.name, - it[BetList.raceId], - it[BetList.jockey], - it[BetList.betting])) - } + val receiver = Bukkit.getOfflinePlayer(it[BetList.playerUUID].toUUID()) + transferMoney(owner, receiver, it[BetList.betting].toDouble()) + executor.sendMessage(Lang.getComponent("bet-revert-return-message-owner", executor.locale(), receiver.name, it[BetList.betting])) + sendRevertMessage(receiver, owner, it) } BetList.deleteWhere { BetList.raceId eq raceId } } - sender.sendMessage(Lang.getComponent("bet-revert-complete-message", locale, raceId)) + } + + private suspend fun returnPlayerBet(raceId: String, jockey: OfflinePlayer, executor: CommandSender) { + val owner = RaceSettingData.getOwner(raceId) + newSuspendedTransaction(Dispatchers.IO) { + BetList.select { (BetList.raceId eq raceId) and (BetList.playerUUID eq jockey.uniqueId.toString()) }.forEach { + val receiver = Bukkit.getOfflinePlayer(it[BetList.playerUUID].toUUID()) + transferMoney(owner, receiver, it[BetList.betting].toDouble()) + executor.sendMessage(Lang.getComponent("bet-revert-return-message-owner", executor.locale(), receiver.name, it[BetList.betting])) + sendRevertMessage(receiver, owner, it) + } + BetList.deleteWhere { (BetList.raceId eq raceId) and (BetList.playerUUID eq jockey.uniqueId.toString()) } + } + } + + private suspend fun returnRowBet(row: Int, raceId: String, executor: CommandSender) { + val owner = RaceSettingData.getOwner(raceId) + val locale = executor.locale() + newSuspendedTransaction(Dispatchers.IO) { + BetList.select { (BetList.rowNum eq row) and (BetList.raceId eq raceId) }.forEach { + val receiver = Bukkit.getOfflinePlayer(it[BetList.playerUUID].toUUID()) + transferMoney(owner, receiver, it[BetList.betting].toDouble()) + executor.sendMessage(Lang.getComponent("bet-revert-return-message-owner", locale, receiver.name, it[BetList.betting])) + sendRevertMessage(receiver, owner, it) + } + BetList.deleteWhere { (BetList.rowNum eq row) and (BetList.raceId eq raceId) } + } + } + private suspend fun transferMoney(sender: OfflinePlayer, receiver: OfflinePlayer, amount: Double) = withContext(minecraft) { + val eco = VaultAPI.getEconomy() + eco.withdrawPlayer(sender, amount) + eco.depositPlayer(receiver, amount) } - private suspend fun getBetSum(raceId: String) = newSuspendedTransaction(Dispatchers.IO) { - BetList.select { BetList.raceId eq raceId }.sumOf { - it[BetList.betting] + private fun sendRevertMessage(receiver: OfflinePlayer, owner: OfflinePlayer, it: ResultRow) { + if (receiver.isOnline) { + (receiver as Player).sendMessage(Lang.getComponent("bet-revert-return-message-player", + receiver.locale(), + owner.name, + it[BetList.raceId], + it[BetList.jockey], + it[BetList.betting])) } } -} +} \ No newline at end of file diff --git a/src/main/kotlin/dev/nikomaru/raceassist/bet/commands/BetSheetCommand.kt b/src/main/kotlin/dev/nikomaru/raceassist/bet/commands/BetSheetCommand.kt index 8aa9678..d5fabf0 100644 --- a/src/main/kotlin/dev/nikomaru/raceassist/bet/commands/BetSheetCommand.kt +++ b/src/main/kotlin/dev/nikomaru/raceassist/bet/commands/BetSheetCommand.kt @@ -21,20 +21,21 @@ import cloud.commandframework.annotations.* import com.google.api.services.sheets.v4.model.* import dev.nikomaru.raceassist.api.sheet.SheetsServiceUtil.getSheetsService import dev.nikomaru.raceassist.data.files.BetSettingData -import dev.nikomaru.raceassist.utils.CommandUtils.returnRaceSetting +import dev.nikomaru.raceassist.utils.Utils.returnCanRaceSetting import kotlinx.coroutines.Dispatchers import kotlinx.coroutines.withContext import org.bukkit.command.CommandSender @CommandMethod("ra|RaceAssist bet") class BetSheetCommand { - @CommandPermission("RaceAssist.commands.bet.sheet") + @CommandPermission("raceassist.commands.bet.sheet") @CommandMethod("sheet ") + @CommandDescription("現在の賭け状況を閲覧できるシートを設定します") suspend fun sheet(sender: CommandSender, @Argument(value = "raceId", suggestions = "raceId") raceId: String, @Argument(value = "sheet") sheetId: String) { withContext(Dispatchers.IO) { - if (returnRaceSetting(raceId, sender)) return@withContext + if (returnCanRaceSetting(raceId, sender)) return@withContext } BetSettingData.setSpreadSheetId(raceId, sheetId) createNewSheets(sheetId, raceId) @@ -44,22 +45,14 @@ class BetSheetCommand { val sheetsService = getSheetsService(sheetId) ?: return@withContext val content = BatchUpdateSpreadsheetRequest() val requests: ArrayList = ArrayList() - val request1 = Request() - val request2 = Request() - val addSheet1 = AddSheetRequest() - val addSheet2 = AddSheetRequest() - val properties1 = SheetProperties() - val properties2 = SheetProperties() + val request = Request() + val addSheet = AddSheetRequest() + val properties = SheetProperties() //賭けを表示するためのシート - properties1.title = "${raceId}_RaceAssist_Bet" - //将来の結果のため - properties2.title = "${raceId}_RaceAssist_Result" - addSheet1.properties = properties1 - addSheet2.properties = properties2 - request1.addSheet = addSheet1 - request2.addSheet = addSheet2 - requests.add(request1) - requests.add(request2) + properties.title = "${raceId}_RaceAssist_Bet" + addSheet.properties = properties + request.addSheet = addSheet + requests.add(request) content.requests = requests sheetsService.spreadsheets()?.batchUpdate(sheetId, content)?.execute() } diff --git a/src/main/kotlin/dev/nikomaru/raceassist/bet/commands/BetUnitCommand.kt b/src/main/kotlin/dev/nikomaru/raceassist/bet/commands/BetUnitCommand.kt new file mode 100644 index 0000000..b6fa557 --- /dev/null +++ b/src/main/kotlin/dev/nikomaru/raceassist/bet/commands/BetUnitCommand.kt @@ -0,0 +1,42 @@ +/* + * Copyright © 2021-2022 Nikomaru + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +package dev.nikomaru.raceassist.bet.commands + +import cloud.commandframework.annotations.* +import cloud.commandframework.annotations.specifier.Range +import dev.nikomaru.raceassist.data.files.BetSettingData +import dev.nikomaru.raceassist.utils.Lang +import dev.nikomaru.raceassist.utils.Utils +import dev.nikomaru.raceassist.utils.Utils.locale +import org.bukkit.command.CommandSender + +@CommandMethod("ra|RaceAssist bet") +class BetUnitCommand { + + @CommandPermission("raceassist.commands.bet.unit") + @CommandMethod("unit ") + @CommandDescription("最小の賭け単位を設定します") + suspend fun setUnit(sender: CommandSender, + @Argument(value = "raceId", suggestions = "raceId") raceId: String, + @Argument(value = "unit") @Range(min = "1", max = "100000") unit: Int) { + val locale = sender.locale() + if (Utils.returnCanRaceSetting(raceId, sender)) return + BetSettingData.setBetUnit(raceId, unit) + sender.sendMessage(Lang.getComponent("change-bet-unit-message", locale, raceId, unit)) + } +} \ No newline at end of file diff --git a/src/main/kotlin/dev/nikomaru/raceassist/bet/event/BetGuiClickEvent.kt b/src/main/kotlin/dev/nikomaru/raceassist/bet/event/BetGuiClickEvent.kt index 00b647e..696d285 100644 --- a/src/main/kotlin/dev/nikomaru/raceassist/bet/event/BetGuiClickEvent.kt +++ b/src/main/kotlin/dev/nikomaru/raceassist/bet/event/BetGuiClickEvent.kt @@ -21,8 +21,8 @@ import com.google.api.services.sheets.v4.model.BatchUpdateValuesRequest import com.google.api.services.sheets.v4.model.ValueRange import dev.nikomaru.raceassist.api.VaultAPI import dev.nikomaru.raceassist.api.sheet.SheetsServiceUtil.getSheetsService +import dev.nikomaru.raceassist.bet.BetUtils import dev.nikomaru.raceassist.bet.GuiComponent -import dev.nikomaru.raceassist.bet.commands.BetOpenCommand.Companion.TempBetDatas import dev.nikomaru.raceassist.bet.gui.BetChestGui.Companion.AllPlayers import dev.nikomaru.raceassist.data.database.BetList import dev.nikomaru.raceassist.data.database.BetList.rowNum @@ -85,7 +85,7 @@ class BetGuiClickEvent : Listener { val selectedNowBet: Int = getNowBet(raceId, player, slot) player.playSound(player.location, Sound.BLOCK_NOTE_BLOCK_CHIME, 1f, 1.0f) - val iterator = TempBetDatas.iterator() + val iterator = BetUtils.TempBetDatas.iterator() while (iterator.hasNext()) { val it = iterator.next() if (it.raceId == raceId && it.player == player && it.jockey == AllPlayers[raceId]?.get(slot)) { @@ -111,7 +111,7 @@ class BetGuiClickEvent : Listener { val selectedNowBet: Int = getNowBet(raceId, player, (slot - 9)) player.playSound(player.location, Sound.BLOCK_NOTE_BLOCK_BELL, 1f, 1.0f) - val iterator = TempBetDatas.iterator() + val iterator = BetUtils.TempBetDatas.iterator() while (iterator.hasNext()) { val it = iterator.next() if (it.raceId == raceId && it.player == player && it.jockey == AllPlayers[raceId]?.get(slot - 9)) { @@ -145,7 +145,7 @@ class BetGuiClickEvent : Listener { return } player.playSound(player.location, Sound.BLOCK_NOTE_BLOCK_BELL, 1f, 0.7f) - val iterator = TempBetDatas.iterator() + val iterator = BetUtils.TempBetDatas.iterator() while (iterator.hasNext()) { val it = iterator.next() if (it.raceId == raceId && it.player == player && it.jockey == AllPlayers[raceId]?.get(slot - 27)) { @@ -180,7 +180,7 @@ class BetGuiClickEvent : Listener { } player.playSound(player.location, Sound.BLOCK_NOTE_BLOCK_CHIME, 1f, 0.7f) - val iterator = TempBetDatas.iterator() + val iterator = BetUtils.TempBetDatas.iterator() while (iterator.hasNext()) { val it = iterator.next() if (it.raceId == raceId && it.player == player && it.jockey == AllPlayers[raceId]?.get(slot - 36)) { @@ -201,7 +201,7 @@ class BetGuiClickEvent : Listener { 17 -> { //clear player.playSound(player.location, Sound.UI_BUTTON_CLICK, 1f, 1f) - val iterator = TempBetDatas.iterator() + val iterator = BetUtils.TempBetDatas.iterator() while (iterator.hasNext()) { val it = iterator.next() if (it.raceId == raceId && it.player == player) { @@ -221,7 +221,7 @@ class BetGuiClickEvent : Listener { player.closeInventory() player.playSound(player.location, Sound.UI_BUTTON_CLICK, 0.5f, 1f) - val iterator = TempBetDatas.iterator() + val iterator = BetUtils.TempBetDatas.iterator() while (iterator.hasNext()) { val it = iterator.next() if (it.raceId == raceId && it.player == player) { @@ -250,7 +250,7 @@ class BetGuiClickEvent : Listener { newSuspendedTransaction(Dispatchers.Default) { var row = getMaxRow(raceId) - val iterator = TempBetDatas.iterator() + val iterator = BetUtils.TempBetDatas.iterator() while (iterator.hasNext()) { val temp = iterator.next() if (temp.raceId == raceId && temp.player == player && temp.bet != 0) { @@ -331,7 +331,7 @@ class BetGuiClickEvent : Listener { private fun getNowBet(raceId: String, player: Player, slot: Int): Int { var bet = 0 - val iterator = TempBetDatas.iterator() + val iterator = BetUtils.TempBetDatas.iterator() while (iterator.hasNext()) { val it = iterator.next() if (it.raceId == raceId && it.player == player && it.jockey == AllPlayers[raceId]?.get(slot)) { @@ -343,7 +343,7 @@ class BetGuiClickEvent : Listener { private fun getAllBet(raceId: String, player: Player): Int { var sum = 0 - TempBetDatas.forEach { + BetUtils.TempBetDatas.forEach { if (it.raceId == raceId && it.player == player) { sum += it.bet } diff --git a/src/main/kotlin/dev/nikomaru/raceassist/bet/gui/BetChestGui.kt b/src/main/kotlin/dev/nikomaru/raceassist/bet/gui/BetChestGui.kt index 0129901..22625f1 100644 --- a/src/main/kotlin/dev/nikomaru/raceassist/bet/gui/BetChestGui.kt +++ b/src/main/kotlin/dev/nikomaru/raceassist/bet/gui/BetChestGui.kt @@ -17,12 +17,11 @@ package dev.nikomaru.raceassist.bet.gui +import dev.nikomaru.raceassist.bet.BetUtils.getOdds import dev.nikomaru.raceassist.bet.GuiComponent -import dev.nikomaru.raceassist.data.database.BetList import dev.nikomaru.raceassist.data.files.BetSettingData import dev.nikomaru.raceassist.data.files.RaceSettingData import dev.nikomaru.raceassist.utils.Lang -import kotlinx.coroutines.Dispatchers import net.kyori.adventure.text.Component import net.kyori.adventure.text.Component.text import net.kyori.adventure.text.format.TextColor @@ -31,10 +30,6 @@ import org.bukkit.entity.Player import org.bukkit.inventory.Inventory import org.bukkit.inventory.ItemStack import org.bukkit.inventory.meta.SkullMeta -import org.jetbrains.exposed.sql.and -import org.jetbrains.exposed.sql.select -import org.jetbrains.exposed.sql.transactions.experimental.newSuspendedTransaction -import kotlin.math.floor class BetChestGui { @@ -42,35 +37,22 @@ class BetChestGui { val gui = Bukkit.createInventory(player, 45, GuiComponent.guiComponent()) val players: ArrayList = ArrayList() val odds: HashMap = HashMap() - var sum = 0 - val rate: Int = BetSettingData.getReturnPercent(raceId) AllPlayers[raceId] = arrayListOf() RaceSettingData.getJockeys(raceId).forEach { players.add(it) - AllPlayers[raceId]!!.add(it) + AllPlayers[raceId]?.add(it) } - - newSuspendedTransaction(Dispatchers.IO) { - BetList.select { BetList.raceId eq raceId }.forEach { - sum += it[BetList.betting] - } - } - players.forEach { jockey -> - newSuspendedTransaction(Dispatchers.IO) { - var jockeySum = 0 - BetList.select { (BetList.raceId eq raceId) and (BetList.jockeyUUID eq jockey.uniqueId.toString()) }.forEach { - jockeySum += it[BetList.betting] - } - odds[jockey] = floor(((sum * (rate.toDouble() / 100)) / jockeySum) * 100) / 100 - } + players.forEach { + odds[it] = getOdds(raceId, it) } for (i in 0 until 45) { gui.setItem(i, ItemStack(Material.GRAY_STAINED_GLASS_PANE)) } + // IFに置き換えるよてい https://github.com/stefvanschie/IF for (i in 0 until players.size) { val item = ItemStack(Material.PLAYER_HEAD, 1) val meta: SkullMeta = item.itemMeta as SkullMeta diff --git a/src/main/kotlin/dev/nikomaru/raceassist/data/database/BetListData.kt b/src/main/kotlin/dev/nikomaru/raceassist/data/database/BetListData.kt new file mode 100644 index 0000000..13abecb --- /dev/null +++ b/src/main/kotlin/dev/nikomaru/raceassist/data/database/BetListData.kt @@ -0,0 +1,23 @@ +/* + * Copyright © 2021-2022 Nikomaru + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +package dev.nikomaru.raceassist.data.database + +import java.time.LocalDateTime +import java.util.* + +data class BetListData(val rowNum: Int, val timeStamp: LocalDateTime, val playerUUID: UUID, val jockeyUUID: UUID, val betting: Int) \ No newline at end of file diff --git a/src/main/kotlin/dev/nikomaru/raceassist/data/files/RaceUtils.kt b/src/main/kotlin/dev/nikomaru/raceassist/data/files/RaceUtils.kt index a4f0289..e4b84e1 100644 --- a/src/main/kotlin/dev/nikomaru/raceassist/data/files/RaceUtils.kt +++ b/src/main/kotlin/dev/nikomaru/raceassist/data/files/RaceUtils.kt @@ -18,10 +18,10 @@ package dev.nikomaru.raceassist.data.files import dev.nikomaru.raceassist.RaceAssist.Companion.plugin +import dev.nikomaru.raceassist.utils.Utils.toUUID import kotlinx.coroutines.Dispatchers import kotlinx.coroutines.withContext import kotlinx.serialization.* -import kotlinx.serialization.Serializable import kotlinx.serialization.descriptors.PrimitiveKind import kotlinx.serialization.descriptors.PrimitiveSerialDescriptor import kotlinx.serialization.encoding.Decoder @@ -30,38 +30,25 @@ import kotlinx.serialization.json.* import org.bukkit.Bukkit import org.bukkit.OfflinePlayer import java.awt.Polygon -import java.io.* -import java.nio.file.Files import java.util.* object RaceUtils { suspend fun RaceConfig.save(raceId: String) { - val file = File(File(plugin.dataFolder, "RaceData"), "$raceId.json") + val file = plugin.dataFolder.resolve("RaceData").resolve("$raceId.json") val json = json.encodeToJsonElement(this) val string = json.toString() - raceConfigCache[raceId] = this withContext(Dispatchers.IO) { file.createNewFile() - val fw = PrintWriter(BufferedWriter(OutputStreamWriter(FileOutputStream(file), "UTF-8"))) - fw.write(string) - fw.close() + file.writeText(string) } } suspend fun getRaceConfig(raceId: String) = withContext(Dispatchers.IO) { - if (raceConfigCache.containsKey(raceId)) { - return@withContext raceConfigCache[raceId]!! - } - - val file = File(File(plugin.dataFolder, "RaceData"), "$raceId.json") - val raceConfig = json.decodeFromString(Files.readString(file.toPath())) - raceConfigCache[raceId] = raceConfig - return@withContext raceConfig + val file = plugin.dataFolder.resolve("RaceData").resolve("$raceId.json") + return@withContext json.decodeFromString(file.readText()) } - private val raceConfigCache: HashMap = HashMap() - } @Serializable @@ -91,7 +78,7 @@ object UUIDSerializer : KSerializer { override val descriptor = PrimitiveSerialDescriptor("UUID", PrimitiveKind.STRING) override fun deserialize(decoder: Decoder): UUID { - return UUID.fromString(decoder.decodeString()) + return decoder.decodeString().toUUID() } override fun serialize(encoder: Encoder, value: UUID) { @@ -104,7 +91,7 @@ object OfflinePlayerSerializer : KSerializer { override val descriptor = PrimitiveSerialDescriptor("OfflinePlayer", PrimitiveKind.STRING) override fun deserialize(decoder: Decoder): OfflinePlayer { - return Bukkit.getOfflinePlayer(UUID.fromString(decoder.decodeString())) + return Bukkit.getOfflinePlayer(decoder.decodeString().toUUID()) } override fun serialize(encoder: Encoder, value: OfflinePlayer) { @@ -144,7 +131,9 @@ object PolygonSerializer : KSerializer { @Serializable data class PolygonData(val points: ArrayList>) +@OptIn(ExperimentalSerializationApi::class) val json = Json { isLenient = true prettyPrint = true + explicitNulls = false } diff --git a/src/main/kotlin/dev/nikomaru/raceassist/dispatch/discord/DiscordWebhook.kt b/src/main/kotlin/dev/nikomaru/raceassist/dispatch/discord/DiscordWebhook.kt deleted file mode 100644 index bde16d8..0000000 --- a/src/main/kotlin/dev/nikomaru/raceassist/dispatch/discord/DiscordWebhook.kt +++ /dev/null @@ -1,59 +0,0 @@ -/* - * Copyright © 2021-2022 Nikomaru - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ - -package dev.nikomaru.raceassist.dispatch.discord - -import dev.nikomaru.raceassist.RaceAssist.Companion.plugin -import dev.nikomaru.raceassist.files.Config -import java.io.OutputStream -import java.net.HttpURLConnection -import java.net.URL -import javax.net.ssl.HttpsURLConnection - -object DiscordWebhook { - - fun sendWebHook(json: String) { - - Config.config.discordWebHook.result.forEach { - try { - val webHookUrl = URL(it) - val con: HttpsURLConnection = (webHookUrl.openConnection() as HttpsURLConnection) - - con.addRequestProperty("Content-Type", "application/JSON; charset=utf-8") - con.addRequestProperty("User-Agent", "DiscordBot") - con.doOutput = true - con.requestMethod = "POST" - - con.setRequestProperty("Content-Length", json.length.toString()) - - val stream: OutputStream = con.outputStream - stream.write(json.toByteArray(Charsets.UTF_8)) - stream.flush() - stream.close() - - val status: Int = con.responseCode - if (status != HttpURLConnection.HTTP_OK && status != HttpURLConnection.HTTP_NO_CONTENT) { - plugin.logger.warning("error:$status") - } - con.disconnect() - - } catch (e: Exception) { - e.printStackTrace() - } - } - } -} \ No newline at end of file diff --git a/src/main/kotlin/dev/nikomaru/raceassist/files/Config.kt b/src/main/kotlin/dev/nikomaru/raceassist/files/Config.kt index 9839bca..d957636 100644 --- a/src/main/kotlin/dev/nikomaru/raceassist/files/Config.kt +++ b/src/main/kotlin/dev/nikomaru/raceassist/files/Config.kt @@ -21,7 +21,7 @@ import com.typesafe.config.ConfigRenderOptions import dev.nikomaru.raceassist.RaceAssist.Companion.plugin import kotlinx.serialization.ExperimentalSerializationApi import kotlinx.serialization.hocon.* -import java.io.* +import java.io.File object Config { lateinit var config: ConfigData @@ -44,23 +44,18 @@ object Config { val spreadSheet = SpreadSheet(8888, arrayListOf()) val discordWebHook = DiscordWebHook(arrayListOf(), arrayListOf()) - val configData = ConfigData(version, 40, 200, discordWebHook, spreadSheet) + val configData = ConfigData(version, 40, 200, discordWebHook, spreadSheet, arrayListOf(), 600) val renderOptions = ConfigRenderOptions.defaults().setOriginComments(false).setComments(false).setFormatted(true).setJson(false) val string = hocon.encodeToConfig(configData).root().render(renderOptions) if (!file.exists()) { file.createNewFile() - val fw = PrintWriter(BufferedWriter(OutputStreamWriter(FileOutputStream(file), "UTF-8"))) - fw.write(string) - fw.close() + file.writeText(string) } else { val verNode = hocon.decodeFromConfig(ConfigFactory.parseFile(file)).version if (verNode != version) { - file.deleteOnExit() - val fw = PrintWriter(BufferedWriter(OutputStreamWriter(FileOutputStream(file), "UTF-8"))) - fw.write(string) - fw.close() + file.writeText(string) } } } diff --git a/src/main/kotlin/dev/nikomaru/raceassist/files/ConfigData.kt b/src/main/kotlin/dev/nikomaru/raceassist/files/ConfigData.kt index f1c2f7c..ff4368a 100644 --- a/src/main/kotlin/dev/nikomaru/raceassist/files/ConfigData.kt +++ b/src/main/kotlin/dev/nikomaru/raceassist/files/ConfigData.kt @@ -19,12 +19,20 @@ package dev.nikomaru.raceassist.files import kotlinx.serialization.Serializable -//TODO(change to hocon to use kotlinx.serialization) @Serializable -data class ConfigData(val version: String, val threshold: Int, val delay: Long, val discordWebHook: DiscordWebHook, val spreadSheet: SpreadSheet) +data class ConfigData(val version: String, + val threshold: Int, + val delay: Long, + val discordWebHook: DiscordWebHook, + val spreadSheet: SpreadSheet, + val resultWebhook: ArrayList, + val resultTimeOut: Long) @Serializable data class DiscordWebHook(val result: ArrayList, val betAll: ArrayList) +@Serializable +data class ResultWebhook(val url: String, val name: String, val password: String) + @Serializable data class SpreadSheet(val port: Int, val sheetName: ArrayList) \ No newline at end of file diff --git a/src/main/kotlin/dev/nikomaru/raceassist/horse/commands/OwnerDeleteCommand.kt b/src/main/kotlin/dev/nikomaru/raceassist/horse/commands/OwnerDeleteCommand.kt index 3a0c059..f7da191 100644 --- a/src/main/kotlin/dev/nikomaru/raceassist/horse/commands/OwnerDeleteCommand.kt +++ b/src/main/kotlin/dev/nikomaru/raceassist/horse/commands/OwnerDeleteCommand.kt @@ -18,6 +18,7 @@ package dev.nikomaru.raceassist.horse.commands import cloud.commandframework.annotations.CommandMethod +import cloud.commandframework.annotations.CommandPermission import org.bukkit.command.CommandSender import org.bukkit.entity.Horse import org.bukkit.entity.Player @@ -25,12 +26,13 @@ import org.bukkit.entity.Player @CommandMethod("ra horse") class OwnerDeleteCommand { @CommandMethod("ownerDelete") + @CommandPermission("raceassist.command.ownerdelete") fun removeOwner(sender: CommandSender) { if (sender !is Player) { sender.sendMessage("このコマンドはプレイヤーのみ実行できます") return } - val entity = sender.getTargetEntity(5) ?: return sender.sendMessage("対象が見つかりませんでした") + val entity = sender.getTargetEntity(10) ?: return sender.sendMessage("対象が見つかりませんでした") if (entity !is Horse) { sender.sendMessage("対象が馬ではありません") return diff --git a/src/main/kotlin/dev/nikomaru/raceassist/race/RaceResultData.kt b/src/main/kotlin/dev/nikomaru/raceassist/race/RaceResultData.kt new file mode 100644 index 0000000..1ef1a00 --- /dev/null +++ b/src/main/kotlin/dev/nikomaru/raceassist/race/RaceResultData.kt @@ -0,0 +1,60 @@ +/* + * Copyright © 2021-2022 Nikomaru + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +package dev.nikomaru.raceassist.race + +import dev.nikomaru.raceassist.data.files.PolygonSerializer +import dev.nikomaru.raceassist.data.files.UUIDSerializer +import kotlinx.datetime.LocalDateTime +import kotlinx.serialization.Serializable +import java.awt.Polygon +import java.util.* + +@Serializable +data class RaceResultData(val ver: String = "1.0", + val raceId: String, + val raceUniqueId: String, + val administrator: String, + val horse: HashMap<@Serializable(with = UUIDSerializer::class) UUID, @Serializable(with = UUIDSerializer::class) UUID>, + val start: LocalDateTime, + var finish: LocalDateTime, + var suspend: Boolean, + val result: HashMap, + val lap: Int, + val distance: Int, + val uuidToName: HashMap<@Serializable(with = UUIDSerializer::class) UUID, String>, + val replacement: HashMap<@Serializable(with = UUIDSerializer::class) UUID, String>, + val rectangleData: RectangleData, + val insidePolygon: @Serializable(with = PolygonSerializer::class) Polygon, + val outsidePolygon: @Serializable(with = PolygonSerializer::class) Polygon, + val currentRaceData: ArrayList) + +@Serializable +data class CurrentRacaData( + val time: Double, + val playerRaceData: ArrayList, +) + +@Serializable +data class PlayerRaceData(val uuid: @Serializable(with = UUIDSerializer::class) UUID, + val finish: Boolean, + val distance: Int?, + val blockX: Int?, + val blockY: Int?) + +@Serializable +data class RectangleData(val x1: Int, val y1: Int, val x2: Int, val y2: Int) \ No newline at end of file diff --git a/src/main/kotlin/dev/nikomaru/raceassist/race/commands/HelpCommand.kt b/src/main/kotlin/dev/nikomaru/raceassist/race/commands/HelpCommand.kt index 1a8a4a7..1d30291 100644 --- a/src/main/kotlin/dev/nikomaru/raceassist/race/commands/HelpCommand.kt +++ b/src/main/kotlin/dev/nikomaru/raceassist/race/commands/HelpCommand.kt @@ -25,100 +25,10 @@ import org.bukkit.command.CommandSender class HelpCommand { @CommandMethod("help") @CommandPermission("raceassist.command.help") + @CommandDescription("help command") fun help(sender: CommandSender) { - val message: String - if (sender.hasPermission("raceassist.admin")) { - message = """ - RaceAssist audience - /ra audience join 観客に自分を追加します - /ra audience leave 観客から自分を削除します - /ra audience list 観客の一覧を表示 - ← setting bet → - """.trimIndent() - } else { - message = """ - RaceAssist - /ra audience join 観客に自分を追加 - /ra audience leave 観客から自分を削除 - /ra bet open 賭け画面を開く - """.trimIndent() - } + val message = "コマンドリスト クリックで開く" sender.sendMessage(mm.deserialize(message)) } - @CommandMethod("help ") - @CommandPermission("raceassist.command.help") - @Hidden - fun help(sender: CommandSender, @Argument("tag") tag: String) { - val message: String = when (tag) { - "audience" -> { - """ - RaceAssist audience - /ra audience join 観客に自分を追加します - /ra audience leave 観客から自分を削除します - /ra audience list 観客の一覧を表示 - ← setting bet → - """.trimIndent() - } - "bet" -> { - """ - RaceAssist bet - /ra bet can on/off 対象のレースに対して賭けが可能か変更 - /ra bet delete 賭けを削除します - /ra bet list 賭けの一覧を表示します - /ra bet open 賭けをすることのできる画面を開く - /ra bet rate 賭けのレートを変更します - /ra bet revert すべての人に返金します - /ra bet remove 指定した番号の賭けを返金 - /ra bet sheet spreadsheetを登録します - ← audience place → - """.trimIndent() - } - "place" -> { - """ - RaceAssist place - /ra place reverse レースの走行方向の向きを反転 - /ra place central レースの中心点を設定 - /ra place degree レースのゴールの角度を設定 - /ra place lap レースのラップ数を指定 - /ra place set in|out レース場の内周、外周を指定 - /ra place finish 上記の設定の終了 - ← bet player → - """.trimIndent() - } - "player" -> { - """ - RaceAssist player - /ra player add 騎手を追加 - /ra player remove 騎手を削除 - /ra player delete 騎手をすべて削除 - /ra player list 騎手の一覧を表示 - ← place race → - """.trimIndent() - } - "race" -> { - """ - RaceAssist race - /ra race start レースを開始 - /ra race debug レースのデバッグ - /ra race stop レースの停止 - ← player setting → - """.trimIndent() - } - "setting" -> { - """ - RaceAssist setting - /ra setting create レースの作成 - /ra setting delete レースの削除 - /ra setting copy レースをコピーします - ← race audience → - """.trimIndent() - } - else -> { - "" - } - } - sender.sendMessage(mm.deserialize(message)) - - } } \ No newline at end of file diff --git a/src/main/kotlin/dev/nikomaru/raceassist/race/commands/ReloadCommand.kt b/src/main/kotlin/dev/nikomaru/raceassist/race/commands/ReloadCommand.kt new file mode 100644 index 0000000..6bef533 --- /dev/null +++ b/src/main/kotlin/dev/nikomaru/raceassist/race/commands/ReloadCommand.kt @@ -0,0 +1,37 @@ +/* + * Copyright © 2021-2022 Nikomaru + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +package dev.nikomaru.raceassist.race.commands + +import cloud.commandframework.annotations.* +import dev.nikomaru.raceassist.files.Config +import kotlinx.serialization.ExperimentalSerializationApi +import org.bukkit.command.CommandSender + +@CommandMethod("ra|raceassist") +class ReloadCommand { + + @OptIn(ExperimentalSerializationApi::class) + @CommandMethod("reload") + @CommandPermission("raceassist.command.reload") + @CommandDescription("help command") + fun reload(sender: CommandSender) { + Config.load() + sender.sendMessage("Reloaded config") + } + +} \ No newline at end of file diff --git a/src/main/kotlin/dev/nikomaru/raceassist/race/commands/audience/AudienceJoinCommand.kt b/src/main/kotlin/dev/nikomaru/raceassist/race/commands/audience/AudienceJoinCommand.kt index 454b150..fb08baa 100644 --- a/src/main/kotlin/dev/nikomaru/raceassist/race/commands/audience/AudienceJoinCommand.kt +++ b/src/main/kotlin/dev/nikomaru/raceassist/race/commands/audience/AudienceJoinCommand.kt @@ -19,14 +19,14 @@ package dev.nikomaru.raceassist.race.commands.audience import cloud.commandframework.annotations.* import dev.nikomaru.raceassist.data.files.RaceSettingData -import dev.nikomaru.raceassist.utils.CommandUtils.audience import dev.nikomaru.raceassist.utils.Lang +import dev.nikomaru.raceassist.utils.Utils.audience import org.bukkit.command.CommandSender import org.bukkit.entity.Player @CommandMethod("ra|RaceAssist audience") class AudienceJoinCommand { - @CommandPermission("RaceAssist.commands.audience.join") + @CommandPermission("raceassist.commands.audience.join") @CommandMethod("join ") fun join(sender: CommandSender, @Argument(value = "raceId", suggestions = "raceId") raceId: String) { if (sender !is Player) { diff --git a/src/main/kotlin/dev/nikomaru/raceassist/race/commands/audience/AudienceLeaveCommand.kt b/src/main/kotlin/dev/nikomaru/raceassist/race/commands/audience/AudienceLeaveCommand.kt index d2c0ea2..369d22f 100644 --- a/src/main/kotlin/dev/nikomaru/raceassist/race/commands/audience/AudienceLeaveCommand.kt +++ b/src/main/kotlin/dev/nikomaru/raceassist/race/commands/audience/AudienceLeaveCommand.kt @@ -18,14 +18,14 @@ package dev.nikomaru.raceassist.race.commands.audience import cloud.commandframework.annotations.* -import dev.nikomaru.raceassist.utils.CommandUtils.audience import dev.nikomaru.raceassist.utils.Lang +import dev.nikomaru.raceassist.utils.Utils.audience import org.bukkit.command.CommandSender import org.bukkit.entity.Player @CommandMethod("ra|RaceAssist audience") class AudienceLeaveCommand { - @CommandPermission("RaceAssist.commands.audience.leave") + @CommandPermission("raceassist.commands.audience.leave") @CommandMethod("leave ") fun leave(sender: CommandSender, @Argument(value = "raceId", suggestions = "raceId") raceId: String) { if (sender !is Player) { diff --git a/src/main/kotlin/dev/nikomaru/raceassist/race/commands/audience/AudienceListCommand.kt b/src/main/kotlin/dev/nikomaru/raceassist/race/commands/audience/AudienceListCommand.kt index 90063ef..62445a8 100644 --- a/src/main/kotlin/dev/nikomaru/raceassist/race/commands/audience/AudienceListCommand.kt +++ b/src/main/kotlin/dev/nikomaru/raceassist/race/commands/audience/AudienceListCommand.kt @@ -18,24 +18,23 @@ package dev.nikomaru.raceassist.race.commands.audience import cloud.commandframework.annotations.* -import dev.nikomaru.raceassist.utils.CommandUtils -import dev.nikomaru.raceassist.utils.CommandUtils.returnRaceSetting import dev.nikomaru.raceassist.utils.Lang +import dev.nikomaru.raceassist.utils.Utils +import dev.nikomaru.raceassist.utils.Utils.locale +import dev.nikomaru.raceassist.utils.Utils.returnCanRaceSetting import org.bukkit.Bukkit import org.bukkit.command.CommandSender -import org.bukkit.entity.Player -import java.util.* @CommandMethod("ra|RaceAssist audience") class AudienceListCommand { - @CommandPermission("RaceAssist.commands.audience.list") + @CommandPermission("raceassist.commands.audience.list") @CommandMethod("list ") suspend fun list(sender: CommandSender, @Argument(value = "raceId", suggestions = "raceId") raceId: String) { - val locale = if (sender is Player) sender.locale() else Locale.getDefault() + val locale = sender.locale() - if (returnRaceSetting(raceId, sender)) return + if (returnCanRaceSetting(raceId, sender)) return sender.sendMessage(Lang.getComponent("participants-list", locale)) - CommandUtils.audience[raceId]?.forEach { + Utils.audience[raceId]?.forEach { sender.sendMessage(Bukkit.getOfflinePlayer(it).name.toString()) } diff --git a/src/main/kotlin/dev/nikomaru/raceassist/race/commands/place/PlaceCentralCommand.kt b/src/main/kotlin/dev/nikomaru/raceassist/race/commands/place/PlaceCentralCommand.kt index 99e0163..b59637f 100644 --- a/src/main/kotlin/dev/nikomaru/raceassist/race/commands/place/PlaceCentralCommand.kt +++ b/src/main/kotlin/dev/nikomaru/raceassist/race/commands/place/PlaceCentralCommand.kt @@ -18,16 +18,16 @@ package dev.nikomaru.raceassist.race.commands.place import cloud.commandframework.annotations.* -import dev.nikomaru.raceassist.utils.CommandUtils.canSetCentral -import dev.nikomaru.raceassist.utils.CommandUtils.centralRaceId -import dev.nikomaru.raceassist.utils.CommandUtils.returnRaceSetting import dev.nikomaru.raceassist.utils.Lang +import dev.nikomaru.raceassist.utils.Utils.canSetCentral +import dev.nikomaru.raceassist.utils.Utils.centralRaceId +import dev.nikomaru.raceassist.utils.Utils.returnCanRaceSetting import org.bukkit.command.CommandSender import org.bukkit.entity.Player @CommandMethod("ra|RaceAssist place") class PlaceCentralCommand { - @CommandPermission("RaceAssist.commands.place.central") + @CommandPermission("raceassist.commands.place.central") @CommandMethod("central ") suspend fun central(sender: CommandSender, @Argument(value = "raceId", suggestions = "raceId") raceId: String) { if (sender !is Player) { @@ -35,7 +35,7 @@ class PlaceCentralCommand { return } - if (returnRaceSetting(raceId, sender)) return + if (returnCanRaceSetting(raceId, sender)) return canSetCentral[sender.uniqueId] = true centralRaceId[sender.uniqueId] = raceId sender.sendMessage(Lang.getComponent("to-set-central-point", sender.locale())) diff --git a/src/main/kotlin/dev/nikomaru/raceassist/race/commands/place/PlaceDegreeCommand.kt b/src/main/kotlin/dev/nikomaru/raceassist/race/commands/place/PlaceDegreeCommand.kt index 861bd9a..2c126fd 100644 --- a/src/main/kotlin/dev/nikomaru/raceassist/race/commands/place/PlaceDegreeCommand.kt +++ b/src/main/kotlin/dev/nikomaru/raceassist/race/commands/place/PlaceDegreeCommand.kt @@ -20,16 +20,16 @@ package dev.nikomaru.raceassist.race.commands.place import cloud.commandframework.annotations.* import dev.nikomaru.raceassist.data.files.PlaceSettingData import dev.nikomaru.raceassist.data.files.PlaceSettingData.getReverse -import dev.nikomaru.raceassist.utils.CommandUtils.getCentralPoint -import dev.nikomaru.raceassist.utils.CommandUtils.getRaceDegree -import dev.nikomaru.raceassist.utils.CommandUtils.returnRaceSetting import dev.nikomaru.raceassist.utils.Lang +import dev.nikomaru.raceassist.utils.Utils.getCentralPoint +import dev.nikomaru.raceassist.utils.Utils.getRaceDegree +import dev.nikomaru.raceassist.utils.Utils.returnCanRaceSetting import org.bukkit.command.CommandSender import org.bukkit.entity.Player @CommandMethod("ra|RaceAssist place") class PlaceDegreeCommand { - @CommandPermission("RaceAssist.commands.place.degree") + @CommandPermission("raceassist.commands.place.degree") @CommandMethod("degree ") suspend fun degree(sender: CommandSender, @Argument(value = "raceId", suggestions = "raceId") raceId: String) { if (sender !is Player) { @@ -37,7 +37,7 @@ class PlaceDegreeCommand { return } - if (returnRaceSetting(raceId, sender)) return + if (returnCanRaceSetting(raceId, sender)) return val centralXPoint = getCentralPoint(raceId, true) ?: return sender.sendMessage(Lang.getComponent("no-exist-central-point", sender.locale())) val centralYPoint = getCentralPoint(raceId, false) ?: return sender.sendMessage(Lang.getComponent("no-exist-central-point", sender.locale())) val reverse = getReverse(raceId) diff --git a/src/main/kotlin/dev/nikomaru/raceassist/race/commands/place/PlaceFinishCommand.kt b/src/main/kotlin/dev/nikomaru/raceassist/race/commands/place/PlaceFinishCommand.kt index 32306cb..1f6fdf7 100644 --- a/src/main/kotlin/dev/nikomaru/raceassist/race/commands/place/PlaceFinishCommand.kt +++ b/src/main/kotlin/dev/nikomaru/raceassist/race/commands/place/PlaceFinishCommand.kt @@ -21,15 +21,15 @@ import cloud.commandframework.annotations.CommandMethod import cloud.commandframework.annotations.CommandPermission import dev.nikomaru.raceassist.race.utils.InsideCircuit import dev.nikomaru.raceassist.race.utils.OutsideCircuit -import dev.nikomaru.raceassist.utils.CommandUtils.canSetInsideCircuit -import dev.nikomaru.raceassist.utils.CommandUtils.canSetOutsideCircuit import dev.nikomaru.raceassist.utils.Lang +import dev.nikomaru.raceassist.utils.Utils.canSetInsideCircuit +import dev.nikomaru.raceassist.utils.Utils.canSetOutsideCircuit import org.bukkit.command.CommandSender import org.bukkit.entity.Player @CommandMethod("ra|RaceAssist place") class PlaceFinishCommand { - @CommandPermission("RaceAssist.commands.place.finish") + @CommandPermission("raceassist.commands.place.finish") @CommandMethod("finish") suspend fun finish(sender: CommandSender) { if (sender !is Player) { diff --git a/src/main/kotlin/dev/nikomaru/raceassist/race/commands/place/PlaceLapCommand.kt b/src/main/kotlin/dev/nikomaru/raceassist/race/commands/place/PlaceLapCommand.kt index 923da01..460fee3 100644 --- a/src/main/kotlin/dev/nikomaru/raceassist/race/commands/place/PlaceLapCommand.kt +++ b/src/main/kotlin/dev/nikomaru/raceassist/race/commands/place/PlaceLapCommand.kt @@ -20,14 +20,14 @@ package dev.nikomaru.raceassist.race.commands.place import cloud.commandframework.annotations.* import cloud.commandframework.annotations.specifier.Range import dev.nikomaru.raceassist.data.files.PlaceSettingData -import dev.nikomaru.raceassist.utils.CommandUtils import dev.nikomaru.raceassist.utils.Lang +import dev.nikomaru.raceassist.utils.Utils import org.bukkit.command.CommandSender import org.bukkit.entity.Player @CommandMethod("ra|RaceAssist place") class PlaceLapCommand { - @CommandPermission("RaceAssist.commands.place.lap") + @CommandPermission("raceassist.commands.place.lap") @CommandMethod("lap ") suspend fun setLap(sender: CommandSender, @Argument(value = "raceId", suggestions = "raceId") raceId: String, @@ -37,7 +37,7 @@ class PlaceLapCommand { return } - if (CommandUtils.returnRaceSetting(raceId, sender)) return + if (Utils.returnCanRaceSetting(raceId, sender)) return if (lap < 1) { sender.sendMessage(Lang.getComponent("to-need-enter-over-1", sender.locale())) diff --git a/src/main/kotlin/dev/nikomaru/raceassist/race/commands/place/PlaceReverseCommand.kt b/src/main/kotlin/dev/nikomaru/raceassist/race/commands/place/PlaceReverseCommand.kt index 6fe1e1c..6ceee4e 100644 --- a/src/main/kotlin/dev/nikomaru/raceassist/race/commands/place/PlaceReverseCommand.kt +++ b/src/main/kotlin/dev/nikomaru/raceassist/race/commands/place/PlaceReverseCommand.kt @@ -19,21 +19,21 @@ package dev.nikomaru.raceassist.race.commands.place import cloud.commandframework.annotations.* import dev.nikomaru.raceassist.data.files.PlaceSettingData -import dev.nikomaru.raceassist.utils.CommandUtils.returnRaceSetting import dev.nikomaru.raceassist.utils.Lang +import dev.nikomaru.raceassist.utils.Utils.returnCanRaceSetting import org.bukkit.command.CommandSender import org.bukkit.entity.Player @CommandMethod("ra|RaceAssist place") class PlaceReverseCommand { - @CommandPermission("RaceAssist.commands.place.reverse") + @CommandPermission("raceassist.commands.place.reverse") @CommandMethod("reverse ") suspend fun reverse(sender: CommandSender, @Argument(value = "raceId", suggestions = "raceId") raceId: String) { if (sender !is Player) { sender.sendMessage("Only the player can do this.") return } - if (returnRaceSetting(raceId, sender)) return + if (returnCanRaceSetting(raceId, sender)) return PlaceSettingData.setReverse(raceId, !PlaceSettingData.getReverse(raceId)) diff --git a/src/main/kotlin/dev/nikomaru/raceassist/race/commands/place/PlaceSetCommand.kt b/src/main/kotlin/dev/nikomaru/raceassist/race/commands/place/PlaceSetCommand.kt index 0fa43ad..2435fda 100644 --- a/src/main/kotlin/dev/nikomaru/raceassist/race/commands/place/PlaceSetCommand.kt +++ b/src/main/kotlin/dev/nikomaru/raceassist/race/commands/place/PlaceSetCommand.kt @@ -19,18 +19,18 @@ package dev.nikomaru.raceassist.race.commands.place import cloud.commandframework.annotations.* import dev.nikomaru.raceassist.data.files.RaceSettingData -import dev.nikomaru.raceassist.utils.CommandUtils.canSetInsideCircuit -import dev.nikomaru.raceassist.utils.CommandUtils.canSetOutsideCircuit -import dev.nikomaru.raceassist.utils.CommandUtils.circuitRaceId -import dev.nikomaru.raceassist.utils.CommandUtils.getInsideRaceExist -import dev.nikomaru.raceassist.utils.CommandUtils.returnRaceSetting import dev.nikomaru.raceassist.utils.Lang +import dev.nikomaru.raceassist.utils.Utils.canSetInsideCircuit +import dev.nikomaru.raceassist.utils.Utils.canSetOutsideCircuit +import dev.nikomaru.raceassist.utils.Utils.circuitRaceId +import dev.nikomaru.raceassist.utils.Utils.getInsideRaceExist +import dev.nikomaru.raceassist.utils.Utils.returnCanRaceSetting import org.bukkit.command.CommandSender import org.bukkit.entity.Player @CommandMethod("ra|RaceAssist place") class PlaceSetCommand { - @CommandPermission("RaceAssist.commands.place.set") + @CommandPermission("raceassist.commands.place.set") @CommandMethod("set ") suspend fun set(sender: CommandSender, @Argument(value = "raceId", suggestions = "raceId") raceId: String, @@ -43,7 +43,7 @@ class PlaceSetCommand { if (!RaceSettingData.existsRace(raceId)) { sender.sendMessage(Lang.getComponent("no-exist-race", sender.locale())) return - } else if (returnRaceSetting(raceId, sender)) return + } else if (returnCanRaceSetting(raceId, sender)) return if (canSetOutsideCircuit[sender.uniqueId] != null || canSetInsideCircuit[sender.uniqueId] != null) { sender.sendMessage(Lang.getComponent("already-setting-mode", sender.locale())) diff --git a/src/main/kotlin/dev/nikomaru/raceassist/race/commands/player/PlayerAddCommand.kt b/src/main/kotlin/dev/nikomaru/raceassist/race/commands/player/PlayerAddCommand.kt index 4c8501d..a650a35 100644 --- a/src/main/kotlin/dev/nikomaru/raceassist/race/commands/player/PlayerAddCommand.kt +++ b/src/main/kotlin/dev/nikomaru/raceassist/race/commands/player/PlayerAddCommand.kt @@ -19,25 +19,24 @@ package dev.nikomaru.raceassist.race.commands.player import cloud.commandframework.annotations.* import dev.nikomaru.raceassist.data.files.RaceSettingData -import dev.nikomaru.raceassist.utils.CommandUtils import dev.nikomaru.raceassist.utils.Lang +import dev.nikomaru.raceassist.utils.Utils +import dev.nikomaru.raceassist.utils.Utils.locale import org.bukkit.Bukkit import org.bukkit.OfflinePlayer import org.bukkit.command.CommandSender -import org.bukkit.entity.Player -import java.util.* @CommandMethod("ra|RaceAssist player") class PlayerAddCommand { - @CommandPermission("RaceAssist.commands.player.add") + @CommandPermission("raceassist.commands.player.add") @CommandMethod("add ") suspend fun addPlayer(sender: CommandSender, @Argument(value = "raceId", suggestions = "raceId") raceId: String, @Argument(value = "playerName", suggestions = "playerName") playerName: String) { - if (CommandUtils.returnRaceSetting(raceId, sender)) return + if (Utils.returnCanRaceSetting(raceId, sender)) return - val locale = if (sender is Player) sender.locale() else Locale.getDefault() + val locale = sender.locale() val jockey: OfflinePlayer = Bukkit.getOfflinePlayerIfCached(playerName) ?: return sender.sendMessage(Lang.getComponent("player-add-not-exist", locale)) diff --git a/src/main/kotlin/dev/nikomaru/raceassist/race/commands/player/PlayerDeleteCommand.kt b/src/main/kotlin/dev/nikomaru/raceassist/race/commands/player/PlayerDeleteCommand.kt index a8a5365..9e1a1f9 100644 --- a/src/main/kotlin/dev/nikomaru/raceassist/race/commands/player/PlayerDeleteCommand.kt +++ b/src/main/kotlin/dev/nikomaru/raceassist/race/commands/player/PlayerDeleteCommand.kt @@ -19,25 +19,24 @@ package dev.nikomaru.raceassist.race.commands.player import cloud.commandframework.annotations.* import dev.nikomaru.raceassist.data.files.RaceSettingData -import dev.nikomaru.raceassist.utils.CommandUtils import dev.nikomaru.raceassist.utils.Lang +import dev.nikomaru.raceassist.utils.Utils +import dev.nikomaru.raceassist.utils.Utils.locale import org.bukkit.command.CommandSender -import org.bukkit.entity.Player -import java.util.* @CommandMethod("ra|RaceAssist player") class PlayerDeleteCommand { - @CommandPermission("RaceAssist.commands.player.delete") + @CommandPermission("raceassist.commands.player.delete") @CommandMethod("delete ") suspend fun deletePlayer(sender: CommandSender, @Argument(value = "raceId", suggestions = "raceId") raceId: String) { - if (CommandUtils.returnRaceSetting(raceId, sender)) return + if (Utils.returnCanRaceSetting(raceId, sender)) return RaceSettingData.getJockeys(raceId).forEach { RaceSettingData.removeJockey(raceId, it) } - val locale = if (sender is Player) sender.locale() else Locale.getDefault() + val locale = sender.locale() sender.sendMessage(Lang.getComponent("to-delete-all-player-from-race-group", locale, raceId)) } diff --git a/src/main/kotlin/dev/nikomaru/raceassist/race/commands/player/PlayerListCommand.kt b/src/main/kotlin/dev/nikomaru/raceassist/race/commands/player/PlayerListCommand.kt index a915c40..7bdd08c 100644 --- a/src/main/kotlin/dev/nikomaru/raceassist/race/commands/player/PlayerListCommand.kt +++ b/src/main/kotlin/dev/nikomaru/raceassist/race/commands/player/PlayerListCommand.kt @@ -19,17 +19,17 @@ package dev.nikomaru.raceassist.race.commands.player import cloud.commandframework.annotations.* import dev.nikomaru.raceassist.data.files.RaceSettingData -import dev.nikomaru.raceassist.utils.CommandUtils +import dev.nikomaru.raceassist.utils.Utils import org.bukkit.command.CommandSender @CommandMethod("ra|RaceAssist player") class PlayerListCommand { - @CommandPermission("RaceAssist.commands.player.list") + @CommandPermission("raceassist.commands.player.list") @CommandMethod("list ") suspend fun displayPlayerList(sender: CommandSender, @Argument(value = "raceId", suggestions = "raceId") raceId: String) { - if (CommandUtils.returnRaceSetting(raceId, sender)) return + if (Utils.returnCanRaceSetting(raceId, sender)) return if (RaceSettingData.getJockeys(raceId).isEmpty()) { sender.sendMessage("プレイヤーはいません") } diff --git a/src/main/kotlin/dev/nikomaru/raceassist/race/commands/player/PlayerRemoveCommand.kt b/src/main/kotlin/dev/nikomaru/raceassist/race/commands/player/PlayerRemoveCommand.kt index c8b850f..478a256 100644 --- a/src/main/kotlin/dev/nikomaru/raceassist/race/commands/player/PlayerRemoveCommand.kt +++ b/src/main/kotlin/dev/nikomaru/raceassist/race/commands/player/PlayerRemoveCommand.kt @@ -19,27 +19,22 @@ package dev.nikomaru.raceassist.race.commands.player import cloud.commandframework.annotations.* import dev.nikomaru.raceassist.data.files.RaceSettingData -import dev.nikomaru.raceassist.utils.CommandUtils import dev.nikomaru.raceassist.utils.Lang +import dev.nikomaru.raceassist.utils.Utils +import dev.nikomaru.raceassist.utils.Utils.locale import org.bukkit.Bukkit import org.bukkit.command.CommandSender -import org.bukkit.entity.Player -import java.util.* @CommandMethod("ra|RaceAssist player") class PlayerRemoveCommand { - @CommandPermission("RaceAssist.commands.player.remove") + @CommandPermission("raceassist.commands.player.remove") @CommandMethod("remove ") suspend fun removePlayer(sender: CommandSender, @Argument(value = "raceId", suggestions = "raceId") raceId: String, @Argument(value = "playerName", suggestions = "playerName") playerName: String) { - val locale = if (sender is Player) sender.locale() else Locale.getDefault() + val locale = sender.locale() val player = Bukkit.getOfflinePlayerIfCached(playerName) ?: return sender.sendMessage(Lang.getComponent("player-add-not-exist", locale)) - - - - - if (CommandUtils.returnRaceSetting(raceId, sender)) return + if (Utils.returnCanRaceSetting(raceId, sender)) return RaceSettingData.removeJockey(raceId, player) sender.sendMessage(Lang.getComponent("to-delete-player-from-race-group", locale, raceId)) diff --git a/src/main/kotlin/dev/nikomaru/raceassist/race/commands/player/PlayerReplacementCommand.kt b/src/main/kotlin/dev/nikomaru/raceassist/race/commands/player/PlayerReplacementCommand.kt new file mode 100644 index 0000000..d19784f --- /dev/null +++ b/src/main/kotlin/dev/nikomaru/raceassist/race/commands/player/PlayerReplacementCommand.kt @@ -0,0 +1,55 @@ +/* + * Copyright © 2021-2022 Nikomaru + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +package dev.nikomaru.raceassist.race.commands.player + +import cloud.commandframework.annotations.* +import dev.nikomaru.raceassist.data.files.RaceSettingData +import dev.nikomaru.raceassist.utils.Lang +import dev.nikomaru.raceassist.utils.Utils +import dev.nikomaru.raceassist.utils.Utils.locale +import org.bukkit.Bukkit +import org.bukkit.command.CommandSender + +@CommandMethod("ra|RaceAssist player") +class PlayerReplacementCommand { + + @CommandPermission("raceassist.commands.player.replacement") + @CommandMethod("replacement set ") + suspend fun setReplacement(sender: CommandSender, + @Argument(value = "raceId", suggestions = "raceId") raceId: String, + @Argument(value = "playerName", suggestions = "playerName") playerName: String, + @Argument(value = "replacement") replacement: String) { + val locale = sender.locale() + val player = Bukkit.getOfflinePlayerIfCached(playerName) ?: return sender.sendMessage(Lang.getComponent("player-add-not-exist", locale)) + if (Utils.returnCanRaceSetting(raceId, sender)) return + RaceSettingData.setReplacement(raceId, player.uniqueId, replacement) + sender.sendMessage(Lang.getComponent("player-set-replacement", locale)) + } + + @CommandPermission("raceassist.commands.player.replacement") + @CommandMethod("replacement remove ") + suspend fun removeReplacement(sender: CommandSender, + @Argument(value = "raceId", suggestions = "raceId") raceId: String, + @Argument(value = "playerName", suggestions = "playerName") playerName: String) { + val locale = sender.locale() + val player = Bukkit.getOfflinePlayerIfCached(playerName) ?: return sender.sendMessage(Lang.getComponent("player-add-not-exist", locale)) + if (Utils.returnCanRaceSetting(raceId, sender)) return + RaceSettingData.removeReplacement(raceId, player.uniqueId) + sender.sendMessage(Lang.getComponent("player-remove-replacement", locale)) + } +} \ No newline at end of file diff --git a/src/main/kotlin/dev/nikomaru/raceassist/race/commands/race/RaceDebugCommand.kt b/src/main/kotlin/dev/nikomaru/raceassist/race/commands/race/RaceDebugCommand.kt index 6febc5e..325c234 100644 --- a/src/main/kotlin/dev/nikomaru/raceassist/race/commands/race/RaceDebugCommand.kt +++ b/src/main/kotlin/dev/nikomaru/raceassist/race/commands/race/RaceDebugCommand.kt @@ -21,14 +21,14 @@ import cloud.commandframework.annotations.* import com.github.shynixn.mccoroutine.bukkit.launch import dev.nikomaru.raceassist.RaceAssist.Companion.plugin import dev.nikomaru.raceassist.data.files.PlaceSettingData -import dev.nikomaru.raceassist.utils.CommandUtils -import dev.nikomaru.raceassist.utils.CommandUtils.displayLap -import dev.nikomaru.raceassist.utils.CommandUtils.getCentralPoint -import dev.nikomaru.raceassist.utils.CommandUtils.getPolygon -import dev.nikomaru.raceassist.utils.CommandUtils.getRaceDegree -import dev.nikomaru.raceassist.utils.CommandUtils.judgeLap -import dev.nikomaru.raceassist.utils.CommandUtils.stop import dev.nikomaru.raceassist.utils.Lang +import dev.nikomaru.raceassist.utils.Utils +import dev.nikomaru.raceassist.utils.Utils.displayLap +import dev.nikomaru.raceassist.utils.Utils.getCentralPoint +import dev.nikomaru.raceassist.utils.Utils.getPolygon +import dev.nikomaru.raceassist.utils.Utils.getRaceDegree +import dev.nikomaru.raceassist.utils.Utils.judgeLap +import dev.nikomaru.raceassist.utils.Utils.stop import dev.nikomaru.raceassist.utils.coroutines.minecraft import kotlinx.coroutines.* import net.kyori.adventure.text.serializer.legacy.LegacyComponentSerializer @@ -45,7 +45,7 @@ import kotlin.math.roundToInt @CommandMethod("ra|RaceAssist race") class RaceDebugCommand { - @CommandPermission("RaceAssist.commands.race.debug") + @CommandPermission("raceassist.commands.race.debug") @CommandMethod("debug ") suspend fun debug(sender: CommandSender, @Argument(value = "raceId", suggestions = "raceId") raceId: String) { if (sender !is Player) { @@ -54,7 +54,7 @@ class RaceDebugCommand { } val locale = sender.locale() plugin.launch { - if (CommandUtils.returnRaceSetting(raceId, sender)) return@launch + if (Utils.returnCanRaceSetting(raceId, sender)) return@launch if (!getCircuitExist(raceId)) { sender.sendMessage(Lang.getComponent("no-exist-race", locale)) return@launch diff --git a/src/main/kotlin/dev/nikomaru/raceassist/race/commands/race/RaceStartCommand.kt b/src/main/kotlin/dev/nikomaru/raceassist/race/commands/race/RaceStartCommand.kt index 2c2b38a..7cb483f 100644 --- a/src/main/kotlin/dev/nikomaru/raceassist/race/commands/race/RaceStartCommand.kt +++ b/src/main/kotlin/dev/nikomaru/raceassist/race/commands/race/RaceStartCommand.kt @@ -20,40 +20,52 @@ package dev.nikomaru.raceassist.race.commands.race import cloud.commandframework.annotations.* import com.github.shynixn.mccoroutine.bukkit.launch import dev.nikomaru.raceassist.RaceAssist.Companion.plugin -import dev.nikomaru.raceassist.bet.commands.BetReturnCommand -import dev.nikomaru.raceassist.data.files.PlaceSettingData -import dev.nikomaru.raceassist.data.files.RaceSettingData -import dev.nikomaru.raceassist.dispatch.discord.DiscordWebhook +import dev.nikomaru.raceassist.bet.BetUtils +import dev.nikomaru.raceassist.data.files.* import dev.nikomaru.raceassist.files.Config +import dev.nikomaru.raceassist.race.* import dev.nikomaru.raceassist.utils.* -import dev.nikomaru.raceassist.utils.CommandUtils.displayLap -import dev.nikomaru.raceassist.utils.CommandUtils.getRaceDegree -import dev.nikomaru.raceassist.utils.CommandUtils.judgeLap -import dev.nikomaru.raceassist.utils.CommandUtils.stop import dev.nikomaru.raceassist.utils.Lang.mm +import dev.nikomaru.raceassist.utils.Utils.displayLap +import dev.nikomaru.raceassist.utils.Utils.getRaceDegree +import dev.nikomaru.raceassist.utils.Utils.judgeLap +import dev.nikomaru.raceassist.utils.Utils.locale +import dev.nikomaru.raceassist.utils.Utils.stop import dev.nikomaru.raceassist.utils.coroutines.minecraft import kotlinx.coroutines.* +import kotlinx.datetime.* +import kotlinx.datetime.TimeZone +import kotlinx.serialization.encodeToString import net.kyori.adventure.text.Component.text import net.kyori.adventure.text.serializer.legacy.LegacyComponentSerializer import net.kyori.adventure.title.Title +import okhttp3.* +import okhttp3.MediaType.Companion.toMediaType +import okhttp3.RequestBody.Companion.toRequestBody +import org.apache.commons.lang.RandomStringUtils import org.bukkit.Bukkit import org.bukkit.OfflinePlayer import org.bukkit.command.CommandSender +import org.bukkit.entity.Horse import org.bukkit.entity.Player import org.bukkit.scoreboard.* import org.json.simple.JSONArray import org.json.simple.JSONObject import java.awt.Polygon +import java.io.OutputStream +import java.net.HttpURLConnection +import java.net.URL import java.util.* +import javax.net.ssl.HttpsURLConnection import kotlin.math.* @CommandMethod("ra|RaceAssist race") class RaceStartCommand { - @CommandPermission("RaceAssist.commands.race.start") + @CommandPermission("raceassist.commands.race.start") @CommandMethod("start ") suspend fun start(sender: CommandSender, @Argument(value = "raceId", suggestions = "raceId") raceId: String) { - val locale = if (sender is Player) sender.locale() else Locale.getDefault() + val locale = sender.locale() if (PlaceSettingData.getInsidePolygon(raceId).npoints == 0 || PlaceSettingData.getOutsidePolygon(raceId).npoints == 0) { sender.sendMessage(Lang.getComponent("no-exist-race", locale)) @@ -80,7 +92,7 @@ class RaceStartCommand { val goalDegree: Int = PlaceSettingData.getGoalDegree(raceId) val jockeyCount = jockeys.size - val finishJockey: ArrayList = ArrayList() + val finishJockeys: ArrayList = ArrayList() val totalDegree: HashMap = HashMap() val beforeDegree: HashMap = HashMap() val currentLap: HashMap = HashMap() @@ -97,8 +109,7 @@ class RaceStartCommand { val audiences = RaceAudience() - - CommandUtils.audience[raceId]?.forEach { + Utils.audience[raceId]?.forEach { audiences.add(Bukkit.getOfflinePlayer(it)) } jockeys.forEach { @@ -120,11 +131,8 @@ class RaceStartCommand { } val lap = PlaceSettingData.getLap(raceId) - val outsidePolygon = PlaceSettingData.getOutsidePolygon(raceId) - val reverse = PlaceSettingData.getReverse(raceId) - val innerCircumference = getInnerCircumference(insidePolygon) jockeys.forEach { @@ -137,46 +145,95 @@ class RaceStartCommand { val beforeTime = System.currentTimeMillis() audiences.showTitleI18n("race-start") + //最初の位置をランダムに選んだ人から決める + //最初の人から相対的に距離を決めるがゴールをまたいでいた場合後方にいる人がマイナスにされない val randomJockey = jockeys.random() - val startDegree = getRaceDegree((randomJockey.location.blockZ - centralYPoint).toDouble(), if (reverse) { - (-1 * (randomJockey.location.blockX - centralXPoint)).toDouble() - } else { - (randomJockey.location.blockX - centralXPoint).toDouble() - }) + val startDegree = getStartPoint(randomJockey, centralYPoint, reverse, centralXPoint) + + // 結果の保存のため + val limit = ((Config.config.resultTimeOut) * (1000.0 / (Config.config.delay).toDouble())).toLong() * 1000 + val goalDistance = getGoalDistance(lap, goalDegree, startDegree, innerCircumference) + + val senderName = if (sender is Player) sender.name else "Console" + + val uuidToName = jockeys.associate { it.uniqueId to it.name } as HashMap + + val rectangleData = RectangleData(outsidePolygon.bounds2D.maxX.roundToInt(), + outsidePolygon.bounds2D.maxY.roundToInt(), + outsidePolygon.bounds2D.minX.roundToInt(), + outsidePolygon.bounds2D.minY.roundToInt()) + val horses: HashMap = HashMap() + jockeys.forEach { + val vehicle = it.vehicle + if (vehicle != null) { + if (vehicle is Horse) { + horses[it.uniqueId] = vehicle.uniqueId + } + } + } + + val raceUniqueId = RandomStringUtils.randomAlphanumeric(15) + val raceResultData = RaceResultData("1.0", + raceId, + raceUniqueId, + senderName, + horses, + Clock.System.now().toLocalDateTime(TimeZone.currentSystemDefault()), + Clock.System.now().toLocalDateTime(TimeZone.currentSystemDefault()), + false, + hashMapOf(), + lap, + goalDistance, + uuidToName, + RaceSettingData.getReplacement(raceId), + rectangleData, + insidePolygon, + outsidePolygon, + arrayListOf()) //レースの処理 while (true) { //正常時の終了 + val currentRacaData = CurrentRacaData(((System.currentTimeMillis() - beforeTime).toDouble() / 1000), arrayListOf()) + if (jockeys.size < 1) { - BetReturnCommand.canReturn[raceId] = true - BetReturnCommand.payRefund(Bukkit.getOfflinePlayer(finishJockey[0]), raceId, sender, locale) + BetUtils.returnBet(Bukkit.getOfflinePlayer(finishJockeys[0]), raceId, sender, locale) break } //stopコマンドによる終了 if (stop[raceId] == true) { suspend = true - audiences.sendMessageI18n("suspended-race") + raceResultData.suspend = true + audiences.sendMessageI18n("suspended-race-by-operator") + break + } + if ((System.currentTimeMillis() - beforeTime) > limit) { + suspend = true + raceResultData.suspend = true + audiences.sendMessageI18n("suspended-race-by-limit") break } val iterator = jockeys.iterator() - //各騎手の位置の取得 + while (iterator.hasNext()) { val player: Player = iterator.next() + if (!player.isOnline) { iterator.remove() continue } - + //各騎手の位置の取得 val nowX: Int = player.location.blockX val nowY = player.location.blockZ val relativeNowX = if (!reverse) nowX - centralXPoint else -1 * (nowX - centralXPoint) val relativeNowY = nowY - centralYPoint val currentDegree = getRaceDegree(relativeNowY.toDouble(), relativeNowX.toDouble()) val uuid = player.uniqueId - val beforeLap = currentLap[uuid] + //ラップの計算 withContext(Dispatchers.Default) { + currentLap[uuid] = currentLap[uuid]!! + judgeLap(goalDegree, beforeDegree[uuid], currentDegree, threshold) passBorders[uuid] = passBorders[uuid]!! + judgeLap(0, beforeDegree[uuid], currentDegree, threshold) displayLap(currentLap[uuid], beforeLap, player, lap) @@ -184,6 +241,11 @@ class RaceStartCommand { totalDegree[uuid] = currentDegree + (passBorders[uuid]!! * 360) } + val currentDistance = (((totalDegree[uuid]!!.toDouble() - startDegree.toDouble()) / 360.0) * innerCircumference).toInt() + + val currentResultData = PlayerRaceData(uuid, false, currentDistance, nowX, nowY) + currentRacaData.playerRaceData.add(currentResultData) + //コース内にいるか判断 if (insidePolygon.contains(nowX, nowY) || !outsidePolygon.contains(nowX, nowY)) { player.sendActionBar(Lang.getComponent("outside-the-racetrack", player.locale())) @@ -191,21 +253,36 @@ class RaceStartCommand { //ゴールした時の処理 if (currentLap[uuid]!! >= lap) { - iterator.remove() - finishJockey.add(uuid) - totalDegree.remove(uuid) - currentLap.remove(uuid) - player.showTitle(Title.title(Lang.getComponent("player-ranking", player.locale(), jockeyCount - jockeys.size, jockeyCount), - text(""))) + withContext(Dispatchers.Default) { + iterator.remove() + finishJockeys.add(uuid) + totalDegree.remove(uuid) + currentLap.remove(uuid) + player.showTitle(Title.title(Lang.getComponent("player-ranking", player.locale(), jockeyCount - jockeys.size, jockeyCount), + text(""))) + } time[uuid] = ((System.currentTimeMillis() - beforeTime) / 1000).toInt() continue } + } + + + finishJockeys.forEach { finishJockey -> + val player = Bukkit.getPlayer(finishJockey) ?: return@forEach + + val uuid = player.uniqueId + + val none = currentRacaData.playerRaceData.none { it.uuid == uuid } + if (none) { + currentRacaData.playerRaceData.add(PlayerRaceData(uuid, true, null, null, null)) + } + } + //順位の表示 plugin.launch { val displayRanking = async(minecraft) { - - displayScoreboard(finishJockey.plus(decideRanking(totalDegree)), + displayScoreboard(finishJockeys.plus(decideRanking(totalDegree)), totalDegree, raceAudience, innerCircumference.roundToInt(), @@ -217,27 +294,64 @@ class RaceStartCommand { delay(Config.config.delay) displayRanking.await() }.join() + //現在のレースの状況保存のため + raceResultData.currentRaceData.add(currentRacaData) } + //終了時の処理 + raceResultData.finish = Clock.System.now().toLocalDateTime(TimeZone.currentSystemDefault()) audiences.showTitleI18n("finish-race") delay(2000) - for (i in 0 until finishJockey.size) { - audiences.sendMessageI18n("to-notice-ranking-message", i + 1, Bukkit.getPlayer(finishJockey[i])?.name!!) + for (i in 0 until finishJockeys.size) { + audiences.sendMessageI18n("to-notice-ranking-message", i + 1, Bukkit.getPlayer(finishJockeys[i])?.name!!) } - withContext(Dispatchers.IO) { - if (Config.config.discordWebHook.result.isNotEmpty()) { - sendWebHook(finishJockey, time, RaceSettingData.getOwner(raceId), raceId, suspend) - } + finishJockeys.forEachIndexed { index, element -> + raceResultData.result[index + 1] = element } + + //結果の保存 + putRaceResult(raceResultData) + sendWebHook(finishJockeys, time, RaceSettingData.getOwner(raceId), raceId, suspend) + + //後始末 Bukkit.getOnlinePlayers().forEach { it.scoreboard.clearSlot(DisplaySlot.SIDEBAR) } } + private fun getStartPoint(randomJockey: Player, centralYPoint: Int, reverse: Boolean, centralXPoint: Int) = + getRaceDegree((randomJockey.location.blockZ - centralYPoint).toDouble(), if (reverse) { + (-1 * (randomJockey.location.blockX - centralXPoint)).toDouble() + } else { + (randomJockey.location.blockX - centralXPoint).toDouble() + }) + + private suspend fun putRaceResult(raceResultData: RaceResultData) { + withContext(Dispatchers.IO) { + val resultFolder = plugin.dataFolder.resolve("result") + resultFolder.mkdirs() + val resultFile = resultFolder.resolve("${raceResultData.raceUniqueId}.json") + resultFile.writeText(json.encodeToString(raceResultData)) + sendResultWebHook(raceResultData) + } + } + + private fun sendResultWebHook(raceResultData: RaceResultData) { + val json = json.encodeToString(raceResultData) + val body: RequestBody = json.toRequestBody("application/json; charset=utf-8".toMediaType()) + val client = OkHttpClient() + Config.config.resultWebhook.forEach { + val request: Request = + Request.Builder().url(it.url + raceResultData.raceUniqueId).header("Authorization", Credentials.basic(it.name, it.password)) + .post(body).build() + client.newCall(request).execute().body?.close() + } + } + private suspend fun getInnerCircumference(insidePolygon: Polygon) = withContext(Dispatchers.Default) { //内周の距離のカウント var total = 0.0 @@ -253,7 +367,11 @@ class RaceStartCommand { total } - private fun sendWebHook(finishJockey: ArrayList, time: HashMap, starter: OfflinePlayer, raceId: String, suspend: Boolean) { + private suspend fun sendWebHook(finishJockey: ArrayList, + time: HashMap, + starter: OfflinePlayer, + raceId: String, + suspend: Boolean) { val json = JSONObject() json["username"] = "RaceAssist" json["avatar_url"] = "https://3.bp.blogspot.com/-Y3AVYVjLcPs/UYiNxIliDxI/AAAAAAAARSg/nZLIqBRUta8/s800/animal_uma.png" @@ -279,8 +397,38 @@ class RaceStartCommand { embeds.add(embedsObject) json["embeds"] = embeds + sendDiscordResultWebHook(json.toString()) + } + + private suspend fun sendDiscordResultWebHook(json: String) = withContext(Dispatchers.IO) { + + Config.config.discordWebHook.result.forEach { + try { + val webHookUrl = URL(it) + val con: HttpsURLConnection = (webHookUrl.openConnection() as HttpsURLConnection) + + con.addRequestProperty("Content-Type", "application/JSON; charset=utf-8") + con.addRequestProperty("User-Agent", "DiscordBot") + con.doOutput = true + con.requestMethod = "POST" + + con.setRequestProperty("Content-Length", json.length.toString()) - DiscordWebhook.sendWebHook(json.toString()) + val stream: OutputStream = con.outputStream + stream.write(json.toByteArray(Charsets.UTF_8)) + stream.flush() + stream.close() + + val status: Int = con.responseCode + if (status != HttpURLConnection.HTTP_OK && status != HttpURLConnection.HTTP_NO_CONTENT) { + plugin.logger.warning("error:$status") + } + con.disconnect() + + } catch (e: Exception) { + e.printStackTrace() + } + } } private suspend fun displayScoreboard(nowRankings: List, @@ -303,14 +451,11 @@ class RaceStartCommand { Lang.getComponent("scoreboard-now-ranking", player.locale())) objective.displaySlot = DisplaySlot.SIDEBAR + val goalDistance = getGoalDistance(lap, goalDegree, startDegree, innerCircumference.toDouble()) + for (i in nowRankings.indices) { val playerName = RaceSettingData.getReplacement(raceId)[nowRankings[i]] ?: Bukkit.getPlayer(nowRankings[i])?.name - val goalDistance = (((lap - 1).toDouble() + if (goalDegree > startDegree) { - ((goalDegree.toDouble() - startDegree.toDouble()) / 360.0) - } else { - ((goalDegree.toDouble() + 360.0 - startDegree.toDouble()) / 360.0) - }) * innerCircumference.toDouble()).toInt() val component = if (currentDegree[Bukkit.getPlayer(nowRankings[i])!!.uniqueId] == null) { Lang.getComponent("scoreboard-now-ranking-and-name", player.locale(), i + 1, playerName) @@ -331,6 +476,13 @@ class RaceStartCommand { } } + private fun getGoalDistance(lap: Int, goalDegree: Int, startDegree: Int, innerCircumference: Double) = + (((lap - 1).toDouble() + if (goalDegree > startDegree) { + ((goalDegree.toDouble() - startDegree.toDouble()) / 360.0) + } else { + ((goalDegree.toDouble() + 360.0 - startDegree.toDouble()) / 360.0) + }) * innerCircumference).toInt() + private fun decideRanking(totalDegree: HashMap): ArrayList { val ranking = ArrayList() val sorted = totalDegree.toList().sortedBy { (_, value) -> value } diff --git a/src/main/kotlin/dev/nikomaru/raceassist/race/commands/race/RaceStopCommand.kt b/src/main/kotlin/dev/nikomaru/raceassist/race/commands/race/RaceStopCommand.kt index 60f4f77..d9dd7bc 100644 --- a/src/main/kotlin/dev/nikomaru/raceassist/race/commands/race/RaceStopCommand.kt +++ b/src/main/kotlin/dev/nikomaru/raceassist/race/commands/race/RaceStopCommand.kt @@ -18,17 +18,17 @@ package dev.nikomaru.raceassist.race.commands.race import cloud.commandframework.annotations.* -import dev.nikomaru.raceassist.utils.CommandUtils -import dev.nikomaru.raceassist.utils.CommandUtils.stop +import dev.nikomaru.raceassist.utils.Utils +import dev.nikomaru.raceassist.utils.Utils.stop import kotlinx.coroutines.delay import org.bukkit.command.CommandSender @CommandMethod("ra|RaceAssist race") class RaceStopCommand { - @CommandPermission("RaceAssist.commands.race.stop") + @CommandPermission("raceassist.commands.race.stop") @CommandMethod("stop ") suspend fun stop(sender: CommandSender, @Argument(value = "raceId", suggestions = "raceId") raceId: String) { - if (CommandUtils.returnRaceSetting(raceId, sender)) return + if (Utils.returnCanRaceSetting(raceId, sender)) return stop[raceId] = true delay(1000) stop[raceId] = false diff --git a/src/main/kotlin/dev/nikomaru/raceassist/race/commands/setting/SettingCopyCommand.kt b/src/main/kotlin/dev/nikomaru/raceassist/race/commands/setting/SettingCopyCommand.kt index 9cc67ca..51fc7f7 100644 --- a/src/main/kotlin/dev/nikomaru/raceassist/race/commands/setting/SettingCopyCommand.kt +++ b/src/main/kotlin/dev/nikomaru/raceassist/race/commands/setting/SettingCopyCommand.kt @@ -26,7 +26,7 @@ import org.bukkit.entity.Player @CommandMethod("ra|RaceAssist setting") class SettingCopyCommand { - @CommandPermission("RaceAssist.commands.setting.copy") + @CommandPermission("raceassist.commands.setting.copy") @CommandMethod("copy ") suspend fun copy(sender: CommandSender, @Regex(value = "[a-zA-Z]+-\\d+$") @Argument(value = "raceId_1", suggestions = "raceId") raceId_1: String, diff --git a/src/main/kotlin/dev/nikomaru/raceassist/race/commands/setting/SettingCreateCommand.kt b/src/main/kotlin/dev/nikomaru/raceassist/race/commands/setting/SettingCreateCommand.kt index 2913d87..ba84efd 100644 --- a/src/main/kotlin/dev/nikomaru/raceassist/race/commands/setting/SettingCreateCommand.kt +++ b/src/main/kotlin/dev/nikomaru/raceassist/race/commands/setting/SettingCreateCommand.kt @@ -25,9 +25,9 @@ import org.bukkit.entity.Player @CommandMethod("ra|RaceAssist setting") class SettingCreateCommand { - @CommandPermission("RaceAssist.commands.setting.create") + @CommandPermission("raceassist.commands.setting.create") @CommandMethod("create ") - suspend fun create(sender: CommandSender, @Argument(value = "raceId") @Regex(value = "[a-zA-Z]+-\\d+$") raceId: String) { + suspend fun create(sender: CommandSender, @Argument(value = "raceId") @Regex(value = "[^_]+_\\d+$") raceId: String) { if (sender !is Player) { sender.sendMessage("Only the player can do this.") return diff --git a/src/main/kotlin/dev/nikomaru/raceassist/race/commands/setting/SettingDeleteCommand.kt b/src/main/kotlin/dev/nikomaru/raceassist/race/commands/setting/SettingDeleteCommand.kt index f699478..3995c53 100644 --- a/src/main/kotlin/dev/nikomaru/raceassist/race/commands/setting/SettingDeleteCommand.kt +++ b/src/main/kotlin/dev/nikomaru/raceassist/race/commands/setting/SettingDeleteCommand.kt @@ -19,13 +19,13 @@ package dev.nikomaru.raceassist.race.commands.setting import cloud.commandframework.annotations.* import dev.nikomaru.raceassist.data.files.RaceSettingData -import dev.nikomaru.raceassist.utils.CommandUtils +import dev.nikomaru.raceassist.utils.Utils import org.bukkit.command.CommandSender import org.bukkit.entity.Player @CommandMethod("ra|RaceAssist setting") class SettingDeleteCommand { - @CommandPermission("RaceAssist.commands.setting.delete") + @CommandPermission("raceassist.commands.setting.delete") @CommandMethod("delete ") @Confirmation suspend fun delete(sender: CommandSender, @Argument(value = "raceId", suggestions = "raceId") raceId: String) { @@ -33,7 +33,7 @@ class SettingDeleteCommand { sender.sendMessage("Only the player can do this.") return } - if (CommandUtils.returnRaceSetting(raceId, sender)) return + if (Utils.returnCanRaceSetting(raceId, sender)) return RaceSettingData.deleteRace(raceId) } diff --git a/src/main/kotlin/dev/nikomaru/raceassist/race/commands/setting/SettingReplacemcntCommand.kt b/src/main/kotlin/dev/nikomaru/raceassist/race/commands/setting/SettingReplacemcntCommand.kt index 69a3d49..0c0497e 100644 --- a/src/main/kotlin/dev/nikomaru/raceassist/race/commands/setting/SettingReplacemcntCommand.kt +++ b/src/main/kotlin/dev/nikomaru/raceassist/race/commands/setting/SettingReplacemcntCommand.kt @@ -19,12 +19,11 @@ package dev.nikomaru.raceassist.race.commands.setting import cloud.commandframework.annotations.* import dev.nikomaru.raceassist.data.files.RaceSettingData -import dev.nikomaru.raceassist.utils.CommandUtils import dev.nikomaru.raceassist.utils.Lang +import dev.nikomaru.raceassist.utils.Utils +import dev.nikomaru.raceassist.utils.Utils.locale import org.bukkit.Bukkit import org.bukkit.command.CommandSender -import org.bukkit.entity.Player -import java.util.* @CommandMethod("ra|RaceAssist setting") @CommandPermission("raceassist.commands.setting.replacement") @@ -35,8 +34,8 @@ class SettingReplacemcntCommand { @Argument(value = "raceId", suggestions = "raceId") raceId: String, @Argument(value = "playerName", suggestions = "playerName") playerName: String, @Argument(value = "replacement") replacement: String) { - if (CommandUtils.returnRaceSetting(raceId, sender)) return - val locale = if (sender is Player) sender.locale() else Locale.getDefault() + if (Utils.returnCanRaceSetting(raceId, sender)) return + val locale = sender.locale() val player = Bukkit.getOfflinePlayerIfCached(playerName) ?: return sender.sendMessage(Lang.getComponent("player-add-not-exist", locale)) RaceSettingData.setReplacement(raceId, player.uniqueId, replacement) @@ -48,8 +47,8 @@ class SettingReplacemcntCommand { suspend fun remove(sender: CommandSender, @Argument(value = "raceId", suggestions = "raceId") raceId: String, @Argument(value = "playerName", suggestions = "playerName") playerName: String) { - if (CommandUtils.returnRaceSetting(raceId, sender)) return - val locale = if (sender is Player) sender.locale() else Locale.getDefault() + if (Utils.returnCanRaceSetting(raceId, sender)) return + val locale = sender.locale() val player = Bukkit.getOfflinePlayerIfCached(playerName) ?: return sender.sendMessage(Lang.getComponent("player-add-not-exist", locale)) RaceSettingData.removeReplacement(raceId, player.uniqueId) @@ -58,8 +57,8 @@ class SettingReplacemcntCommand { @CommandMethod("replacement delete ") suspend fun delete(sender: CommandSender, @Argument(value = "raceId", suggestions = "raceId") raceId: String) { - if (CommandUtils.returnRaceSetting(raceId, sender)) return - val locale = if (sender is Player) sender.locale() else Locale.getDefault() + if (Utils.returnCanRaceSetting(raceId, sender)) return + val locale = sender.locale() RaceSettingData.deleteReplacement(raceId) sender.sendMessage(Lang.getComponent("command-result-delete-success", locale)) @@ -68,8 +67,8 @@ class SettingReplacemcntCommand { @CommandMethod("replacement list ") suspend fun list(sender: CommandSender, @Argument(value = "raceId", suggestions = "raceId") raceId: String) { - if (CommandUtils.returnRaceSetting(raceId, sender)) return - val locale = if (sender is Player) sender.locale() else Locale.getDefault() + if (Utils.returnCanRaceSetting(raceId, sender)) return + val locale = sender.locale() val replacement = RaceSettingData.getReplacement(raceId) if (replacement.isEmpty()) { sender.sendMessage(Lang.getComponent("command-result-replacement-list-empty", locale)) diff --git a/src/main/kotlin/dev/nikomaru/raceassist/race/commands/setting/SettingStaffCommand.kt b/src/main/kotlin/dev/nikomaru/raceassist/race/commands/setting/SettingStaffCommand.kt index 4f100b0..992be7f 100644 --- a/src/main/kotlin/dev/nikomaru/raceassist/race/commands/setting/SettingStaffCommand.kt +++ b/src/main/kotlin/dev/nikomaru/raceassist/race/commands/setting/SettingStaffCommand.kt @@ -20,13 +20,11 @@ package dev.nikomaru.raceassist.race.commands.setting import cloud.commandframework.annotations.* import dev.nikomaru.raceassist.data.files.RaceSettingData import dev.nikomaru.raceassist.data.files.StaffSettingData -import dev.nikomaru.raceassist.utils.CommandUtils import dev.nikomaru.raceassist.utils.Lang +import dev.nikomaru.raceassist.utils.Utils +import dev.nikomaru.raceassist.utils.Utils.locale import org.bukkit.Bukkit -import org.bukkit.OfflinePlayer import org.bukkit.command.CommandSender -import org.bukkit.entity.Player -import java.util.* @CommandMethod("ra|raceassist setting") @CommandPermission("raceassist.commands.setting.staff") @@ -37,9 +35,9 @@ class SettingStaffCommand { @Argument(value = "raceId", suggestions = "raceId") raceId: String, @Argument(value = "playerName", suggestions = "playerName") playerName: String) { - if (CommandUtils.returnRaceSetting(raceId, sender)) return + if (Utils.returnCanRaceSetting(raceId, sender)) return - val locale = if (sender is Player) sender.locale() else Locale.getDefault() + val locale = sender.locale() val target = Bukkit.getOfflinePlayerIfCached(playerName) ?: return sender.sendMessage(Lang.getComponent("player-add-not-exist", locale)) if (StaffSettingData.addStaff(raceId, target)) { @@ -54,9 +52,9 @@ class SettingStaffCommand { suspend fun removeStaff(sender: CommandSender, @Argument(value = "raceId", suggestions = "raceId") raceId: String, @Argument(value = "playerName", suggestions = "playerName") playerName: String) { - if (CommandUtils.returnRaceSetting(raceId, sender)) return + if (Utils.returnCanRaceSetting(raceId, sender)) return - val locale = if (sender is Player) sender.locale() else Locale.getDefault() + val locale = sender.locale() val target = Bukkit.getOfflinePlayerIfCached(playerName) ?: return sender.sendMessage(Lang.getComponent("player-add-not-exist", locale)) if (RaceSettingData.getOwner(raceId) == target) { return sender.sendMessage(Lang.getComponent("cant-remove-yourself-staff", locale)) @@ -72,19 +70,10 @@ class SettingStaffCommand { @CommandMethod("staff list ") suspend fun listStaff(sender: CommandSender, @Argument(value = "raceId", suggestions = "raceId") raceId: String) { - if (CommandUtils.returnRaceSetting(raceId, sender)) return + if (Utils.returnCanRaceSetting(raceId, sender)) return StaffSettingData.getStaffs(raceId).forEach { sender.sendMessage(it.name.toString()) } } - - private fun returnCanSetPlayer(target: OfflinePlayer, sender: CommandSender, playerName: String): Boolean { - if (!target.hasPlayedBefore()) { - val locale = if (sender is Player) sender.locale() else Locale.getDefault() - sender.sendMessage(Lang.getComponent("not-exsist-staff-this-player", locale, playerName, locale)) - return true - } - return false - } } \ No newline at end of file diff --git a/src/main/kotlin/dev/nikomaru/raceassist/race/commands/setting/SettingViewCommand.kt b/src/main/kotlin/dev/nikomaru/raceassist/race/commands/setting/SettingViewCommand.kt new file mode 100644 index 0000000..46a4009 --- /dev/null +++ b/src/main/kotlin/dev/nikomaru/raceassist/race/commands/setting/SettingViewCommand.kt @@ -0,0 +1,56 @@ +/* + * Copyright © 2021-2022 Nikomaru + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +package dev.nikomaru.raceassist.race.commands.setting + +import cloud.commandframework.annotations.* +import dev.nikomaru.raceassist.data.files.RaceSettingData +import dev.nikomaru.raceassist.data.files.RaceUtils +import org.bukkit.Bukkit +import org.bukkit.command.CommandSender +import java.util.* + +@CommandMethod("ra|RaceAssist setting") +class SettingViewCommand { + + @CommandMethod("view ") + @CommandPermission("raceassist.commands.setting.view") + suspend fun view(sender: CommandSender, @Argument(value = "raceId", suggestions = "raceId") raceId: String) { + if (!RaceSettingData.existsRace(raceId)) return + val raceData = RaceUtils.getRaceConfig(raceId) + sender.sendMessage("raceId = ${raceData.raceId}") + sender.sendMessage("raceName = ${raceData.raceName}") + sender.sendMessage("owner = ${raceData.owner.name}") + sender.sendMessage("staff = ${raceData.staff.joinToString { it.name.toString() }}") + sender.sendMessage("jockeys = ${raceData.jockeys.joinToString { it.name.toString() }}") + sender.sendMessage("replacement = ${raceData.replacement.map { it.key.toName() to it.value }.toMap()}") + sender.sendMessage("x = ${raceData.place.centralX}") + sender.sendMessage("y = ${raceData.place.centralY}") + sender.sendMessage("lap = ${raceData.place.lap}") + sender.sendMessage("reverce = ${raceData.place.reverse}") + sender.sendMessage("goalDegree = ${raceData.place.goalDegree}") + sender.sendMessage("bet-avaiable = ${raceData.bet.available}") + sender.sendMessage("bet-returnPercent = ${raceData.bet.returnPercent}") + sender.sendMessage("bet-spreadSheetId = ${raceData.bet.spreadSheetId}") + sender.sendMessage("bet-betUnit = ${raceData.bet.betUnit}") + + } + + private fun UUID.toName(): String { + return Bukkit.getOfflinePlayer(this).name.toString() + } +} \ No newline at end of file diff --git a/src/main/kotlin/dev/nikomaru/raceassist/race/event/SetCentralPointEvent.kt b/src/main/kotlin/dev/nikomaru/raceassist/race/event/SetCentralPointEvent.kt index 7060df7..cdbcc7b 100644 --- a/src/main/kotlin/dev/nikomaru/raceassist/race/event/SetCentralPointEvent.kt +++ b/src/main/kotlin/dev/nikomaru/raceassist/race/event/SetCentralPointEvent.kt @@ -18,9 +18,9 @@ package dev.nikomaru.raceassist.race.event import dev.nikomaru.raceassist.data.files.PlaceSettingData -import dev.nikomaru.raceassist.utils.CommandUtils.canSetCentral -import dev.nikomaru.raceassist.utils.CommandUtils.centralRaceId import dev.nikomaru.raceassist.utils.Lang +import dev.nikomaru.raceassist.utils.Utils.canSetCentral +import dev.nikomaru.raceassist.utils.Utils.centralRaceId import org.bukkit.event.EventHandler import org.bukkit.event.Listener import org.bukkit.event.block.Action diff --git a/src/main/kotlin/dev/nikomaru/raceassist/race/event/SetInsideCircuitEvent.kt b/src/main/kotlin/dev/nikomaru/raceassist/race/event/SetInsideCircuitEvent.kt index 8dae791..77dde3b 100644 --- a/src/main/kotlin/dev/nikomaru/raceassist/race/event/SetInsideCircuitEvent.kt +++ b/src/main/kotlin/dev/nikomaru/raceassist/race/event/SetInsideCircuitEvent.kt @@ -17,9 +17,9 @@ package dev.nikomaru.raceassist.race.event import dev.nikomaru.raceassist.race.utils.InsideCircuit -import dev.nikomaru.raceassist.utils.CommandUtils.canSetInsideCircuit -import dev.nikomaru.raceassist.utils.CommandUtils.circuitRaceId import dev.nikomaru.raceassist.utils.Lang +import dev.nikomaru.raceassist.utils.Utils.canSetInsideCircuit +import dev.nikomaru.raceassist.utils.Utils.circuitRaceId import org.bukkit.event.EventHandler import org.bukkit.event.Listener import org.bukkit.event.block.Action diff --git a/src/main/kotlin/dev/nikomaru/raceassist/race/event/SetOutsideCircuitEvent.kt b/src/main/kotlin/dev/nikomaru/raceassist/race/event/SetOutsideCircuitEvent.kt index c724708..f346551 100644 --- a/src/main/kotlin/dev/nikomaru/raceassist/race/event/SetOutsideCircuitEvent.kt +++ b/src/main/kotlin/dev/nikomaru/raceassist/race/event/SetOutsideCircuitEvent.kt @@ -17,9 +17,9 @@ package dev.nikomaru.raceassist.race.event import dev.nikomaru.raceassist.race.utils.OutsideCircuit -import dev.nikomaru.raceassist.utils.CommandUtils.canSetOutsideCircuit -import dev.nikomaru.raceassist.utils.CommandUtils.circuitRaceId import dev.nikomaru.raceassist.utils.Lang +import dev.nikomaru.raceassist.utils.Utils.canSetOutsideCircuit +import dev.nikomaru.raceassist.utils.Utils.circuitRaceId import org.bukkit.event.EventHandler import org.bukkit.event.Listener import org.bukkit.event.block.Action diff --git a/src/main/kotlin/dev/nikomaru/raceassist/race/utils/InsideCircuit.kt b/src/main/kotlin/dev/nikomaru/raceassist/race/utils/InsideCircuit.kt index 2a9d538..183b5eb 100644 --- a/src/main/kotlin/dev/nikomaru/raceassist/race/utils/InsideCircuit.kt +++ b/src/main/kotlin/dev/nikomaru/raceassist/race/utils/InsideCircuit.kt @@ -18,9 +18,9 @@ package dev.nikomaru.raceassist.race.utils import dev.nikomaru.raceassist.RaceAssist.Companion.plugin import dev.nikomaru.raceassist.data.files.PlaceSettingData -import dev.nikomaru.raceassist.utils.CommandUtils.canSetInsideCircuit -import dev.nikomaru.raceassist.utils.CommandUtils.circuitRaceId import dev.nikomaru.raceassist.utils.Lang +import dev.nikomaru.raceassist.utils.Utils.canSetInsideCircuit +import dev.nikomaru.raceassist.utils.Utils.circuitRaceId import org.bukkit.Bukkit import org.bukkit.entity.Player import java.awt.Polygon diff --git a/src/main/kotlin/dev/nikomaru/raceassist/race/utils/OutsideCircuit.kt b/src/main/kotlin/dev/nikomaru/raceassist/race/utils/OutsideCircuit.kt index 3710713..b274a39 100644 --- a/src/main/kotlin/dev/nikomaru/raceassist/race/utils/OutsideCircuit.kt +++ b/src/main/kotlin/dev/nikomaru/raceassist/race/utils/OutsideCircuit.kt @@ -18,9 +18,9 @@ package dev.nikomaru.raceassist.race.utils import dev.nikomaru.raceassist.RaceAssist.Companion.plugin import dev.nikomaru.raceassist.data.files.PlaceSettingData -import dev.nikomaru.raceassist.utils.CommandUtils.canSetOutsideCircuit -import dev.nikomaru.raceassist.utils.CommandUtils.circuitRaceId import dev.nikomaru.raceassist.utils.Lang +import dev.nikomaru.raceassist.utils.Utils.canSetOutsideCircuit +import dev.nikomaru.raceassist.utils.Utils.circuitRaceId import org.bukkit.Bukkit import org.bukkit.entity.Player import java.awt.Polygon @@ -32,8 +32,6 @@ object OutsideCircuit { outsidePolygonMap.putIfAbsent(raceId, Polygon()) insidePolygonMap.putIfAbsent(raceId, PlaceSettingData.getInsidePolygon(raceId)) - - if (insidePolygonMap[raceId]!!.contains(x, z)) { player.sendActionBar(Lang.getComponent("to-click-inside-point", player.locale())) return diff --git a/src/main/kotlin/dev/nikomaru/raceassist/utils/Lang.kt b/src/main/kotlin/dev/nikomaru/raceassist/utils/Lang.kt index bd252a5..f2c7cf9 100644 --- a/src/main/kotlin/dev/nikomaru/raceassist/utils/Lang.kt +++ b/src/main/kotlin/dev/nikomaru/raceassist/utils/Lang.kt @@ -34,7 +34,7 @@ object Lang { suspend fun load() { withContext(Dispatchers.IO) { - val lang = listOf("ja_JP", "de_DE", "en_US", "fr_FR", "ko_KR", "zh_CN", "zh_TW") + val lang = listOf("ja_JP", "en_US") lang.forEach { locale -> val conf = Properties() diff --git a/src/main/kotlin/dev/nikomaru/raceassist/utils/CommandUtils.kt b/src/main/kotlin/dev/nikomaru/raceassist/utils/Utils.kt similarity index 76% rename from src/main/kotlin/dev/nikomaru/raceassist/utils/CommandUtils.kt rename to src/main/kotlin/dev/nikomaru/raceassist/utils/Utils.kt index 6932e8f..e85b655 100644 --- a/src/main/kotlin/dev/nikomaru/raceassist/utils/CommandUtils.kt +++ b/src/main/kotlin/dev/nikomaru/raceassist/utils/Utils.kt @@ -17,6 +17,8 @@ package dev.nikomaru.raceassist.utils +import com.github.shynixn.mccoroutine.bukkit.launch +import dev.nikomaru.raceassist.RaceAssist.Companion.plugin import dev.nikomaru.raceassist.data.files.PlaceSettingData import dev.nikomaru.raceassist.data.files.RaceSettingData import dev.nikomaru.raceassist.data.files.StaffSettingData.existStaff @@ -29,7 +31,7 @@ import org.jetbrains.exposed.sql.transactions.experimental.newSuspendedTransacti import java.util.* import kotlin.math.atan2 -object CommandUtils { +object Utils { val audience: HashMap> = HashMap() val canSetInsideCircuit = HashMap() @@ -39,7 +41,6 @@ object CommandUtils { val centralRaceId = HashMap() var stop = HashMap() - suspend fun getInsideRaceExist(raceId: String) = newSuspendedTransaction(Dispatchers.IO) { PlaceSettingData.getInsidePolygon(raceId).npoints > 0 } @@ -48,25 +49,33 @@ object CommandUtils { if (currentLap == null || beforeLap == null) { return } - if (currentLap > beforeLap) { - if (currentLap == lap - 1) { - player.showTitle(title((Lang.getComponent("last-lap", player.locale())), Lang.getComponent("one-step-forward-lap", player.locale()))) - } else { - player.showTitle(title(Lang.getComponent("now-lap", player.locale(), currentLap, lap), - Lang.getComponent("one-step-forward-lap", player.locale()))) - } - delay(40) - player.clearTitle() - } else if (currentLap < beforeLap) { - player.showTitle(title(Lang.getComponent("now-lap", player.locale(), currentLap, lap), - Lang.getComponent("one-step-backwards-lap", player.locale()))) - delay(40) - player.clearTitle() - + if (currentLap == lap) { + return } + plugin.launch { + val count: Long = 2000 + withContext(Dispatchers.Default) { + if (currentLap > beforeLap) { + if (currentLap == lap - 1) { + player.showTitle(title((Lang.getComponent("last-lap", player.locale())), + Lang.getComponent("one-step-forward-lap", player.locale()))) + } else { + player.showTitle(title(Lang.getComponent("now-lap", player.locale(), currentLap, lap), + Lang.getComponent("one-step-forward-lap", player.locale()))) + } + delay(count) + player.clearTitle() + } else if (currentLap < beforeLap) { + player.showTitle(title(Lang.getComponent("now-lap", player.locale(), currentLap, lap), + Lang.getComponent("one-step-backwards-lap", player.locale()))) + delay(count) + player.clearTitle() + } + } + }.join() } - suspend fun returnRaceSetting(raceId: String, player: CommandSender) = withContext(Dispatchers.IO) { + suspend fun returnCanRaceSetting(raceId: String, player: CommandSender) = withContext(Dispatchers.IO) { if (player is ConsoleCommandSender) { return@withContext true } @@ -138,6 +147,10 @@ object CommandUtils { } } + fun CommandSender.locale(): Locale { + return if (this is Player) this.locale() else Locale.getDefault() + } + suspend fun getCentralPoint(raceId: String, xPoint: Boolean): Int? = newSuspendedTransaction(Dispatchers.IO) { if (xPoint) { PlaceSettingData.getCentralXPoint(raceId) @@ -146,4 +159,8 @@ object CommandUtils { } } + fun String.toUUID(): UUID { + return UUID.fromString(this) + } + } \ No newline at end of file diff --git a/src/main/resources/lang/de_DE.properties b/src/main/resources/lang/de_DE.properties deleted file mode 100644 index cfa51a6..0000000 --- a/src/main/resources/lang/de_DE.properties +++ /dev/null @@ -1,113 +0,0 @@ -add-staff=Personal hinzugefügt -already-added-staff=Bereits hinzugefügt -already-exist-this-user=Der Spieler existiert bereits -already-joined=Bereits verbunden -already-setting-mode=Bereits im Konfigurationsmodus -already-used-the-name-race=Es wurde bereits eine Rennstrecke mit diesem Namen eingerichtet -bet-complete-message-owner={0} bet {1}circle -bet-complete-message-player=Zahl{0} : {1} bis {2}Kreis -bet-list-detail-message={0} {1} Spieler:{2} -> Reiter:{3} {4}Kreis -bet-remove-race-confirm-message=Um einen Einsatz mit {0}zu entfernen, führen Sie denselben Befehl innerhalb von 5 Sekunden erneut aus -bet-remove-race={0}Rennen entfernt -bet-revert-complete-message={0}Wetteinsätze abgeschlossen -bet-revert-race-confirm-message={0}Wenn alle Erstattungen für das Rennen fällig sind, führen Sie denselben Befehl innerhalb von 5 Sekunden erneut aus -bet-revert-return-message-owner={0}zurückgegeben{1}Kreis -bet-revert-return-message-player={0}bis{1}{2}{3}Der {0} über {1} wurde erstattet -betting-zero-money={0}Einheit Yen : 0 Yen multipliziert mit -can-bet-this-raceid={0}Auf Rennen kann jetzt gewettet werden -cannot-bet-this-raceid=Wetten sind nicht mehr möglich auf Rennen mit {0}. -cannot-decrease-more-money=Der Betrag kann nicht weiter reduziert werden -cant-remove-yourself-staff=Sie können sich nicht selbst aus dem Stab entfernen -cant-set-not-staff=Nicht-Personal kann nicht hinzugefügt werden -change-bet-rate-message={0}Wettquoten für Rennen mit{1}gesetzt -delete-staff=Personal entfernt -discord-webhook-name=Gestartet von:{0} Renn-ID:{1} -discord-webhook-ranking={0}Position. -finish-pay=Zahlung abgeschlossen -finish-race=Das Rennen ist vorbei. -finished-the-race=Erledigt -goal-degree-must-multiple-90=Der Zielwinkel muss ein Vielfaches von 90 sein -gui-cancel=Abbrechen. -gui-decide=Noch zu bestimmen. -gui-jockey-name=Reiter : {0} -gui-jockey-odds=Quoten : {0} -gui-need-money={0}Kreis erforderlich -gui-no-one-betting=Keiner hat darauf gewettet -gui-reset=Zurücksetzen. -joined-group=Teilnahme. -last-lap=Letzte Runde. -max-player-is-eight=Es können nur maximal 8 Spieler eingestellt werden -no-exist-central-point=Der Mittelpunkt existiert nicht -no-exist-goal-degree=Zielwinkel existiert nicht -no-exist-race=Rennen existiert nicht -no-exist-this-raceid-race={0}Rennen existiert nicht -no-have-money=Sie haben kein Geld -no-inside-course-set=Innerer Kurs nicht gesetzt -not-exsist-staff-this-player={0} existiert nicht -not-find-staff=Personal nicht gefunden -not-found-this-race=Diese Rasse wird nicht gefunden -now-betting-price={0}Kreiseinheit : {1}Kreis multipliziert mit -now-cannot-bet-race=Dieses Rennen ist derzeit nicht für Wetten verfügbar. -now-lap=Aktuell{0} / {1}Umschlag. -now-not-belong=Nicht teilnehmend -now-you-not-setting-mode=Sie befinden sich derzeit nicht im Konfigurationsmodus -one-step-backwards-lap=Ein Wrap zurückgegeben -one-step-forward-lap=Eine Umdrehung weiter. -only-race-creator-can-setting=Kann nicht für die Rasse eines anderen eingestellt werden -orientation-is-not-set=Ausrichtung nicht festgelegt -outside-the-racetrack=Kann sich außerhalb der Rennstrecke befinden -over-two-users-need=Mindestens zwei Benutzer sind erforderlich, um das Ereignis abzuhalten -paid-bet-creator={0}bezahlt{1}Yen -paid-bet-player=Name des Rennens : {0} {1}bis{2}Erstattung {3}bezahlt {3} ist bezahlt worden -participants-list=Liste der Teilnehmer -pay-confirm-bet-player={0}zahlt{1}den{2}Yen-Betrag{3}, der auf den {0} gesetzt wurde. -player-add-not-exist=Spieler mit diesem Namen nicht gefunden -player-add-to-race-group={0} hinzugefügt zu {1} -player-is-offline={0}ist offline -player-join={0}ist beigetreten -player-not-exist={0} existiert nicht -player-not-jockey={0} ist kein Reiter -player-ranking={0}/{1} Position. -race-remove-race-confirm-message=Um ein Rennen mit {0}zu entfernen, führen Sie denselben Befehl innerhalb von 5 Sekunden erneut aus -race-start=Das Rennen hat begonnen. -return-confirm-message=Innerhalb von 5 Sekunden erneut ausführen, um zu bezahlen -scoreboard-context=Debug-Modus -scoreboard-now-lap-and-now-degree=Runde{0} Runde Aktueller Winkel{1}° -scoreboard-now-ranking-and-name={0}Position {1} -scoreboard-now-ranking=Ranking. -scoreboard-ranking=Ranking -set-rate-message-in1-100=Bitte geben Sie eine Zahl zwischen 1 und 100 ein -sheet-bet-multiplier=Bettenverhältnis (%)->. -sheet-bet-price=Pfähle -sheet-jockey=Zielspieler. -sheet-minecraft-name=miklaname -sheet-timestamp=Zeitstempel -suspended-race=Von der Verwaltung suspendiert. -time-remaining=Verbleibende Zeit {0} Sekunden -to-be-inside-set-mode=Sie befinden sich jetzt im Modus der inneren Kurseinstellung -to-be-outside-set-mode=Sie befinden sich jetzt im Modus der äußeren Kurseinstellung -to-bet-one-unit=1 Einheit {0}Yen Einsatz -to-bet-ten-unit=10 Einheiten {0}Yen Einsatz -to-cancel-bet-one-unit=1 Einheit {0}Yen Niedriger -to-cancel-bet-ten-unit=10 Einheiten {0}Yen Niedriger -to-change-race-orientation=Ausrichtung des Rennens geändert -to-click-block=Klicken Sie auf den Block -to-click-inside-point=Der zu setzende Punkt muss außerhalb des gesetzten Punktes liegen -to-click-left-start-right-finish=Klicken Sie mit der linken Maustaste, um die Einstellung zu starten, und mit der rechten Maustaste, um sie zu unterbrechen. -to-click-next-point=Aktuelle Einstellposition: X = {0}, Z ={1} Nächster Punkt anklicken -to-create-race=Rennbahn erstellt -to-delete-all-player-from-race-group=Alle Spieler aus {0} entfernt -to-delete-player-from-race-group=Zielspieler aus {0} entfernt -to-delete-race-and-so-on=Die Daten über Rennstrecken und Spieler usw. wurden gelöscht. -to-enter-finish-message=Um die Konfiguration abzuschließen, geben Sie "/RaceAssist place finish" ein. -to-exit-the-group=Beenden. -to-finish-inside-course-setting=Einrichtung des inneren Kurses abgeschlossen -to-finish-outside-course-setting=Einstellung des äußeren Kurses abgeschlossen -to-need-enter-over-1=Bitte geben Sie eine Zahl ein, die größer oder gleich 1 ist -to-notice-ranking-message={0}Position {1} -to-notice-start-message=Start. -to-set-degree={0}Grad. -to-set-central-point=Mittelpunkt setzen -to-set-lap=Anzahl der eingestellten Runden -to-set-this-point-central=Zentrum gesetzt -to-suspend-process=Prozess unterbrochen. \ No newline at end of file diff --git a/src/main/resources/lang/fr_FR.properties b/src/main/resources/lang/fr_FR.properties deleted file mode 100644 index 254e5e0..0000000 --- a/src/main/resources/lang/fr_FR.properties +++ /dev/null @@ -1,113 +0,0 @@ -add-staff=Personnel ajouté -already-added-staff=既に追加されています -already-exist-this-user=Le joueur existe déjà -already-joined=Déjà rejoint -already-setting-mode=Déjà en mode configuration -already-used-the-name-race=Un hippodrome portant ce nom a déjà été mis en place. -bet-complete-message-owner={0} bet {1}circle -bet-complete-message-player=nombre{0} : {1} à {2}cercle -bet-list-detail-message={0} {1} Joueur :{2} -> Coureur :{3} {4}Cercle -bet-remove-race-confirm-message=Pour supprimer un pari avec {0}, exécutez à nouveau la même commande dans les 5 secondes qui suivent. -bet-remove-race={0}course supprimée -bet-revert-complete-message={0}le pari est terminé. -bet-revert-race-confirm-message={0}Si tous les remboursements sont dus sur la course, exécutez à nouveau la même commande dans les 5 secondes. -bet-revert-return-message-owner={0}retourné{1}cercle -bet-revert-return-message-player={0}à{1}{2}{3}Le {0} sur {1} a été remboursé. -betting-zero-money={0}Unité du yen : 0 yen multiplié par -can-bet-this-raceid={0}les courses peuvent maintenant être pariées. -cannot-bet-this-raceid=Les paris ne sont plus possibles sur les courses avec {0}. -cannot-decrease-more-money=Le montant ne peut plus être réduit. -cant-remove-yourself-staff=Vous ne pouvez pas vous retirer du personnel -cant-set-not-staff=Les non-membres du personnel ne peuvent pas être ajoutés. -change-bet-rate-message={0}taux de pari pour les courses avec{1}fixé -delete-staff=Personnel supprimé -discord-webhook-name=Commencé par :{0} ID de la course :{1} -discord-webhook-ranking={0}Position. -finish-pay=Paiement terminé -finish-race=La course est terminée. -finished-the-race=Terminé -goal-degree-must-multiple-90=L'angle du but doit être un multiple de 90 -gui-cancel=Annuler. -gui-decide=A déterminer. -gui-jockey-name=Rider : {0} -gui-jockey-odds=Odds : {0} -gui-need-money={0}Cercle requis -gui-no-one-betting=Pas de pari par personne -gui-reset=Réinitialisation. -joined-group=Participation. -last-lap=Dernier tour. -max-player-is-eight=Seul un maximum de 8 joueurs peut être défini. -no-exist-central-point=Le point central n'existe pas -no-exist-goal-degree=L'angle du but n'existe pas -no-exist-race=La course n'existe pas -no-exist-this-raceid-race={0}La course n'existe pas. -no-have-money=Vous n'avez pas d'argent -no-inside-course-set=Parcours intérieur non défini -not-exsist-staff-this-player={0} n'existe pas -not-find-staff=Personnel non trouvé -not-found-this-race=Cette course n'est pas trouvée -now-betting-price={0}Unité du cercle : {1}Cercle multiplié par -now-cannot-bet-race=Cette course est actuellement indisponible pour les paris. -now-lap=courant{0} / {1}enveloppement. -now-not-belong=Pas de participation -now-you-not-setting-mode=Vous n'êtes pas actuellement en mode configuration -one-step-backwards-lap=Une enveloppe retournée -one-step-forward-lap=Une enveloppe avancée. -only-race-creator-can-setting=Ne peut être défini pour la course de quelqu'un d'autre. -orientation-is-not-set=Orientation non définie -outside-the-racetrack=Peut être en dehors de l'hippodrome -over-two-users-need=Au moins deux utilisateurs sont nécessaires pour organiser l'événement. -paid-bet-creator={0}payé{1}yen -paid-bet-player=Nom de la course : {0} {1}à{2}remboursement {3}payé {3} a été payé -participants-list=Liste des participants -pay-confirm-bet-player={0}paie{1}le{2}paiement en yens{3}qui a été misé sur le {0}. -player-add-not-exist=Joueur avec ce nom non trouvé -player-add-to-race-group={0} ajouté à {1} -player-is-offline={0}est hors ligne -player-join={0}s'est joint à nous -player-not-exist={0} n'existe pas -player-not-jockey={0} n'est pas un cavalier -player-ranking={0}/{1} position. -race-remove-race-confirm-message=Pour supprimer une course avec {0}, exécutez à nouveau la même commande dans un délai de 5 secondes -race-start=La course a commencé. -return-confirm-message=Exécuter à nouveau dans les 5 secondes pour payer. -scoreboard-context=mode débogage -scoreboard-now-lap-and-now-degree=Lap{0} Lap Angle actuel{1}° -scoreboard-now-ranking-and-name={0}Position {1} -scoreboard-now-ranking=Classement. -scoreboard-ranking=classement -set-rate-message-in1-100=Veuillez entrer un nombre entre 1 et 100. -sheet-bet-multiplier=Rapport de lit (%)->. -sheet-bet-price=piquets -sheet-jockey=Les joueurs ciblés. -sheet-minecraft-name=miklaname -sheet-timestamp=Horodatage -suspended-race=Suspendu par l'administrateur. -time-remaining=Temps restant {0} secondes -to-be-inside-set-mode=Vous êtes maintenant en mode de réglage du parcours intérieur. -to-be-outside-set-mode=Vous êtes maintenant en mode de réglage de la trajectoire extérieure. -to-bet-one-unit=1 unité {0}yen Mise -to-bet-ten-unit=10 unités {0}yen Mise -to-cancel-bet-one-unit=1 unité {0}yen Plus bas -to-cancel-bet-ten-unit=10 unités {0}yen Plus bas -to-change-race-orientation=Changement d'orientation de la course -to-click-block=Cliquez sur le bloc -to-click-inside-point=Le point à fixer doit être en dehors de celui fixé à l'intérieur. -to-click-left-start-right-finish=Cliquez avec le bouton gauche de la souris pour commencer le réglage, avec le bouton droit pour l'interrompre. -to-click-next-point=Position de réglage actuelle : X = {0}, Z ={1} Cliquez sur le point suivant. -to-create-race=Piste de course créée -to-delete-all-player-from-race-group=Tous les joueurs retirés de {0} -to-delete-player-from-race-group=Suppression du joueur cible de {0} . -to-delete-race-and-so-on=Les données sur les hippodromes et les joueurs, etc. ont été supprimées. -to-enter-finish-message=Pour terminer la configuration, tapez "/RaceAssist place finish". -to-exit-the-group=Sortie. -to-finish-inside-course-setting=Terminé la mise en place du parcours intérieur. -to-finish-outside-course-setting=Fin de la mise en place du parcours extérieur. -to-need-enter-over-1=Veuillez entrer un nombre supérieur ou égal à 1. -to-notice-ranking-message={0}Position {1} -to-notice-start-message=Début. -to-set-degree={0}degré. -to-set-central-point=Définir le point central -to-set-lap=Nombre de tours établis -to-set-this-point-central=Centre set -to-suspend-process=Processus interrompu. \ No newline at end of file diff --git a/src/main/resources/lang/ja_JP.properties b/src/main/resources/lang/ja_JP.properties index 92153b5..22e9a99 100644 --- a/src/main/resources/lang/ja_JP.properties +++ b/src/main/resources/lang/ja_JP.properties @@ -8,7 +8,7 @@ bet-complete-message-owner={0}{1}円番号{0} : {1} に {2}円 bet-list-detail-message={0} {1} プレイヤー:{2} -> 騎手:{3} {4}円 bet-remove-race={0}のレースを削除しました -bet-revert-complete-message={0}の賭け金の返還を完了しました +bet-revert-complete-message=賭け金の返還を完了しました bet-revert-return-message-owner={0}に{1}円を返しました bet-revert-return-message-player={0}から{1}で{2}にかけていた{3}円が返金されました betting-zero-money={0}円単位 : 0円かけています @@ -16,27 +16,25 @@ can-bet-this-raceid={0}のレースにはベットが可能にな cannot-bet-this-raceid={0}ののレースにはベットが不可能になりました cannot-decrease-more-money=これ以上金額を減らすことはできません cant-remove-yourself-staff=自分自身をスタッフから削除することはできません -cant-set-not-staff=スタッフではない人を追加することはできません change-bet-rate-message={0}のレースのベットレートを{1}に設定しました +change-bet-unit-message={0}のレースの賭けの単位を{1}に設定しました delete-staff=スタッフを削除しました discord-webhook-name=開始した人:{0} レースID:{1} discord-webhook-ranking={0}位 finish-pay=支払いが完了しました finish-race=レースが終了しました finished-the-race=完走しました -goal-degree-must-multiple-90=ゴール角度は90の倍数である必要があります gui-cancel=キャンセルする gui-decide=決定する gui-jockey-name=騎手 : {0} gui-jockey-odds=オッズ : {0} gui-need-money={0}円必要です -gui-no-one-betting=誰にも賭けられていません +no-one-betting=誰にも賭けられていません gui-reset=リセットする joined-group=参加しました last-lap=最終ラップです max-player-is-eight=プレイヤーは最大で8人しか設定することはできません no-exist-central-point=中心点が存在しません -no-exist-goal-degree=ゴール角度が存在しません no-exist-race=レースが存在しません no-exist-this-raceid-race={0}のレースは存在しません no-have-money=あなたにはお金がありません @@ -52,13 +50,13 @@ now-you-not-setting-mode=あなたは設定モードに現在な one-step-backwards-lap=ラップが一つ戻りました one-step-forward-lap=ラップが一つ進みました only-race-creator-can-setting=他人のレースは設定できません -orientation-is-not-set=向きが設定されていません outside-the-racetrack=レース場外に出てる可能性があります over-two-users-need=開催には2人以上のユーザーが必要です paid-bet-creator={0}に{1}円支払いました paid-bet-player=レース名 : {0} {1}から{2}の払戻金 {3}円が支払われました participants-list=参加者一覧 -pay-confirm-bet-player={0}に{1}に賭けていた{2}円の支払額{3}円を支払います +player-remove-replacement=名前の置換を削除しました +player-set-replacement=名前の置換を設定しました player-add-not-exist=その名前のプレイヤーは見つかりません player-add-to-race-group={0} を {1} に追加しました player-is-offline={0}はオフラインです @@ -67,19 +65,18 @@ player-not-exist={0} は存在しません player-not-jockey={0} は騎手ではありません player-ranking={0}/{1} 位です race-start=レースが開始しました -return-confirm-message=支払う場合は5秒以内にもう一度実行してください scoreboard-context=デバッグモード scoreboard-now-lap-and-now-degree=ラップ{0} Lap 現在の角度{1}° scoreboard-now-ranking-and-name={0}位 {1} scoreboard-now-ranking=ランキング scoreboard-ranking=ranking -set-rate-message-in1-100=1から100までの数字を入力してください sheet-bet-multiplier=ベッド倍率 (%)-> sheet-bet-price=賭け金 sheet-jockey=対象プレイヤー sheet-minecraft-name=マイクラネーム sheet-timestamp=タイムスタンプ -suspended-race=管理者によって中断されました +suspended-race-by-operator=管理者によって中断されました +suspended-race-by-limit=レース時間の制限に達したため中断されました time-remaining=残り時間 {0} 秒 to-be-inside-set-mode=内側のコース設定モードになりました to-be-outside-set-mode=外側のコース設定モードになりました @@ -95,7 +92,6 @@ to-click-next-point=現在の設定位置: X = {0}, Z ={1} 次 to-create-race=レース場を作成しました to-delete-all-player-from-race-group={0} から全てのプレイヤーを削除しました to-delete-player-from-race-group={0} から対象のプレイヤーを削除しました -to-delete-race-and-so-on=レース場、及びプレイヤーなどのデータを削除しました to-enter-finish-message=設定を終了する場合は "/RaceAssist place finish" と入力してください to-exit-the-group=退出しました to-finish-inside-course-setting=内側のコース設定を終了しました @@ -109,7 +105,5 @@ to-set-lap=ラップ数を設定しました to-set-this-point-central=中心を設定しました to-suspend-process=処理を中断しました command-result-replacement-set-success=置換対象に{0}を{1}設定しました。 -command-replacement-remove-success=置換対象から{0}を削除しました。 -replacement-delete-success=置換対象を{0}に設定しました。 command-result-replacement-list-empty=置換対象が見つかりません。 command-result-replacement-list-message={0}スタッフを追加しました -already-added-staff=既に追加されています -already-exist-this-user=すでにそのプレイヤーは既に存在します -already-joined=すでに参加しています -already-setting-mode=すでに設定モードになっています -already-used-the-name-race=その名前のレース場は既に設定されています -bet-complete-message-owner={0}{1}円 を賭けました -bet-complete-message-player=番号{0} : {1} に {2}円 -bet-list-detail-message={0} {1} プレイヤー:{2} -> 騎手:{3} {4}円 -bet-remove-race-confirm-message={0}のベットを削除するには、5秒以内にもう一度同じコマンドを実行してください -bet-remove-race={0}のレースを削除しました -bet-revert-complete-message={0}の賭け金の返還を完了しました -bet-revert-race-confirm-message={0}のレースですべて返金する場合は、5秒以内にもう一度同じコマンドを実行してください -bet-revert-return-message-owner={0}に{1}円を返しました -bet-revert-return-message-player={0}から{1}で{2}にかけていた{3}円が返金されました -betting-zero-money={0}円単位 : 0円かけています -can-bet-this-raceid={0}のレースにはベットが可能になりました -cannot-bet-this-raceid={0}ののレースにはベットが不可能になりました -cannot-decrease-more-money=これ以上金額を減らすことはできません -cant-remove-yourself-staff=自分自身をスタッフから削除することはできません -cant-set-not-staff=スタッフではない人を追加することはできません -change-bet-rate-message={0}のレースのベットレートを{1}に設定しました -delete-staff=スタッフを削除しました -discord-webhook-name=開始した人:{0} レースID:{1} -discord-webhook-ranking={0}位 -finish-pay=支払いが完了しました -finish-race=レースが終了しました -finished-the-race=完走しました -goal-degree-must-multiple-90=ゴール角度は90の倍数である必要があります -gui-cancel=キャンセルする -gui-decide=決定する -gui-jockey-name=騎手 : {0} -gui-jockey-odds=オッズ : {0} -gui-need-money={0}円必要です -gui-no-one-betting=誰にも賭けられていません -gui-reset=リセットする -joined-group=参加しました -last-lap=最終ラップです -max-player-is-eight=プレイヤーは最大で8人しか設定することはできません -no-exist-central-point=中心点が存在しません -no-exist-goal-degree=ゴール角度が存在しません -no-exist-race=レースが存在しません -no-exist-this-raceid-race={0}のレースは存在しません -no-have-money=あなたにはお金がありません -no-inside-course-set=内側のコースが設定されていません -not-exsist-staff-this-player={0} は存在しません -not-find-staff=スタッフが見つかりませんでした -not-found-this-race=そのレースは見つかりません -now-betting-price={0}円単位 : {1}円かけています -now-cannot-bet-race=このレースは現在ベットできません。 -now-lap=現在{0} / {1}ラップです -now-not-belong=参加していません -now-you-not-setting-mode=あなたは設定モードに現在なっていません -one-step-backwards-lap=ラップが一つ戻りました -one-step-forward-lap=ラップが一つ進みました -only-race-creator-can-setting=他人のレースは設定できません -orientation-is-not-set=向きが設定されていません -outside-the-racetrack=レース場外に出てる可能性があります -over-two-users-need=開催には2人以上のユーザーが必要です -paid-bet-creator={0}に{1}円支払いました -paid-bet-player=レース名 : {0} {1}から{2}の払戻金 {3}円が支払われました -participants-list=参加者一覧 -pay-confirm-bet-player={0}に{1}に賭けていた{2}円の支払額{3}円を支払います -player-add-not-exist=その名前のプレイヤーは見つかりません -player-add-to-race-group={0} を {1} に追加しました -player-is-offline={0}はオフラインです -player-join={0}が参加しました -player-not-exist={0} は存在しません -player-not-jockey={0} は騎手ではありません -player-ranking={0}/{1} 位です -race-remove-race-confirm-message={0}のレースを削除するには、5秒以内にもう一度同じコマンドを実行してください -race-start=レースが開始しました -return-confirm-message=支払う場合は5秒以内にもう一度実行してください -scoreboard-context=デバッグモード -scoreboard-now-lap-and-now-degree=ラップ{0} Lap 現在の角度{1}° -scoreboard-now-ranking-and-name={0}位 {1} -scoreboard-now-ranking=ランキング -scoreboard-ranking=ranking -set-rate-message-in1-100=1から100までの数字を入力してください -sheet-bet-multiplier=ベッド倍率 (%)-> -sheet-bet-price=賭け金 -sheet-jockey=対象プレイヤー -sheet-minecraft-name=マイクラネーム -sheet-timestamp=タイムスタンプ -suspended-race=管理者によって中断されました -time-remaining=残り時間 {0} 秒 -to-be-inside-set-mode=内側のコース設定モードになりました -to-be-outside-set-mode=外側のコース設定モードになりました -to-bet-one-unit=1単位 {0}円 賭ける -to-bet-ten-unit=10単位 {0}円 賭ける -to-cancel-bet-one-unit=1単位 {0}円 下げる -to-cancel-bet-ten-unit=10単位 {0}円 下げる -to-change-race-orientation=レースの向きを変更しました -to-click-block=ブロックをクリックしてください -to-click-inside-point=設定する点は内側に設定した物より外にしてください -to-click-left-start-right-finish=左クリックで設定を開始し,右クリックで中断します -to-click-next-point=現在の設定位置: X = {0}, Z ={1} 次の点をクリックしてください -to-create-race=レース場を作成しました -to-delete-all-player-from-race-group={0} から全てのプレイヤーを削除しました -to-delete-player-from-race-group={0} から対象のプレイヤーを削除しました -to-delete-race-and-so-on=レース場、及びプレイヤーなどのデータを削除しました -to-enter-finish-message=設定を終了する場合は "/RaceAssist place finish" と入力してください -to-exit-the-group=退出しました -to-finish-inside-course-setting=内側のコース設定を終了しました -to-finish-outside-course-setting=外側のコース設定を終了しました -to-need-enter-over-1=1以上の数字を入力してください -to-notice-ranking-message={0}位 {1} -to-notice-start-message=スタートです -to-set-degree={0}度にしました -to-set-central-point=中心点を設定してください -to-set-lap=ラップ数を設定しました -to-set-this-point-central=中心を設定しました -to-suspend-process=処理を中断しました \ No newline at end of file diff --git a/src/main/resources/lang/zh_CN.properties b/src/main/resources/lang/zh_CN.properties deleted file mode 100644 index c41baa5..0000000 --- a/src/main/resources/lang/zh_CN.properties +++ /dev/null @@ -1,113 +0,0 @@ -add-staff=添加的工作人员 -already-added-staff=已经添加了 -already-exist-this-user=该玩家已经存在。 -already-joined=已经加入了 -already-setting-mode=已经进入配置模式 -already-used-the-name-race=一个具有该名称的赛马场已经被建立起来了。 -bet-complete-message-owner={0} bet {1}circle -bet-complete-message-player=数字{0} : {1} 至 {2}圆圈 -bet-list-detail-message={0} {1} プレイヤー:{2} -> 騎手:{3} {4}円 -bet-remove-race-confirm-message=要删除带有{0}的赌注,请在5秒内再次运行相同的命令 -bet-remove-race={0}移除比赛 -bet-revert-complete-message={0}赌注返回完成 -bet-revert-race-confirm-message={0}如果所有退款都在比赛中到期,在5秒内再次运行相同的命令 -bet-revert-return-message-owner={0}返回{1}圆形 -bet-revert-return-message-player={0}到{1}{2}{3}超过{0} 的部分被退还了 -betting-zero-money={0}日元单位:0日元乘以 -can-bet-this-raceid={0}现在可以投注的比赛 -cannot-bet-this-raceid=在{0}的比赛中,不再可能进行投注。 -cannot-decrease-more-money=该金额不能再减少了 -cant-remove-yourself-staff=你不能将自己从工作人员中删除 -cant-set-not-staff=不能添加非工作人员 -change-bet-rate-message={0}设置了{1}的比赛的投注率 -delete-staff=工作人员被删除 -discord-webhook-name=始作俑者:{0} 比赛编号:{1} -discord-webhook-ranking={0}位置。 -finish-pay=付款完毕 -finish-race=比赛已经结束。 -finished-the-race=已完成 -goal-degree-must-multiple-90=目标角度必须是90的倍数 -gui-cancel=取消。 -gui-decide=待定。 -gui-jockey-name=骑士 : {0} -gui-jockey-odds=赔率 : {0} -gui-need-money={0}圈子要求 -gui-no-one-betting=没有人下注 -gui-reset=复位。 -joined-group=参与。 -last-lap=最后一圈。 -max-player-is-eight=最多只能设置8名球员 -no-exist-central-point=中心点不存在 -no-exist-goal-degree=目标角度不存在 -no-exist-race=种族不存在 -no-exist-this-raceid-race={0}种族不存在 -no-have-money=你没有钱 -no-inside-course-set=内部课程没有设置 -not-exsist-staff-this-player={0} 不存在 -not-find-staff=未找到工作人员 -not-found-this-race=没有找到那个种族。 -now-betting-price={0}圆的单位 : {1}圆乘以 -now-cannot-bet-race=这场比赛目前无法进行投注。 -now-lap=当前{0} / {1}包裹。 -now-not-belong=不参与 -now-you-not-setting-mode=你目前没有进入配置模式 -one-step-backwards-lap=返回了一个包页 -one-step-forward-lap=一包先进。 -only-race-creator-can-setting=不能为别人的比赛设置。 -orientation-is-not-set=方向未设定 -outside-the-racetrack=可能在赛马场外。 -over-two-users-need=至少需要两个用户才能举行该活动 -paid-bet-creator={0}已支付{1}日元 -paid-bet-player=比赛名称 : {0} {1}到{2}退款 {3}已付款{3}已经支付。 -participants-list=与会者名单 -pay-confirm-bet-player={0}に{1}に賭けていた{2}円の支払額{3}円を支払います -player-add-not-exist=未找到该名称的玩家 -player-add-to-race-group={0} 被添加到 {1} 中。 -player-is-offline={0}已离线 -player-join={0}已加入 -player-not-exist={0} 不存在 -player-not-jockey={0} 不是一个骑手 -player-ranking={0}/{1} 位置。 -race-remove-race-confirm-message=要删除带有{0}的竞赛,请在5秒内再次运行相同的命令 -race-start=比赛已经开始。 -return-confirm-message=在5秒内再次运行,以支付 -scoreboard-context=调试模式 -scoreboard-now-lap-and-now-degree=圈数{0} 圈数 当前角度{1}°。 -scoreboard-now-ranking-and-name={0}位置 {1} -scoreboard-now-ranking=排名。 -scoreboard-ranking=排名 -set-rate-message-in1-100=请在1至100之间输入一个数字 -sheet-bet-multiplier=床位比例(%)->。 -sheet-bet-price=赌注 -sheet-jockey=目标球员。 -sheet-minecraft-name=米克兰名 -sheet-timestamp=时间戳 -suspended-race=被管理员暂停。 -time-remaining=剩余时间 {0} 秒 -to-be-inside-set-mode=你现在处于内部课程设置模式。 -to-be-outside-set-mode=你现在处于外部航线设置模式中 -to-bet-one-unit=1个单位 {0}日元赌注 -to-bet-ten-unit=10个单位 {0}日元投注 -to-cancel-bet-one-unit=1个单位 {0}日元 下限 -to-cancel-bet-ten-unit=10个单位 {0}日元 下限 -to-change-race-orientation=比赛方向改变了 -to-click-block=点击该区块 -to-click-inside-point=被设置的点必须在内部设置的点之外。 -to-click-left-start-right-finish=左键单击开始设置,右键单击中断。 -to-click-next-point=当前设置位置:X = {0}, Z ={1} 点击下一个点 -to-create-race=创建的赛马场 -to-delete-all-player-from-race-group=所有球员从{0} 中移除。 -to-delete-player-from-race-group=从{0} 中删除了目标球员。 -to-delete-race-and-so-on=有关赛马场和球员等的数据已被删除。 -to-enter-finish-message=要完成配置,输入"/RaceAssist place finish"。 -to-exit-the-group=退出。 -to-finish-inside-course-setting=完成了内部课程的设置 -to-finish-outside-course-setting=完成了外部课程的设置 -to-need-enter-over-1=请输入一个大于或等于1的数字 -to-notice-ranking-message={0}位置 {1} -to-notice-start-message=开始。 -to-set-degree={0}度。 -to-set-central-point=设置中心点 -to-set-lap=设置的圈数 -to-set-this-point-central=中心设置 -to-suspend-process=进程中断。 \ No newline at end of file diff --git a/src/main/resources/lang/zh_TW.properties b/src/main/resources/lang/zh_TW.properties deleted file mode 100644 index 0651c7c..0000000 --- a/src/main/resources/lang/zh_TW.properties +++ /dev/null @@ -1,113 +0,0 @@ -add-staff=スタッフを追加しました -already-added-staff=既に追加されています -already-exist-this-user=すでにそのプレイヤーは既に存在します -already-joined=すでに参加しています -already-setting-mode=すでに設定モードになっています -already-used-the-name-race=その名前のレース場は既に設定されています -bet-complete-message-owner={0}{1}円 を賭けました -bet-complete-message-player=番号{0} : {1} に {2}円 -bet-list-detail-message={0} {1} プレイヤー:{2} -> 騎手:{3} {4}円 -bet-remove-race-confirm-message={0}のベットを削除するには、5秒以内にもう一度同じコマンドを実行してください -bet-remove-race={0}のレースを削除しました -bet-revert-complete-message={0}の賭け金の返還を完了しました -bet-revert-race-confirm-message={0}のレースですべて返金する場合は、5秒以内にもう一度同じコマンドを実行してください -bet-revert-return-message-owner={0}に{1}円を返しました -bet-revert-return-message-player={0}から{1}で{2}にかけていた{3}円が返金されました -betting-zero-money={0}円単位 : 0円かけています -can-bet-this-raceid={0}のレースにはベットが可能になりました -cannot-bet-this-raceid={0}ののレースにはベットが不可能になりました -cannot-decrease-more-money=これ以上金額を減らすことはできません -cant-remove-yourself-staff=自分自身をスタッフから削除することはできません -cant-set-not-staff=スタッフではない人を追加することはできません -change-bet-rate-message={0}のレースのベットレートを{1}に設定しました -delete-staff=スタッフを削除しました -discord-webhook-name=開始した人:{0} レースID:{1} -discord-webhook-ranking={0}位 -finish-pay=支払いが完了しました -finish-race=レースが終了しました -finished-the-race=完走しました -goal-degree-must-multiple-90=ゴール角度は90の倍数である必要があります -gui-cancel=キャンセルする -gui-decide=決定する -gui-jockey-name=騎手 : {0} -gui-jockey-odds=オッズ : {0} -gui-need-money={0}円必要です -gui-no-one-betting=誰にも賭けられていません -gui-reset=リセットする -joined-group=参加しました -last-lap=最終ラップです -max-player-is-eight=プレイヤーは最大で8人しか設定することはできません -no-exist-central-point=中心点が存在しません -no-exist-goal-degree=ゴール角度が存在しません -no-exist-race=レースが存在しません -no-exist-this-raceid-race={0}のレースは存在しません -no-have-money=あなたにはお金がありません -no-inside-course-set=内側のコースが設定されていません -not-exsist-staff-this-player={0} は存在しません -not-find-staff=スタッフが見つかりませんでした -not-found-this-race=そのレースは見つかりません -now-betting-price={0}円単位 : {1}円かけています -now-cannot-bet-race=このレースは現在ベットできません。 -now-lap=現在{0} / {1}ラップです -now-not-belong=参加していません -now-you-not-setting-mode=あなたは設定モードに現在なっていません -one-step-backwards-lap=ラップが一つ戻りました -one-step-forward-lap=ラップが一つ進みました -only-race-creator-can-setting=他人のレースは設定できません -orientation-is-not-set=向きが設定されていません -outside-the-racetrack=レース場外に出てる可能性があります -over-two-users-need=開催には2人以上のユーザーが必要です -paid-bet-creator={0}に{1}円支払いました -paid-bet-player=レース名 : {0} {1}から{2}の払戻金 {3}円が支払われました -participants-list=参加者一覧 -pay-confirm-bet-player={0}に{1}に賭けていた{2}円の支払額{3}円を支払います -player-add-not-exist=その名前のプレイヤーは見つかりません -player-add-to-race-group={0} を {1} に追加しました -player-is-offline={0}はオフラインです -player-join={0}が参加しました -player-not-exist={0} は存在しません -player-not-jockey={0} は騎手ではありません -player-ranking={0}/{1} 位です -race-remove-race-confirm-message={0}のレースを削除するには、5秒以内にもう一度同じコマンドを実行してください -race-start=レースが開始しました -return-confirm-message=支払う場合は5秒以内にもう一度実行してください -scoreboard-context=デバッグモード -scoreboard-now-lap-and-now-degree=ラップ{0} Lap 現在の角度{1}° -scoreboard-now-ranking-and-name={0}位 {1} -scoreboard-now-ranking=ランキング -scoreboard-ranking=ranking -set-rate-message-in1-100=1から100までの数字を入力してください -sheet-bet-multiplier=ベッド倍率 (%)-> -sheet-bet-price=賭け金 -sheet-jockey=対象プレイヤー -sheet-minecraft-name=マイクラネーム -sheet-timestamp=タイムスタンプ -suspended-race=管理者によって中断されました -time-remaining=残り時間 {0} 秒 -to-be-inside-set-mode=内側のコース設定モードになりました -to-be-outside-set-mode=外側のコース設定モードになりました -to-bet-one-unit=1単位 {0}円 賭ける -to-bet-ten-unit=10単位 {0}円 賭ける -to-cancel-bet-one-unit=1単位 {0}円 下げる -to-cancel-bet-ten-unit=10単位 {0}円 下げる -to-change-race-orientation=レースの向きを変更しました -to-click-block=ブロックをクリックしてください -to-click-inside-point=設定する点は内側に設定した物より外にしてください -to-click-left-start-right-finish=左クリックで設定を開始し,右クリックで中断します -to-click-next-point=現在の設定位置: X = {0}, Z ={1} 次の点をクリックしてください -to-create-race=レース場を作成しました -to-delete-all-player-from-race-group={0} から全てのプレイヤーを削除しました -to-delete-player-from-race-group={0} から対象のプレイヤーを削除しました -to-delete-race-and-so-on=レース場、及びプレイヤーなどのデータを削除しました -to-enter-finish-message=設定を終了する場合は "/RaceAssist place finish" と入力してください -to-exit-the-group=退出しました -to-finish-inside-course-setting=内側のコース設定を終了しました -to-finish-outside-course-setting=外側のコース設定を終了しました -to-need-enter-over-1=1以上の数字を入力してください -to-notice-ranking-message={0}位 {1} -to-notice-start-message=スタートです -to-set-degree={0}度にしました -to-set-central-point=中心点を設定してください -to-set-lap=ラップ数を設定しました -to-set-this-point-central=中心を設定しました -to-suspend-process=処理を中断しました \ No newline at end of file