Commands Utility - C00kier/CookiersLib GitHub Wiki
CommandsUtility is a utility class designed to simplify the registration of commands in a Bukkit/Spigot plugin. It supports registering commands declared in plugin.yml as well as dynamic commands registered at runtime via reflection, including permission handling and tab completion.
Registers a command (declared in plugin.yml) with both a CommandExecutor and a TabCompleter.
registerCommandWithTabCompleter(JavaPlugin plugin, String commandName, CommandExecutor executor, TabCompleter tabCompleter)
Parameters:
-
plugin
- The plugin instance. -
commandName
- The command name as specified in plugin.yml. -
executor
- The command logic. -
tabCompleter
- The tab completion logic.
Throws:
-
NullPointerException
if the command is not found in plugin.yml.
Registers a command (declared in plugin.yml) with only a CommandExecutor.
registerCommandWithoutTabCompleter(JavaPlugin plugin, String commandName, CommandExecutor executor)
Parameters:
-
plugin
- The plugin instance. -
commandName
- The command name as specified in plugin.yml. -
executor
- The command logic.
Throws:
-
NullPointerException
if the command is not found in plugin.yml.
Registers a command dynamically at runtime without requiring a plugin.yml entry. Supports permission checks and optional tab completion.
registerDynamicCommand(String commandName, CommandExecutor executor, TabCompleter tabCompleter, List<String> permissions, JavaPlugin plugin)
Parameters:
-
commandName
- Name of the command. -
executor
- Command execution logic. -
tabCompleter
- Tab completion logic (optional). -
permissions
- List of permissions required to use the command. If null or empty, no permission is required. -
plugin
- Plugin instance registering the command.
Details:
- Uses reflection to access the server’s CommandMap.
- Commands registered here are fully functional with permissions and tab completions.
- Logs success or failure during registration.