From ec64a19fc79f68612ed53a3be17c1a7c0f1f20b2 Mon Sep 17 00:00:00 2001 From: EpicKnarvik97 Date: Sat, 6 Sep 2025 03:51:12 +0200 Subject: [PATCH] Adds methods for registering a command --- .../knarlib/plugin/ConfigCommentPlugin.java | 37 +++++++++++++++++++ 1 file changed, 37 insertions(+) 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 executor

The executor to register for the command

+ */ + private void registerCommand(@NotNull String commandName, @NotNull CommandExecutor executor) { + registerCommand(commandName, executor, null); + } + + /** + * Registers a command + * + * @param commandName

The name of the command to register

+ * @param commandExecutor

The command executor to register for the command

+ * @param tabExecutor

The 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); + } + } + }