Skip to content

Commit

Permalink
refactor: swap to brigadier commands
Browse files Browse the repository at this point in the history
  • Loading branch information
Boy0000 committed Oct 31, 2024
1 parent bcd5cc8 commit 5a3d759
Show file tree
Hide file tree
Showing 5 changed files with 38 additions and 58 deletions.
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
group=com.mineinabyss
version=0.23
idofrontVersion=0.25.5
idofrontVersion=0.25.17
2 changes: 1 addition & 1 deletion gradle/libs.versions.toml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
[versions]
geary = "0.30.17"
geary = "0.31.0"

[libraries]
geary-papermc = { module = "com.mineinabyss:geary-papermc", version.ref = "geary" }
10 changes: 10 additions & 0 deletions src/main/kotlin/com/mineinabyss/staminaclimb/StaminaAddon.kt
Original file line number Diff line number Diff line change
@@ -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()
}
})
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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)
}
}

Expand All @@ -34,7 +32,7 @@ class StaminaClimbPlugin : JavaPlugin() {
Bukkit.getOnlinePlayers().forEach(::registerBar)

listeners(ClimbBehaviour, StaminaBar)
StaminaCommands()
StaminaCommands.registerCommands()

Tags.interceptConfigPhaseTagPacket()
}
Expand Down
70 changes: 21 additions & 49 deletions src/main/kotlin/com/mineinabyss/staminaclimb/StaminaCommands.kt
Original file line number Diff line number Diff line change
@@ -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<out String>
): List<String> {
return if (command.name == "staminaclimb") {
when (args.size) {
1 -> listOf("reload")
else -> emptyList()
}
} else emptyList()
}

}

0 comments on commit 5a3d759

Please sign in to comment.