Added registerable implementations of CommandExecutor and Listener

This commit is contained in:
bluefireoly
2020-07-15 14:55:57 +02:00
parent f9b0167f82
commit b6fa27c9a2
2 changed files with 41 additions and 0 deletions

View File

@@ -0,0 +1,26 @@
package net.axay.kspigot.utils
import net.axay.kspigot.main.KSpigot
import org.bukkit.command.CommandExecutor
import org.bukkit.command.TabCompleter
interface RegisterableCommand : CommandExecutor {
/**
* Registers this executor for the given command
* and for the given instance of [kSpigot].
*
* @return true if the command was found -
* false if not
*/
fun registerCommand(commandName: String, kSpigot: KSpigot): Boolean {
kSpigot.plugin.getCommand(commandName)?.let {
it.setExecutor(this)
if (this is TabCompleter)
it.tabCompleter = this
return true
}
return false
}
}

View File

@@ -0,0 +1,15 @@
package net.axay.kspigot.utils
import net.axay.kspigot.main.KSpigot
import org.bukkit.Bukkit
import org.bukkit.event.Listener
interface RegisterableListener : Listener {
/**
* Registers this listener
* for the given instance of [kSpigot].
*/
fun registerListener(kSpigot: KSpigot) = Bukkit.getPluginManager().registerEvents(this, kSpigot.plugin)
}