diff --git a/build.gradle.kts b/build.gradle.kts index 234a54d..a222800 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -1,14 +1,14 @@ -import net.minecrell.pluginyml.bukkit.BukkitPluginDescription +import net.minecrell.pluginyml.paper.PaperPluginDescription group = "net.hareworks" -version = "1.1" +version = "1.2" val exposedVersion = "0.54.0" plugins { - kotlin("jvm") version "2.0.20" - kotlin("plugin.serialization") version "2.0.20" - id("net.minecrell.plugin-yml.bukkit") version "0.6.0" + kotlin("jvm") version "2.2.21" + kotlin("plugin.serialization") version "2.2.21" + id("de.eldoria.plugin-yml.paper") version "0.8.0" id("com.gradleup.shadow") version "9.2.2" } repositories { @@ -18,6 +18,8 @@ repositories { } dependencies { compileOnly("io.papermc.paper:paper-api:1.21.10-R0.1-SNAPSHOT") + compileOnly("org.jetbrains.kotlin:kotlin-stdlib") + compileOnly("net.hareworks:kommand-lib:1.1") implementation("net.kyori:adventure-api:4.17.0") implementation("net.kyori:adventure-text-minimessage:4.17.0") implementation("org.jetbrains.kotlinx:kotlinx-serialization-json:1.7.1") @@ -28,78 +30,34 @@ dependencies { implementation("org.jetbrains.kotlinx:kotlinx-datetime:0.6.1") implementation("org.jetbrains.exposed:exposed-kotlin-datetime:$exposedVersion") implementation("de.tr7zw:item-nbt-api:2.15.3") - implementation("com.michael-bull.kotlin-result:kotlin-result:2.0.0") } tasks { shadowJar { + minimize() archiveBaseName.set("SimplyMCDB") archiveClassifier.set("") relocate("de.tr7zw.changeme.nbtapi", "net.hareworks.simplymcdb.libs.nbtapi") } - - build { - dependsOn(shadowJar) + jar { + enabled = false } } -bukkit { +paper { main = "net.hareworks.simplymcdb.App" name = "Simply-Minecraft-DB" description = "It provides a simple way to manage player data through a database." version = getVersion().toString() - apiVersion = "1.21.10" - authors = - listOf("Hare-K02") - permissions { - register("simplydb.*") { - children = listOf("simplydb.command", "simplydb.admin") + apiVersion = "1.21.10" + authors = listOf( + "Hare-K02" + ) + serverDependencies { + register("kommand-lib") { + load = PaperPluginDescription.RelativeLoadOrder.BEFORE } - register("simplydb.command") { - description = "Allows access to the /simplydb command" - default = BukkitPluginDescription.Permission.Default.TRUE + register("permits-lib") { + load = PaperPluginDescription.RelativeLoadOrder.BEFORE } - register("simplydb.command.*") { - children = listOf( - "simplydb.command.config", - "simplydb.command.config.*", - "simplydb.command.on", - "simplydb.command.off", - ) - } - register("simplydb.command.config") { - description = "Allows access to the /simplydb config command" - default = BukkitPluginDescription.Permission.Default.OP - } - register("simplydb.command.config.*") { - children = listOf( - "simplydb.command.config.reload", - "simplydb.command.config.fetch", - "simplydb.command.config.upload", - ) - } - register("simplydb.command.config.reload") { - description = "Allows access to the /simplydb config reload command" - default = BukkitPluginDescription.Permission.Default.OP - } - register("simplydb.command.config.fetch") { - description = "Allows access to the /simplydb config fetch command" - default = BukkitPluginDescription.Permission.Default.OP - } - register("simplydb.command.config.upload") { - description = "Allows access to the /simplydb config upload command" - default = BukkitPluginDescription.Permission.Default.OP - } - register("simplydb.command.on") { - description = "Allows access to the /simplydb on command" - default = BukkitPluginDescription.Permission.Default.OP - } - register("simplydb.command.off") { - description = "Allows access to the /simplydb off command" - default = BukkitPluginDescription.Permission.Default.OP - } - register("simplydb.admin") { - description = "Allows configration/manage simplydb" - default = BukkitPluginDescription.Permission.Default.OP - } - } + } } diff --git a/flake.nix b/flake.nix index 7f61bf2..0103621 100644 --- a/flake.nix +++ b/flake.nix @@ -36,10 +36,6 @@ export PATH="$JAVA_HOME/bin:$PATH" export GRADLE_USER_HOME="$PWD/.gradle" - - echo "Loaded Minecraft dev env (JDK 21 + Gradle)" - java -version || true - gradle --version || true ''; }; } diff --git a/gradle.properties b/gradle.properties new file mode 100644 index 0000000..0d6aa7b --- /dev/null +++ b/gradle.properties @@ -0,0 +1 @@ +kotlin.stdlib.default.dependency=false diff --git a/settings.gradle.kts b/settings.gradle.kts new file mode 100644 index 0000000..0f85abe --- /dev/null +++ b/settings.gradle.kts @@ -0,0 +1,3 @@ +rootProject.name = "simply-mcdb" + +includeBuild("../kommand-lib") diff --git a/src/main/kotlin/net/hareworks/kommandlib/main.kt b/src/main/kotlin/net/hareworks/kommandlib/main.kt deleted file mode 100644 index 66b124a..0000000 --- a/src/main/kotlin/net/hareworks/kommandlib/main.kt +++ /dev/null @@ -1,147 +0,0 @@ -package net.hareworks.kommandlib - -import com.github.michaelbull.result.* -import kotlin.collections.listOf -import org.bukkit.Bukkit -import org.bukkit.command.CommandMap -import org.bukkit.command.CommandSender -import org.bukkit.command.PluginCommand -import org.bukkit.command.TabCompleter -import org.bukkit.plugin.java.JavaPlugin -import net.hareworks.simplymcdb.App - -class KommandLib(plugin: JavaPlugin, vararg routes: Argument) { - val entries = routes.toList() - init { - val f = Bukkit.getServer().javaClass.getDeclaredField("commandMap") - f.isAccessible = true - val commandMap = f.get(Bukkit.getServer()) as CommandMap - for (route in routes) { - commandMap.register( - plugin.getName(), - (PluginCommand::class - .java - .declaredConstructors - .first() - .apply { isAccessible = true } - .newInstance(route.name, plugin) as - PluginCommand) - .apply { - this.name = name - this.setExecutor { sender, _, alias, args -> - val routeargs = routeTreeSearch(arrayOf(alias, *args)) - if (routeargs.size == args.size + 1) - routeargs.last().onCommand(sender, args) - true - } - this.tabCompleter = TabCompleter { sender, _, alias, args -> - val routeargs = routeTreeSearch(arrayOf(alias, *args)) - if (routeargs.size == args.size) - routeargs.last().getCompletList(sender, args) - else listOf() - } - } - ) - } - } - - fun routeTreeSearch(args: Array): List { - val list = - mutableListOf( - entries.find { it.name == args[0] } ?: throw Exception("Invalid command") - ) - var i = 1 - while (i + 1 <= args.size) { - if (list.last().routes.isEmpty()) break - val route = list.last().routes.sortedBy { it.priority }.find { it.name == args[i] } ?: break - list.add(route) - i += route.unit - } - return list - } - - fun unregister() { - val f = Bukkit.getServer().javaClass.getDeclaredField("commandMap") - f.isAccessible = true - val commandMap = f.get(Bukkit.getServer()) as CommandMap - for (route in entries) { - commandMap.getCommand(route.name)?.unregister(commandMap) - } - } -} - -abstract class Argument( - val argname: String, - vararg routes: Argument, - val execute: (CommandSender, Array) -> Unit -) { - val name = argname - var routes = routes.toList() - var permission: String = "" - set(value) { - field = value - if (value.isEmpty()) return - for (route in routes) { - route.permission = value + "." + route.name - } - } - var condition: (CommandSender) -> Boolean = { true } - - public fun addArgs(vararg routes: Argument): Argument { - this.routes += routes - return this - } - - abstract var priority: Int - open var unit: Int = 1 - open fun onCommand(sender: CommandSender, args: Array) { - execute(sender, args) - } - - abstract fun suggest(sender: CommandSender, args: Array): List - - fun getCompletList(sender: CommandSender, args: Array): List { - return routes - .filter { sender.hasPermission(it.permission) && it.condition(sender) } - .map { it.suggest(sender, args) } - .flatten() - } -} - -class Route( - name: String, - vararg routes: Argument, - execute: (CommandSender, Array) -> Unit -) : Argument(name, *routes, execute = execute) { - override var priority: Int = 2 - - override fun suggest(sender: CommandSender, args: Array): List { - return if (sender.hasPermission(this.permission) && - this.condition(sender) && - this.name.startsWith(args.last()) - ) - listOf(this.name) - else listOf() - } -} - -class Text(name: String, vararg routes: Argument, execute: (CommandSender, Array) -> Unit) : - Argument(name, *routes, execute = execute) { - override var priority: Int = 0 - - override fun suggest(sender: CommandSender, args: Array): List { - return listOf(args.last()) - } -} - -class Integer( - name: String, - vararg routes: Argument, - execute: (CommandSender, Array) -> Unit -) : Argument(name, *routes, execute = execute) { - override var priority: Int = 1 - - override fun suggest(sender: CommandSender, args: Array): List { - return listOf() - } -} \ No newline at end of file diff --git a/src/main/kotlin/net/hareworks/simplymcdb/App.kt b/src/main/kotlin/net/hareworks/simplymcdb/App.kt index 37de7c7..108c4b1 100644 --- a/src/main/kotlin/net/hareworks/simplymcdb/App.kt +++ b/src/main/kotlin/net/hareworks/simplymcdb/App.kt @@ -1,7 +1,7 @@ package net.hareworks.simplymcdb -import net.hareworks.kommandlib.KommandLib -import net.hareworks.simplymcdb.command.smcdb +import net.hareworks.kommand_lib.KommandLib +import net.hareworks.simplymcdb.command.registerCommands import net.hareworks.simplymcdb.database.Database import org.bukkit.plugin.java.JavaPlugin @@ -30,7 +30,7 @@ public class App : JavaPlugin() { override fun onEnable() { instance = this Config.init() - command = KommandLib(this, smcdb) + command = registerCommands(this) server.pluginManager.registerEvents(EventListener, this) @@ -59,4 +59,4 @@ public class App : JavaPlugin() { logger.info("simplymcdb disabled.") enabled = State.DISABLED } -} \ No newline at end of file +} diff --git a/src/main/kotlin/net/hareworks/simplymcdb/Command.kt b/src/main/kotlin/net/hareworks/simplymcdb/Command.kt index 8ff5766..9ae7702 100644 --- a/src/main/kotlin/net/hareworks/simplymcdb/Command.kt +++ b/src/main/kotlin/net/hareworks/simplymcdb/Command.kt @@ -1,287 +1,267 @@ package net.hareworks.simplymcdb.command -import com.github.michaelbull.result.* -import net.hareworks.kommandlib.* -import net.hareworks.simplymcdb.* +import java.util.UUID +import net.hareworks.kommand_lib.KommandLib +import net.hareworks.kommand_lib.kommand +import net.hareworks.simplymcdb.App +import net.hareworks.simplymcdb.Config +import net.hareworks.simplymcdb.State import net.hareworks.simplymcdb.database.Database +import net.hareworks.simplymcdb.fetch +import net.hareworks.simplymcdb.findPlayersNeedingMigration +import net.hareworks.simplymcdb.isRegistered +import net.hareworks.simplymcdb.overwritePlayerData +import net.hareworks.simplymcdb.register +import net.hareworks.simplymcdb.update +import net.hareworks.simplymcdb.PlayerSerializer import net.kyori.adventure.audience.Audience import net.kyori.adventure.text.minimessage.MiniMessage import org.bukkit.entity.Player +import org.bukkit.plugin.java.JavaPlugin + +private val miniMessage = MiniMessage.miniMessage() +private val commandBuffer = mutableMapOf() public fun Audience.sendMM(message: String) { - this.sendMessage(MiniMessage.miniMessage().deserialize(message)) + this.sendMessage(miniMessage.deserialize(message)) } -val command_buffer = mutableMapOf() -public val smcdb = - Route("smcdb") { sender, _ -> sender.sendMessage("simptlymcdb command") } - .addArgs( - Route("config") { sender, _ -> - (sender as Player).performCommand("smcdb config help") - } - .addArgs( - Route("reload") { sender, _ -> - sender.sendMessage("reloading config...") - Config.reload() - sender.sendMessage("reloaded.") - }, - Route("fetch") { sender, _ -> - sender.sendMessage("fetching config...") - }, - Route("upload") { sender, _ -> - sender.sendMessage("uploading config...") - }, - Route("help") { sender, _ -> - var help = - MiniMessage.miniMessage() - .deserialize( - "simplymcdb config helpreload: reload the config from config.ymlfetch: fetch the config from the databaseupload: upload the current config to the database" - ) - sender.sendMessage(help) - } - ), - Route("help") { sender, _ -> - sender.sendMM( - "simplymcdb helpconfig: configre the pluginactivate: when the plugin is disabled, activate itdeactivate: when the plugin is enabled, deactivate it" - ) - }, - Route("activate") { sender, _ -> - if (App.instance.enabled == State.ACTIVE) { - sender.sendMessage("simplymcdb is already enabled.") - return@Route - } - App.instance.enable() - sender.sendMessage("simplymcdb enabled.") - }, - Route("deactivate") { sender, _ -> - if (App.instance.enabled == State.DISABLED) { - sender.sendMessage("simplymcdb is already disabled.") - return@Route - } - App.instance.disable() - sender.sendMessage("simplymcdb disabled.") - }, - Route("database") { _, _ -> } - .addArgs( - Route("init") { sender, _ -> - Database.initialize() - sender.sendMessage("database initialized.") - }, - Route("reset") { sender, _ -> - Database.reset() - sender.sendMessage("database reset.") - }, - ), - Route("migrate") { sender, _ -> - if (sender !is Player) { - sender.sendMM("[SMCDB] This command can only be run by players.") - return@Route - } - when (App.instance.enabled) { - State.DISABLED -> { - sender.sendMM("[SMCDB] simplymcdb is disabled.") - return@Route - } - State.DISCONNECTED -> { - sender.sendMM("[SMCDB] Database disconnected. Try again later.") - return@Route - } - else -> {} - } - if (!isRegistered(sender.uniqueId)) { - sender.sendMM("[SMCDB] You are not registered in the database.") - return@Route - } - try { - sender.sendMM("[SMCDB] Applying legacy data...") - fetch(sender) - update(sender) - sender.sendMM("[SMCDB] Migration complete. Data updated to the latest format.") - } catch (e: Exception) { - App.instance.logger.warning("Failed to migrate data for ${sender.uniqueId}: ${e.message}") - sender.sendMM("[SMCDB] Migration failed. Check server logs.") - } - }.addArgs( - Route("all") { sender, _ -> - if (sender !is Player) { - sender.sendMM("[SMCDB] This command can only be run by players.") - return@Route - } - when (App.instance.enabled) { - State.DISABLED -> { - sender.sendMM("[SMCDB] simplymcdb is disabled.") - return@Route - } - State.DISCONNECTED -> { - sender.sendMM( - "[SMCDB] Database disconnected. Try again later." - ) - return@Route - } - else -> {} - } - val targets = findPlayersNeedingMigration() - if (targets.isEmpty()) { - sender.sendMM("[SMCDB] No legacy data found.") - return@Route - } - sender.sendMM( - "[SMCDB] Migrating ${targets.size} legacy profiles... Please wait." - ) - val backup = PlayerSerializer.serialize(sender) - var migrated = 0 - try { - targets.forEach { entry -> - try { - PlayerSerializer.deserialize(sender, entry.serialized) - val updatedSnapshot = PlayerSerializer.serialize(sender) - overwritePlayerData(entry.uuid, updatedSnapshot) - migrated++ - } catch (ex: Exception) { - App.instance.logger.warning( - "Failed to migrate data for ${entry.uuid}: ${ex.message}" - ) - } - } - } finally { - try { - PlayerSerializer.deserialize(sender, backup) - } catch (restoreEx: Exception) { - App.instance.logger.warning( - "Failed to restore migration executor state: ${restoreEx.message}" - ) - } - } - sender.sendMM( - "[SMCDB] Migration finished ($migrated/${targets.size}). Check logs for failures." - ) - } - ), - Route("check") { sender, _ -> - sender.sendMM( - "${when (App.instance.enabled) { - State.ACTIVE -> "●" - State.DISCONNECTED -> "■" - State.DISABLED -> "○" - }} simply-minecraft-database" - ) - sender.sendMM( - "status: ${when (App.instance.enabled) { - State.ACTIVE -> "active" - State.DISCONNECTED -> "disconnected" - State.DISABLED -> "disabled"}}" - ) - sender.sendMM( - "- database test: ${if (Database.ping()) "success" else "failed"}" - ) - sender.sendMM( - "- config test: ${if (Config.config.getBoolean("enabled")) "enabled" else "disabled"}" - ) - }, - Route("register") { sender, _ -> - if (sender !is Player) { - sender.sendMM("This command is only available for players.") - return@Route - } else - when (App.instance.enabled) { - State.DISABLED -> - sender.sendMM( - "[SMCDB] simplymcdb is disabled.
Run /smcdb check to check the status." - ) - State.DISCONNECTED -> - sender.sendMM( - "[SMCDB] simplymcdb is enabled but disconnected.
Run /smcdb check to check the status." - ) - else -> { - if (!isRegistered(sender.uniqueId)) { - sender.sendMM( - "[SMCDB] The inventory of the other servers will be overwritten." + - "Are you sure you want to register?" + - "/smcdb confirm to confirm." - ) - } else { - sender.sendMM("[SMCDB] You are already registered.") - } - } - } - }, - Route("confirm") { sender, _ -> - if (sender !is Player) return@Route - when (command_buffer[sender.uniqueId]) { - "register" -> { - if (App.instance.enabled == State.ACTIVE) { - register(sender) - sender.sendMM("[SMCDB] Successfully registered.") - } else { - sender.sendMM("[SMCDB] simplymcdb is disabled.") - } - } - else -> { - sender.sendMM("[SMCDB] Invalid command.") - } - } - command_buffer.remove(sender.uniqueId) - } - // Route("update") { sender, _ -> - // if (sender !is Player) { - // sender.sendMM("This command is only available for players.") - // return@Route - // } else - // when (App.instance.enabled) { - // State.DISABLED -> - // sender.sendMM( - // "[SMCDB] simplymcdb is disabled.
Run - // /smcdb check to check the status." - // ) - // State.DISCONNECTED -> - // sender.sendMM( - // "[SMCDB] simplymcdb is enabled but - // disconnected.
Run /smcdb check to check the status." - // ) - // else -> { - // if (isRegistered(sender.uniqueId)) { - // update(sender) - // sender.sendMM("[SMCDB] Successfully updated.") - // } else { - // sender.sendMM("[SMCDB] You are not registered.") - // } - // } - // } - // }, - // Route("fetch") { sender, _ -> - // if (sender !is Player) { - // sender.sendMM("This command is only available for players.") - // return@Route - // } else - // when (App.instance.enabled) { - // State.DISABLED -> - // sender.sendMM( - // "[SMCDB] simplymcdb is disabled.
Run - // /smcdb check to check the status." - // ) - // State.DISCONNECTED -> - // sender.sendMM( - // "[SMCDB] simplymcdb is enabled but - // disconnected.
Run /smcdb check to check the status." - // ) - // else -> { - // if (isRegistered(sender.uniqueId)) { - // sender.sendMM( - // "[SMCDB] Welcome back, - // ${sender.name}.Fetching your data..." - // ) - // fetch(sender) - // } else { - // sender.sendMM( - // "[SMCDB] Welcome, ${sender.name}." - // + - // "SMCDB is active but you have already - // played before." + - // "Run /smcdb register to - // register yourself." - // ) - // } - // } - // } - // }, - ) +private fun Audience.sendConfigHelp() { + sendMM( + "simplymcdb config helpreload: reload the config from config.ymlfetch: fetch the config from the databaseupload: upload the current config to the database") +} + +public fun registerCommands(plugin: JavaPlugin): KommandLib = + kommand(plugin) { + command("smcdb") { + description = "Control Simply-Minecraft-DB" + permission = "simplydb.command" + + executes { + sender.sendMessage("simplymcdb command") + } + + literal("config") { + requires("simplydb.command.config") + executes { sender.sendConfigHelp() } + + literal("reload") { + requires("simplydb.command.config.reload") + executes { + sender.sendMessage("reloading config...") + Config.reload() + sender.sendMessage("reloaded.") + } + } + + literal("fetch") { + requires("simplydb.command.config.fetch") + executes { sender.sendMessage("fetching config...") } + } + + literal("upload") { + requires("simplydb.command.config.upload") + executes { sender.sendMessage("uploading config...") } + } + + literal("help") { executes { sender.sendConfigHelp() } } + } + + literal("help") { + executes { + sender.sendMM( + "simplymcdb helpconfig: configre the pluginactivate: when the plugin is disabled, activate itdeactivate: when the plugin is enabled, deactivate it") + } + } + + literal("activate") { + requires("simplydb.command.on") + executes { + if (App.instance.enabled == State.ACTIVE) { + sender.sendMessage("simplymcdb is already enabled.") + return@executes + } + App.instance.enable() + sender.sendMessage("simplymcdb enabled.") + } + } + + literal("deactivate") { + requires("simplydb.command.off") + executes { + if (App.instance.enabled == State.DISABLED) { + sender.sendMessage("simplymcdb is already disabled.") + return@executes + } + App.instance.disable() + sender.sendMessage("simplymcdb disabled.") + } + } + + literal("database") { + literal("init") { + executes { + Database.initialize() + sender.sendMessage("database initialized.") + } + } + literal("reset") { + executes { + Database.reset() + sender.sendMessage("database reset.") + } + } + } + + literal("migrate") { + executes { + val player = sender as? Player + if (player == null) { + sender.sendMM("[SMCDB] This command can only be run by players.") + return@executes + } + when (App.instance.enabled) { + State.DISABLED -> { + sender.sendMM("[SMCDB] simplymcdb is disabled.") + return@executes + } + State.DISCONNECTED -> { + sender.sendMM("[SMCDB] Database disconnected. Try again later.") + return@executes + } + else -> {} + } + if (!isRegistered(player.uniqueId)) { + sender.sendMM("[SMCDB] You are not registered in the database.") + return@executes + } + try { + sender.sendMM("[SMCDB] Applying legacy data...") + fetch(player) + update(player) + sender.sendMM("[SMCDB] Migration complete. Data updated to the latest format.") + } catch (e: Exception) { + App.instance.logger.warning("Failed to migrate data for ${player.uniqueId}: ${e.message}") + sender.sendMM("[SMCDB] Migration failed. Check server logs.") + } + } + + literal("all") { + executes { + val executor = sender as? Player + if (executor == null) { + sender.sendMM("[SMCDB] This command can only be run by players.") + return@executes + } + when (App.instance.enabled) { + State.DISABLED -> { + sender.sendMM("[SMCDB] simplymcdb is disabled.") + return@executes + } + State.DISCONNECTED -> { + sender.sendMM("[SMCDB] Database disconnected. Try again later.") + return@executes + } + else -> {} + } + val targets = findPlayersNeedingMigration() + if (targets.isEmpty()) { + sender.sendMM("[SMCDB] No legacy data found.") + return@executes + } + sender.sendMM("[SMCDB] Migrating ${targets.size} legacy profiles... Please wait.") + val backup = PlayerSerializer.serialize(executor) + var migrated = 0 + try { + targets.forEach { entry -> + try { + PlayerSerializer.deserialize(executor, entry.serialized) + val updatedSnapshot = PlayerSerializer.serialize(executor) + overwritePlayerData(entry.uuid, updatedSnapshot) + migrated++ + } catch (ex: Exception) { + App.instance.logger.warning("Failed to migrate data for ${entry.uuid}: ${ex.message}") + } + } + } finally { + try { + PlayerSerializer.deserialize(executor, backup) + } catch (restoreEx: Exception) { + App.instance.logger.warning("Failed to restore migration executor state: ${restoreEx.message}") + } + } + sender.sendMM("[SMCDB] Migration finished ($migrated/${targets.size}). Check logs for failures.") + } + } + } + + literal("check") { + executes { + sender.sendMM( + "${when (App.instance.enabled) { + State.ACTIVE -> "●" + State.DISCONNECTED -> "■" + State.DISABLED -> "○" + }} simply-minecraft-database") + sender.sendMM( + "status: ${when (App.instance.enabled) { + State.ACTIVE -> "active" + State.DISCONNECTED -> "disconnected" + State.DISABLED -> "disabled" + }}") + sender.sendMM( + "- database test: ${if (Database.ping()) "success" else "failed"}") + sender.sendMM( + "- config test: ${if (Config.config.getBoolean("enabled")) "enabled" else "disabled"}") + } + } + + literal("register") { + executes { + val player = sender as? Player + if (player == null) { + sender.sendMM("This command is only available for players.") + return@executes + } + when (App.instance.enabled) { + State.DISABLED -> { + sender.sendMM("[SMCDB] simplymcdb is disabled.
Run /smcdb check to check the status.") + return@executes + } + State.DISCONNECTED -> { + sender.sendMM("[SMCDB] simplymcdb is enabled but disconnected.
Run /smcdb check to check the status.") + return@executes + } + else -> {} + } + if (!isRegistered(player.uniqueId)) { + sender.sendMM( + "[SMCDB] The inventory of the other servers will be overwritten." + + "Are you sure you want to register?" + + "/smcdb confirm to confirm.") + commandBuffer[player.uniqueId] = "register" + } else { + sender.sendMM("[SMCDB] You are already registered.") + } + } + } + + literal("confirm") { + executes { + val player = sender as? Player ?: return@executes + when (commandBuffer[player.uniqueId]) { + "register" -> { + if (App.instance.enabled == State.ACTIVE) { + register(player) + sender.sendMM("[SMCDB] Successfully registered.") + } else { + sender.sendMM("[SMCDB] simplymcdb is disabled.") + } + } + else -> sender.sendMM("[SMCDB] Invalid command.") + } + commandBuffer.remove(player.uniqueId) + } + } + } + }