diff --git a/src/main/java/net/knarcraft/knarlib/plugin/ConfigCommentPlugin.java b/src/main/java/net/knarcraft/knarlib/plugin/ConfigCommentPlugin.java index 7148b98..7159732 100644 --- a/src/main/java/net/knarcraft/knarlib/plugin/ConfigCommentPlugin.java +++ b/src/main/java/net/knarcraft/knarlib/plugin/ConfigCommentPlugin.java @@ -1,9 +1,15 @@ package net.knarcraft.knarlib.plugin; import net.knarcraft.knarlib.config.StargateYamlConfiguration; +import org.bukkit.command.CommandExecutor; +import org.bukkit.command.PluginCommand; +import org.bukkit.command.TabExecutor; import org.bukkit.configuration.file.FileConfiguration; import org.bukkit.plugin.java.JavaPlugin; import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; + +import java.util.logging.Level; /** * A plugin that uses a Stargate YAML configuration in order to retain all configuration comments @@ -35,4 +41,35 @@ public abstract class ConfigCommentPlugin extends JavaPlugin { return this.configuration; } + /** + * Registers a command + * + * @param commandName
The name of the command to register
+ * @param executorThe executor to register for the command
+ */ + private void registerCommand(@NotNull String commandName, @NotNull CommandExecutor executor) { + registerCommand(commandName, executor, null); + } + + /** + * Registers a command + * + * @param commandNameThe name of the command to register
+ * @param commandExecutorThe command executor to register for the command
+ * @param tabExecutorThe tab executor to register for the command
+ */ + @SuppressWarnings("SameParameterValue") + private void registerCommand(@NotNull String commandName, @NotNull CommandExecutor commandExecutor, + @Nullable TabExecutor tabExecutor) { + PluginCommand pluginCommand = this.getCommand(commandName); + if (pluginCommand != null) { + pluginCommand.setExecutor(commandExecutor); + if (tabExecutor != null) { + pluginCommand.setTabCompleter(tabExecutor); + } + } else { + getLogger().log(Level.SEVERE, "Failed to register command " + commandName); + } + } + }