32 lines
1018 B
Kotlin
32 lines
1018 B
Kotlin
package nl.voidcorp.mainplugin
|
|
|
|
import nl.voidcorp.mainplugin.commands.VoidCommand
|
|
import org.bukkit.command.Command
|
|
import org.bukkit.command.CommandSender
|
|
import org.bukkit.command.TabExecutor
|
|
|
|
class CommandHandler(
|
|
private val plugin: VoidPluginBase
|
|
) : TabExecutor {
|
|
private val commands: MutableMap<String, VoidCommand> = mutableMapOf()
|
|
|
|
override fun onTabComplete(
|
|
sender: CommandSender,
|
|
command: Command,
|
|
alias: String,
|
|
args: Array<out String>
|
|
) = commands[command.name]?.onTabComplete(sender, command, alias, args) ?: mutableListOf()
|
|
|
|
|
|
override fun onCommand(sender: CommandSender, command: Command, label: String, args: Array<out String>): Boolean {
|
|
return commands[command.name]?.onCommand(sender, command, label, args) ?: false
|
|
}
|
|
|
|
fun registerCommand(commandName: String, command: VoidCommand): CommandHandler {
|
|
plugin.getCommand(commandName)?.setExecutor(this)
|
|
commands[commandName] = command
|
|
return this
|
|
}
|
|
|
|
|
|
} |