diff --git a/src/main/kotlin/net/axay/kspigot/utils/RegisterableCommand.kt b/src/main/kotlin/net/axay/kspigot/utils/RegisterableCommand.kt new file mode 100644 index 00000000..8b0e6b9c --- /dev/null +++ b/src/main/kotlin/net/axay/kspigot/utils/RegisterableCommand.kt @@ -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 + } + +} \ No newline at end of file diff --git a/src/main/kotlin/net/axay/kspigot/utils/RegisterableListener.kt b/src/main/kotlin/net/axay/kspigot/utils/RegisterableListener.kt new file mode 100644 index 00000000..1dac2525 --- /dev/null +++ b/src/main/kotlin/net/axay/kspigot/utils/RegisterableListener.kt @@ -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) + +} \ No newline at end of file