kr.summitsystems.springbukkit.command.CommandInitializer.kt Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of spring-bukkit-command Show documentation
Show all versions of spring-bukkit-command Show documentation
Springframework based Bukkit plugin development kit.
The newest version!
package kr.summitsystems.springbukkit.command
import jakarta.annotation.PostConstruct
import org.bukkit.command.Command
import org.bukkit.command.CommandSender
import org.bukkit.plugin.Plugin
import org.bukkit.plugin.PluginDescriptionFile
import org.bukkit.plugin.java.JavaPlugin
import org.springframework.stereotype.Component
@Component
class CommandInitializer(
private val plugin: Plugin,
private val pluginDescriptionFile: PluginDescriptionFile,
private val commandExecutor: CommandExecutor
) {
@PostConstruct
fun registerCommand() {
if (plugin is JavaPlugin) {
pluginDescriptionFile.commands.keys.forEach { name ->
val command = plugin.getCommand(name) ?: return@forEach
command.setExecutor(BukkitCommandExecutorDelegate(commandExecutor))
}
}
}
class BukkitCommandExecutorDelegate(
private val commandExecutor: CommandExecutor
) : org.bukkit.command.CommandExecutor {
override fun onCommand(sender: CommandSender, command: Command, label: String, args: Array): Boolean {
commandExecutor.executeCommand(sender, label, args)
return true
}
}
}
© 2015 - 2024 Weber Informatics LLC | Privacy Policy