From 5a3d759c70330d0340c3c903d9a4356859367c0d Mon Sep 17 00:00:00 2001 From: Boy Date: Thu, 31 Oct 2024 17:10:26 +0100 Subject: [PATCH] refactor: swap to brigadier commands --- gradle.properties | 2 +- gradle/libs.versions.toml | 2 +- .../mineinabyss/staminaclimb/StaminaAddon.kt | 10 +++ .../staminaclimb/StaminaClimbPlugin.kt | 12 ++-- .../staminaclimb/StaminaCommands.kt | 70 ++++++------------- 5 files changed, 38 insertions(+), 58 deletions(-) create mode 100644 src/main/kotlin/com/mineinabyss/staminaclimb/StaminaAddon.kt diff --git a/gradle.properties b/gradle.properties index 5e792b8..14add0f 100644 --- a/gradle.properties +++ b/gradle.properties @@ -1,3 +1,3 @@ group=com.mineinabyss version=0.23 -idofrontVersion=0.25.5 +idofrontVersion=0.25.17 diff --git a/gradle/libs.versions.toml b/gradle/libs.versions.toml index 4db52d8..f9c0c82 100644 --- a/gradle/libs.versions.toml +++ b/gradle/libs.versions.toml @@ -1,5 +1,5 @@ [versions] -geary = "0.30.17" +geary = "0.31.0" [libraries] geary-papermc = { module = "com.mineinabyss:geary-papermc", version.ref = "geary" } diff --git a/src/main/kotlin/com/mineinabyss/staminaclimb/StaminaAddon.kt b/src/main/kotlin/com/mineinabyss/staminaclimb/StaminaAddon.kt new file mode 100644 index 0000000..92b6140 --- /dev/null +++ b/src/main/kotlin/com/mineinabyss/staminaclimb/StaminaAddon.kt @@ -0,0 +1,10 @@ +package com.mineinabyss.staminaclimb + +import com.mineinabyss.geary.addons.dsl.createAddon +import com.mineinabyss.geary.autoscan.autoscan + +val StaminaAddon = createAddon("StaminaClimb", configuration = { + autoscan(StaminaClimbPlugin::class.java.classLoader, "com.mineinabyss.staminaclimb") { + all() + } +}) \ No newline at end of file diff --git a/src/main/kotlin/com/mineinabyss/staminaclimb/StaminaClimbPlugin.kt b/src/main/kotlin/com/mineinabyss/staminaclimb/StaminaClimbPlugin.kt index 87b80f7..94648cb 100644 --- a/src/main/kotlin/com/mineinabyss/staminaclimb/StaminaClimbPlugin.kt +++ b/src/main/kotlin/com/mineinabyss/staminaclimb/StaminaClimbPlugin.kt @@ -1,7 +1,7 @@ package com.mineinabyss.staminaclimb -import com.mineinabyss.geary.autoscan.autoscan -import com.mineinabyss.geary.modules.geary +import com.mineinabyss.geary.papermc.configure +import com.mineinabyss.geary.papermc.gearyPaper import com.mineinabyss.idofront.di.DI import com.mineinabyss.idofront.plugin.listeners import com.mineinabyss.staminaclimb.climbing.ClimbBehaviour @@ -20,10 +20,8 @@ import org.bukkit.plugin.java.JavaPlugin class StaminaClimbPlugin : JavaPlugin() { override fun onLoad() { createClimbContext() - geary { - autoscan(classLoader, "com.mineinabyss.staminaclimb") { - all() - } + gearyPaper.configure { + install(StaminaAddon) } } @@ -34,7 +32,7 @@ class StaminaClimbPlugin : JavaPlugin() { Bukkit.getOnlinePlayers().forEach(::registerBar) listeners(ClimbBehaviour, StaminaBar) - StaminaCommands() + StaminaCommands.registerCommands() Tags.interceptConfigPhaseTagPacket() } diff --git a/src/main/kotlin/com/mineinabyss/staminaclimb/StaminaCommands.kt b/src/main/kotlin/com/mineinabyss/staminaclimb/StaminaCommands.kt index b31f7b0..303788f 100644 --- a/src/main/kotlin/com/mineinabyss/staminaclimb/StaminaCommands.kt +++ b/src/main/kotlin/com/mineinabyss/staminaclimb/StaminaCommands.kt @@ -1,64 +1,36 @@ package com.mineinabyss.staminaclimb -import com.mineinabyss.idofront.commands.execution.IdofrontCommandExecutor -import com.mineinabyss.idofront.commands.extensions.actions.playerAction +import com.mineinabyss.idofront.commands.brigadier.commands import com.mineinabyss.idofront.messaging.info import com.mineinabyss.idofront.messaging.success import com.mineinabyss.staminaclimb.climbing.ClimbBehaviour import com.mineinabyss.staminaclimb.modules.stamina import com.mineinabyss.staminaclimb.nms.Tags import com.mineinabyss.staminaclimb.stamina.StaminaBar -import org.bukkit.command.Command -import org.bukkit.command.CommandSender -import org.bukkit.command.TabCompleter -class StaminaCommands : IdofrontCommandExecutor(), TabCompleter { - override val commands = commands(stamina.plugin) { - "climb" { - permission = "staminaclimb.toggle" - playerAction { - player.climbEnabled = !player.climbEnabled - if (player.climbEnabled) Tags.enableClimb(player) - else Tags.disableClimb(player) - player.info("Stamina and climbing system: ${if (player.climbEnabled) "ON" else "OFF"}!") - } - } - "staminaclimb" { - "reload" { - action { - stamina.staminaTask.cancel() - stamina.plugin.createClimbContext() - stamina.staminaTask.runTaskTimer(stamina.plugin, 0, 1) - StaminaBar.conf = stamina.config - ClimbBehaviour.conf = stamina.config - sender.success("Config has been reloaded!") +object StaminaCommands { + fun registerCommands() { + stamina.plugin.commands { + "climb" { + requiresPermission("") + playerExecutes { + player.climbEnabled = !player.climbEnabled + if (player.climbEnabled) Tags.enableClimb(player) + else Tags.disableClimb(player) + player.info("Stamina and climbing system: ${if (player.climbEnabled) "ON" else "OFF"}!") } - } - "tags" { - action { -// stamina.emptyClimbableMap.entries.find { it.key == BlockTags.CLIMBABLE.location }?.let { -// sender.info("Empty climbable tag: ${it.value.joinToString { BuiltInRegistries.BLOCK.getHolder(it).getOrNull()?.registeredName.toString() }}") -// } -// stamina.normalClimbableMap.entries.find { it.key == BlockTags.CLIMBABLE.location }?.let { -// sender.info("Normal Climbable Tag: ${it.value.joinToString { BuiltInRegistries.BLOCK.getHolder(it).getOrNull()?.registeredName.toString() }}") -// } + "reload" { + requiresPermission("staminaclimb.reload") + executes { + stamina.staminaTask.cancel() + stamina.plugin.createClimbContext() + stamina.staminaTask.runTaskTimer(stamina.plugin, 0, 1) + StaminaBar.conf = stamina.config + ClimbBehaviour.conf = stamina.config + sender.success("Config has been reloaded!") + } } } } } - - override fun onTabComplete( - sender: CommandSender, - command: Command, - label: String, - args: Array - ): List { - return if (command.name == "staminaclimb") { - when (args.size) { - 1 -> listOf("reload") - else -> emptyList() - } - } else emptyList() - } - }