- 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.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.protected final voidsetCommandMap(org.bukkit.command.CommandMap commandMap) 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.
-
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. -
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
-
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
-