Skip to content

Commit

Permalink
Merge pull request #22 from Nlkomaru/features/change-config
Browse files Browse the repository at this point in the history
Features/change config
  • Loading branch information
Nlkomaru authored Jul 2, 2022
2 parents a98881d + d40b167 commit 171f7b5
Show file tree
Hide file tree
Showing 73 changed files with 1,752 additions and 1,596 deletions.
55 changes: 35 additions & 20 deletions build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ plugins {
id("xyz.jpenilla.run-paper") version "1.0.6"
id("org.sonarqube") version "3.3"
id("net.minecrell.plugin-yml.bukkit") version "0.5.1"
kotlin("plugin.serialization") version "1.6.10"
}

group = "dev.nikomaru"
Expand All @@ -25,27 +26,38 @@ repositories {
}

val cloudVersion = "1.6.2"
val exposedVersion = "0.37.3"
val exposedVersion = "0.38.2"
dependencies {
compileOnly("io.papermc.paper:paper-api:1.18.2-R0.1-SNAPSHOT")
compileOnly("com.github.MilkBowl:VaultAPI:1.7")
implementation("org.jetbrains.kotlin:kotlin-stdlib-jdk8")
implementation("cloud.commandframework:cloud-core:$cloudVersion")
implementation("cloud.commandframework:cloud-kotlin-extensions:$cloudVersion")
implementation("cloud.commandframework:cloud-paper:$cloudVersion")
implementation("cloud.commandframework:cloud-annotations:$cloudVersion")
implementation("org.jetbrains.kotlin:kotlin-stdlib:1.6.10-RC")
implementation("org.jetbrains.kotlinx:kotlinx-coroutines-core:1.6.1")
implementation("com.github.shynixn.mccoroutine:mccoroutine-bukkit-api:2.2.0")
implementation("com.github.shynixn.mccoroutine:mccoroutine-bukkit-core:2.2.0")
implementation("org.jetbrains.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("com.google.api-client:google-api-client:1.33.4")
implementation("com.google.oauth-client:google-oauth-client-jetty:1.33.2")
implementation("com.google.apis:google-api-services-sheets:v4-rev20220308-1.32.1")
compileOnly("io.papermc.paper", "paper-api", "1.19-R0.1-SNAPSHOT")

library(kotlin("stdlib"))

compileOnly("com.github.MilkBowl", "VaultAPI", "1.7")

implementation("cloud.commandframework", "cloud-core", cloudVersion)
implementation("cloud.commandframework", "cloud-kotlin-extensions", cloudVersion)
implementation("cloud.commandframework", "cloud-paper", cloudVersion)
implementation("cloud.commandframework", "cloud-annotations", cloudVersion)
implementation("cloud.commandframework", "cloud-kotlin-coroutines-annotations", cloudVersion)
implementation("cloud.commandframework", "cloud-kotlin-coroutines", cloudVersion)

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-coroutines-core", "1.6.2")

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

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

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

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

Expand All @@ -68,6 +80,9 @@ tasks {
build {
dependsOn(shadowJar)
}
runServer {
minecraftVersion("1.19")
}
}


Expand All @@ -78,7 +93,7 @@ bukkit {

main = "dev.nikomaru.raceassist.RaceAssist"

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

Expand Down
1 change: 0 additions & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
# suppress inspection "UnusedProperty" for whole file
# suppress inspection "UnusedProperty" for whole file
kotlin.code.style=official
exposedVersion=0.37.3
cloudVersion=1.6.2
29 changes: 16 additions & 13 deletions src/main/kotlin/dev/nikomaru/raceassist/RaceAssist.kt
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
/*
* Copyright © 2021-2022 Nikomaru <[email protected]>
* This program is free software: you can redistribute it and/or modify
* Copyright © 2021-2022 Nikomaru <[email protected]>
*
* 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.
Expand All @@ -15,17 +16,20 @@
*/
package dev.nikomaru.raceassist

import cloud.commandframework.annotations.AnnotationParser
import cloud.commandframework.bukkit.CloudBukkitCapabilities
import cloud.commandframework.execution.AsynchronousCommandExecutionCoordinator
import cloud.commandframework.kotlin.coroutines.annotations.installCoroutineSupport
import cloud.commandframework.meta.SimpleCommandMeta
import cloud.commandframework.paper.PaperCommandManager
import com.github.shynixn.mccoroutine.bukkit.SuspendingJavaPlugin
import com.github.shynixn.mccoroutine.bukkit.registerSuspendingEvents
import dev.nikomaru.raceassist.api.VaultAPI
import dev.nikomaru.raceassist.bet.commands.*
import dev.nikomaru.raceassist.bet.event.BetGuiClickEvent
import dev.nikomaru.raceassist.database.*
import dev.nikomaru.raceassist.data.database.BetList
import dev.nikomaru.raceassist.files.Config
import dev.nikomaru.raceassist.horse.event.HorseBreedEvent
import dev.nikomaru.raceassist.race.commands.HelpCommand
import dev.nikomaru.raceassist.race.commands.audience.*
import dev.nikomaru.raceassist.race.commands.place.*
Expand All @@ -37,20 +41,19 @@ import dev.nikomaru.raceassist.utils.CommandSuggestions
import dev.nikomaru.raceassist.utils.Lang
import dev.nikomaru.raceassist.utils.coroutines.minecraft
import kotlinx.coroutines.withContext
import kotlinx.serialization.ExperimentalSerializationApi
import org.bukkit.command.CommandSender
import org.bukkit.configuration.file.YamlConfiguration
import org.jetbrains.exposed.sql.SchemaUtils
import org.jetbrains.exposed.sql.transactions.transaction
import java.io.File

class RaceAssist : SuspendingJavaPlugin() {

@OptIn(ExperimentalSerializationApi::class)
override suspend fun onEnableAsync() {
// Plugin startup logic
plugin = this
Lang.load()
saveDefaultConfig()
Config.config = YamlConfiguration.loadConfiguration(File(dataFolder, "config.yml"))
Config.load()
settingDatabase()
setCommand()
Expand All @@ -63,7 +66,7 @@ class RaceAssist : SuspendingJavaPlugin() {
private fun settingDatabase() {
org.jetbrains.exposed.sql.Database.connect(url = "jdbc:sqlite:${plugin.dataFolder}${File.separator}RaceAssist.db", driver = "org.sqlite.JDBC")
transaction {
SchemaUtils.create(CircuitPoint, PlayerList, RaceList, BetList, BetSetting, RaceStaff)
SchemaUtils.create(BetList)
}
}

Expand All @@ -74,18 +77,18 @@ class RaceAssist : SuspendingJavaPlugin() {
private fun setCommand() {

val commandManager: PaperCommandManager<CommandSender> = PaperCommandManager(this,
AsynchronousCommandExecutionCoordinator.simpleCoordinator(),
AsynchronousCommandExecutionCoordinator.newBuilder<CommandSender>().build(),
java.util.function.Function.identity(),
java.util.function.Function.identity())


if (commandManager.queryCapability(CloudBukkitCapabilities.ASYNCHRONOUS_COMPLETION)) {
commandManager.registerAsynchronousCompletions()
}
val annotationParser: cloud.commandframework.annotations.AnnotationParser<CommandSender> =
cloud.commandframework.annotations.AnnotationParser(commandManager, CommandSender::class.java) {
SimpleCommandMeta.empty()
}

val annotationParser = AnnotationParser(commandManager, CommandSender::class.java) {
SimpleCommandMeta.empty()
}.installCoroutineSupport()

annotationParser.parse(CommandSuggestions())

Expand Down Expand Up @@ -118,7 +121,6 @@ class RaceAssist : SuspendingJavaPlugin() {
annotationParser.parse(BetSheetCommand())
annotationParser.parse(BetRemoveCommand())
annotationParser.parse(BetReturnCommand())
annotationParser.parse(BetTransfarCommand())

annotationParser.parse(SettingCreateCommand())
annotationParser.parse(SettingDeleteCommand())
Expand All @@ -133,6 +135,7 @@ class RaceAssist : SuspendingJavaPlugin() {
server.pluginManager.registerSuspendingEvents(SetOutsideCircuitEvent(), this)
server.pluginManager.registerSuspendingEvents(SetCentralPointEvent(), this)
server.pluginManager.registerSuspendingEvents(BetGuiClickEvent(), this)
server.pluginManager.registerSuspendingEvents(HorseBreedEvent(), this)
}

companion object {
Expand Down
5 changes: 3 additions & 2 deletions src/main/kotlin/dev/nikomaru/raceassist/api/VaultAPI.kt
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
/*
* Copyright © 2021-2022 Nikomaru <[email protected]>
* This program is free software: you can redistribute it and/or modify
* Copyright © 2021-2022 Nikomaru <[email protected]>
*
* 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.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
/*
* Copyright © 2021-2022 Nikomaru <[email protected]>
* This program is free software: you can redistribute it and/or modify
* Copyright © 2021-2022 Nikomaru <[email protected]>
*
* 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.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
/*
* Copyright © 2021-2022 Nikomaru <[email protected]>
* This program is free software: you can redistribute it and/or modify
* Copyright © 2021-2022 Nikomaru <[email protected]>
*
* 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.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
/*
* Copyright © 2021-2022 Nikomaru <[email protected]>
* This program is free software: you can redistribute it and/or modify
* Copyright © 2021-2022 Nikomaru <[email protected]>
*
* 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.
Expand All @@ -14,8 +15,6 @@
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/

package dev.nikomaru.raceassist.utils

import java.util.*
package dev.nikomaru.raceassist.bet

data class TempBetData(val raceId: String, val uuid: UUID, val jockey: UUID, var bet: Int)
object BetUtils {}
23 changes: 12 additions & 11 deletions src/main/kotlin/dev/nikomaru/raceassist/bet/GuiComponent.kt
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
/*
* Copyright © 2021-2022 Nikomaru <[email protected]>
* This program is free software: you can redistribute it and/or modify
* Copyright © 2021-2022 Nikomaru <[email protected]>
*
* 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.
Expand All @@ -16,7 +17,7 @@

package dev.nikomaru.raceassist.bet

import dev.nikomaru.raceassist.files.Config.betUnit
import dev.nikomaru.raceassist.data.files.BetSettingData
import dev.nikomaru.raceassist.utils.Lang
import net.kyori.adventure.text.Component
import org.bukkit.Material
Expand All @@ -30,34 +31,34 @@ object GuiComponent {
return Component.text("レース賭け自販機")
}

fun onceUp(locale: Locale): ItemStack {
suspend fun onceUp(locale: Locale, raceId: String): ItemStack {
val onceUp = ItemStack(Material.PINK_STAINED_GLASS_PANE)
val onceUpMeta: ItemMeta = onceUp.itemMeta
onceUpMeta.displayName(Lang.getComponent("to-bet-one-unit", locale, betUnit))
onceUpMeta.displayName(Lang.getComponent("to-bet-one-unit", locale, BetSettingData.getBetUnit(raceId)))
onceUp.itemMeta = onceUpMeta
return onceUp
}

fun onceDown(locale: Locale): ItemStack {
suspend fun onceDown(locale: Locale, raceId: String): ItemStack {
val onceDown = ItemStack(Material.LIGHT_BLUE_STAINED_GLASS_PANE)
val onceDownMeta: ItemMeta = onceDown.itemMeta
onceDownMeta.displayName(Lang.getComponent("to-cancel-bet-one-unit", locale, betUnit))
onceDownMeta.displayName(Lang.getComponent("to-cancel-bet-one-unit", locale, BetSettingData.getBetUnit(raceId)))
onceDown.itemMeta = onceDownMeta
return onceDown
}

fun tenTimesUp(locale: Locale): ItemStack {
suspend fun tenTimesUp(locale: Locale, raceId: String): ItemStack {
val tenTimesUp = ItemStack(Material.RED_STAINED_GLASS_PANE)
val tenTimesUpMeta: ItemMeta = tenTimesUp.itemMeta
tenTimesUpMeta.displayName(Lang.getComponent("to-bet-ten-unit", locale, betUnit * 10))
tenTimesUpMeta.displayName(Lang.getComponent("to-bet-ten-unit", locale, BetSettingData.getBetUnit(raceId) * 10))
tenTimesUp.itemMeta = tenTimesUpMeta
return tenTimesUp
}

fun tenTimesDown(locale: Locale): ItemStack {
suspend fun tenTimesDown(locale: Locale, raceId: String): ItemStack {
val tenTimesDown = ItemStack(Material.BLUE_STAINED_GLASS_PANE)
val tenTimesDownMeta: ItemMeta = tenTimesDown.itemMeta
tenTimesDownMeta.displayName(Lang.getComponent("to-cancel-bet-ten-unit", locale, betUnit * 10))
tenTimesDownMeta.displayName(Lang.getComponent("to-cancel-bet-ten-unit", locale, BetSettingData.getBetUnit(raceId) * 10))
tenTimesDown.itemMeta = tenTimesDownMeta
return tenTimesDown
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
/*
* Copyright © 2021-2022 Nikomaru <[email protected]>
* This program is free software: you can redistribute it and/or modify
* Copyright © 2021-2022 Nikomaru <[email protected]>
*
* 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.
Expand All @@ -17,52 +18,38 @@
package dev.nikomaru.raceassist.bet.commands

import cloud.commandframework.annotations.*
import com.github.shynixn.mccoroutine.bukkit.launch
import dev.nikomaru.raceassist.RaceAssist.Companion.plugin
import dev.nikomaru.raceassist.database.BetSetting
import dev.nikomaru.raceassist.data.files.BetSettingData
import dev.nikomaru.raceassist.utils.CommandUtils
import dev.nikomaru.raceassist.utils.Lang
import kotlinx.coroutines.Dispatchers
import org.bukkit.command.CommandSender
import org.bukkit.entity.Player
import org.jetbrains.exposed.sql.transactions.experimental.newSuspendedTransaction
import org.jetbrains.exposed.sql.update
import java.util.*

@CommandMethod("ra|RaceAssist bet")
class BetCanCommand {
@CommandPermission("RaceAssist.commands.bet.can")
@CommandMethod("can <raceId> <type>")
fun setCanBet(sender: CommandSender,
suspend fun setCanBet(sender: CommandSender,
@Argument(value = "raceId", suggestions = "raceId") raceId: String,
@Argument(value = "type", suggestions = "betType") type: String) {
plugin.launch {
if (CommandUtils.returnRaceSetting(raceId, sender)) return@launch
if (type == "on") {
setCanBet(raceId, sender)
} else if (type == "off") {
setCannotBet(raceId, sender)
}
if (CommandUtils.returnRaceSetting(raceId, sender)) return
if (type == "on") {
setCanBet(raceId, sender)
} else if (type == "off") {
setCannotBet(raceId, sender)
}

}

private suspend fun setCanBet(raceId: String, sender: CommandSender) {
newSuspendedTransaction(Dispatchers.IO) {
BetSetting.update({ BetSetting.raceId eq raceId }) {
it[canBet] = true
}
}
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))
}

companion object {
suspend fun setCannotBet(raceId: String, sender: CommandSender) {
newSuspendedTransaction(Dispatchers.IO) {
BetSetting.update({ BetSetting.raceId eq raceId }) {
it[canBet] = false
}
}
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))
Expand Down
Loading

0 comments on commit 171f7b5

Please sign in to comment.