- All Implemented Interfaces:
org.bukkit.command.CommandExecutor,org.bukkit.command.TabCompleter
- Since:
- 1.0.0
- Author:
- Despical
-
Field Summary
FieldsModifier and TypeFieldDescriptionprotected static CommandFrameworkprotected final dev.despical.commandframework.internal.ParameterHandlerprotected final dev.despical.commandframework.internal.CommandRegistry -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionfinal <T> voidaddCustomParameter(@NotNull Class<T> clazz, @NotNull Function<CommandArguments, T> function) Adds a custom parameter to the parameter handler using a class type.final <A,B extends A>
voidaddCustomParameter(@NotNull String value, @NotNull Function<CommandArguments, B> function) Adds a custom parameter to the parameter handler.protected final <T extends CommandArguments>
voidconfigureDefaultArguments(@NotNull Class<T> argumentsClass) protected final voidconfigureDefaultArguments(@NotNull Function<CommandArguments, ? extends CommandArguments> argumentsFactory) Get an unmodifiable copy of registered commands and sub-commands.Get an unmodifiable copy of registered commands.static CommandFrameworkfinal @NotNull LoggerReturns the logger instance of Command Framework.final @NotNull org.bukkit.plugin.PluginGet an unmodifiable copy of registered sub-commands-.booleanonCommand(@NotNull org.bukkit.command.CommandSender sender, org.bukkit.command.Command cmd, @NotNull String label, String[] args) onTabComplete(@NotNull org.bukkit.command.CommandSender sender, org.bukkit.command.Command cmd, @NotNull String label, String[] args) final OptionManageroptions()Returns the option manager.final voidregisterAllInPackage(@NotNull String packageName) Scans all classes within the specified package, creates instances of them, and registers them as commands.final voidregisterCommands(@NotNull Object instance) Registers commands from the specified instance's class.final booleansetCommandAttributes(@NotNull String commandName, @NotNull CommandAttributes attributes) Replaces the attributes of a command that was registered by this framework.protected final voidsetCommandMap(org.bukkit.command.CommandMap commandMap) final <T extends CommandArguments>
voidsetDefaultArguments(@NotNull Class<T> argumentsClass) Sets the default command arguments class that will be created for each command execution and completion.final <T extends CommandArguments>
voidsetDefaultArguments(@NotNull Function<CommandArguments, T> argumentsFactory) Sets the default command arguments factory that will be used for each command execution and completion.final voidChanges default loggerfinal voidunregisterCommand(@NotNull String commandName) Unregisters a command and its associated tab completer if they are registered with the specified name.final voidUnregisters all commands and tab completers that were registered using the instance of this object.final booleanupdateCommandAttributes(@NotNull String commandName, @NotNull Consumer<CommandAttributes.Builder> updater) Updates the attributes of a command that was registered by this framework.
-
Field Details
-
instance
-
registry
protected final dev.despical.commandframework.internal.CommandRegistry registry -
parameterHandler
protected final dev.despical.commandframework.internal.ParameterHandler parameterHandler
-
-
Constructor Details
-
CommandFramework
public CommandFramework(@NotNull @NotNull org.bukkit.plugin.Plugin plugin)
-
-
Method Details
-
registerCommands
Registers commands from the specified instance's class.This method scans the class of the provided instance and registers all commands defined within that class. The class should contain methods annotated to be recognized as commands.
- Parameters:
instance- the instance of the class from which commands will be registered. Must not benull.
-
registerAllInPackage
Scans all classes within the specified package, creates instances of them, and registers them as commands.Note: Scanned classes must have a public no-args constructor. Interfaces and abstract classes are automatically skipped.
- Parameters:
packageName- The full path of the package to scan (e.g., "com.example.project.commands")- See Also:
-
unregisterCommand
Unregisters a command and its associated tab completer if they are registered with the specified name.- Parameters:
commandName- the name of the command to be unregistered. Must not benullor empty.- Throws:
IllegalArgumentException- ifcommandNameisnullor an empty string.
-
unregisterCommands
public final void unregisterCommands()Unregisters all commands and tab completers that were registered using the instance of this object. -
setCommandAttributes
public final boolean setCommandAttributes(@NotNull @NotNull String commandName, @NotNull @NotNull CommandAttributes attributes) Replaces the attributes of a command that was registered by this framework.This method only looks inside Command Framework's own registry and does not mutate commands registered directly through Bukkit or another command system.
- Parameters:
commandName- the current registered command name, including sub-command path if neededattributes- the new command attributes- Returns:
trueif a framework command was found and updated, otherwisefalse
-
updateCommandAttributes
public final boolean updateCommandAttributes(@NotNull @NotNull String commandName, @NotNull @NotNull Consumer<CommandAttributes.Builder> updater) Updates the attributes of a command that was registered by this framework.- Parameters:
commandName- the current registered command name, including sub-command path if neededupdater- a consumer that mutates the attribute builder- Returns:
trueif a framework command was found and updated, otherwisefalse- See Also:
-
addCustomParameter
public final <A,B extends A> void addCustomParameter(@NotNull @NotNull String value, @NotNull @NotNull Function<CommandArguments, B> function) Adds a custom parameter to the parameter handler.This method allows the addition of a custom parameter to the parameter handler by specifying a value and a function that converts
CommandArgumentsto an instance of a type that extendsCommandFramework.- Type Parameters:
A- the type of the parent class that the custom parameter's type extendsB- the type of the custom parameter, which extendsCommandFramework- Parameters:
value- the value to call custom parameter using @Param, must not be null, can be a class namefunction- a function that takesCommandArgumentsand returns an instance ofCommandFramework, must not be null- Throws:
NullPointerException- ifvalueis already added as a custom parameter
-
addCustomParameter
public final <T> void addCustomParameter(@NotNull @NotNull Class<T> clazz, @NotNull @NotNull Function<CommandArguments, T> function) Adds a custom parameter to the parameter handler using a class type.This method allows the addition of a custom parameter to the parameter handler by specifying a class and a function that converts
CommandArgumentsto an instance ofCommandFramework.The parameter will be registered using the
Class.getSimpleName()as the key.- Type Parameters:
T- the type of the custom parameter- Parameters:
clazz- the class of the custom parameter, used to derive the key usingClass.getSimpleName(), must not be nullfunction- a function that takesCommandArgumentsand returns an instance ofCommandFramework, must not be null- Throws:
CommandException- if a custom parameter with the same class name is already registered
-
setDefaultArguments
public final <T extends CommandArguments> void setDefaultArguments(@NotNull @NotNull Class<T> argumentsClass) Sets the default command arguments class that will be created for each command execution and completion.The class must declare either a
CommandArguments(CommandArguments)copy constructor or the fullCommandArgumentsconstructor signature.- Type Parameters:
T- the command arguments type- Parameters:
argumentsClass- the command arguments subclass to instantiate
-
setDefaultArguments
public final <T extends CommandArguments> void setDefaultArguments(@NotNull @NotNull Function<CommandArguments, T> argumentsFactory) Sets the default command arguments factory that will be used for each command execution and completion.- Type Parameters:
T- the command arguments type- Parameters:
argumentsFactory- the function that converts base command arguments to the desired arguments type
-
getLogger
Returns the logger instance of Command Framework. By default, logger isplugin's logger.- Returns:
- the current logger instance.
- Since:
- 1.4.8
-
setLogger
Changes default logger- Parameters:
logger- the non-null new logger instance- Since:
- 1.4.8
-
options
Returns the option manager.- Returns:
- the option manager.
- Since:
- 1.4.8
-
getCommands
Get an unmodifiable copy of registered commands.- Returns:
- list of the commands.
-
getSubCommands
Get an unmodifiable copy of registered sub-commands-.- Returns:
- list of the sub-commands.
-
getAllCommands
Get an unmodifiable copy of registered commands and sub-commands.- Returns:
- list of the commands and sub-commands.
-
getPlugin
@NotNull @Contract(pure=true) public final @NotNull org.bukkit.plugin.Plugin getPlugin() -
setCommandMap
protected final void setCommandMap(org.bukkit.command.CommandMap commandMap) -
getInstance
-
onCommand
public boolean onCommand(@NotNull @NotNull org.bukkit.command.CommandSender sender, @NotNull org.bukkit.command.Command cmd, @NotNull @NotNull String label, String[] args) - Specified by:
onCommandin interfaceorg.bukkit.command.CommandExecutor
-
onTabComplete
public List<String> onTabComplete(@NotNull @NotNull org.bukkit.command.CommandSender sender, @NotNull org.bukkit.command.Command cmd, @NotNull @NotNull String label, String[] args) - Specified by:
onTabCompletein interfaceorg.bukkit.command.TabCompleter
-
configureDefaultArguments
protected final void configureDefaultArguments(@NotNull @NotNull Function<CommandArguments, ? extends CommandArguments> argumentsFactory) -
configureDefaultArguments
protected final <T extends CommandArguments> void configureDefaultArguments(@NotNull @NotNull Class<T> argumentsClass)
-