Interface CommandHandler
- All Known Subinterfaces:
BukkitCommandHandler
,BungeeCommandHandler
,ConsoleCommandHandler
,JDACommandHandler
,SpongeCommandHandler
,VelocityCommandHandler
- All Known Implementing Classes:
BaseCommandHandler
,BukkitHandler
,BungeeHandler
,CLIHandler
,JDAHandler
,SpongeHandler
,VelocityHandler
-
Method Summary
Modifier and TypeMethodDescription@NotNull CommandHandler
accept
(@NotNull CommandHandlerVisitor visitor) Accepts the givenCommandHandlerVisitor
and allows it to visit this command handler.@NotNull CommandHandler
Disables stacktrace sanitization.<T> @NotNull Optional<@Nullable T>
dispatch
(@NotNull CommandActor actor, @NotNull String commandInput) Evaluates the command from the given input<T> @NotNull Optional<@Nullable T>
dispatch
(@NotNull CommandActor actor, @NotNull ArgumentStack arguments) Evaluates the command from the given arguments@NotNull CommandHandler
Sets the command to fail when too many arguments are specified in the command.@NotNull ArgumentParser
Returns theArgumentParser
responsible for controlling the logic of parsing strings.@NotNull AutoCompleter
Returns the auto-completion handler of this command handler@NotNull @UnmodifiableView Map<CommandPath,
CommandCategory> Returns an unmodifiable view of all the registered categories in this command handler.getCategory
(@NotNull CommandPath path) Returns the givenCommandCategory
that matches the given path.getCommand
(@NotNull CommandPath path) Returns the givenExecutableCommand
that matches the given path.@NotNull @UnmodifiableView Map<CommandPath,
ExecutableCommand> Returns an unmodifiable view of all the registered commands in this command handler.<T> Supplier<T>
getDependency
(@NotNull Class<T> dependencyType) Returns the dependency registered for the given type<T> Supplier<T>
getDependency
(@NotNull Class<T> dependencyType, Supplier<T> def) Returns the dependency registered for the given type, otherwise returns the givendef
value.@NotNull CommandExceptionHandler
Returns the command exception handler currently used by this command handler@NotNull String
Returns the prefix that comes before allFlag
parameters when they are fetched from the command.<T> CommandHelpWriter<T>
Returns theCommandHelpWriter
of this command handler.@NotNull Locale
Gets the current, default locale used by this handler@NotNull String
Returns the prefix that preceds all messages sent byCommandActor.reply(String)
andCommandActor.error(String)
.@NotNull MethodCallerFactory
Returns theMethodCallerFactory
responsible for generating reflective calls.@NotNull Set<CommandPath>
Returns all the root commands or categories paths in this command handler.@NotNull String
Returns the prefix that comes before allSwitch
parameters when they are fetched from the command.@NotNull Translator
Returns the translator of this command handlerparseArguments
(String... arguments) Parses the string array and returns anArgumentStack
for it.parseArgumentsForCompletion
(String... arguments) Parses the string and returns anArgumentStack
for it.@NotNull CommandHandler
Registers the specified command from an instance.<T extends Annotation>
@NotNull CommandHandlerregisterAnnotationReplacer
(@NotNull Class<T> annotationType, @NotNull AnnotationReplacer<T> replacer) Registers an annotation replacer.@NotNull CommandHandler
registerCondition
(@NotNull CommandCondition condition) Registers the specified condition in which all commands will be validated with.<T> @NotNull CommandHandler
registerContextResolver
(int priority, @NotNull Class<T> type, @NotNull ContextResolver<T> resolver) Registers a parameter resolver that gets its value from the command context.<T> @NotNull CommandHandler
registerContextResolver
(@NotNull Class<T> type, @NotNull ContextResolver<T> resolver) Registers a parameter resolver that gets its value from the command context.@NotNull CommandHandler
registerContextResolverFactory
(int priority, @NotNull ContextResolverFactory factory) Registers aContextResolverFactory
to this handler@NotNull CommandHandler
registerContextResolverFactory
(@NotNull ContextResolverFactory factory) Registers aContextResolverFactory
to this handler<T> @NotNull CommandHandler
registerContextValue
(int priority, @NotNull Class<T> type, T value) Registers a parameter type to always be a static value.<T> @NotNull CommandHandler
registerContextValue
(@NotNull Class<T> type, T value) Registers a parameter type to always be a static value.<T> @NotNull CommandHandler
registerDependency
(@NotNull Class<T> type, @NotNull Supplier<T> supplier) Registers a dependency for dependency injection.<T> @NotNull CommandHandler
registerDependency
(@NotNull Class<T> type, T value) Registers a (static) dependency for dependency injection.<T extends Throwable>
@NotNull CommandHandlerregisterExceptionHandler
(@NotNull Class<T> exceptionType, @NotNull BiConsumer<CommandActor, T> handler) Convenient method to register exception handlers.<T> @NotNull CommandHandler
registerParameterValidator
(@NotNull Class<T> type, @NotNull ParameterValidator<T> validator) Registers aParameterValidator
for the specified parameter type.@NotNull CommandHandler
registerPermissionReader
(@NotNull PermissionReader reader) Registers the given permission reader, which allows registering customCommandPermission
implementations with annotations.<T> @NotNull CommandHandler
registerResponseHandler
(@NotNull Class<T> responseType, @NotNull ResponseHandler<T> handler) Registers a response handler for the specified response type.@NotNull CommandHandler
registerSenderResolver
(@NotNull SenderResolver resolver) Registers the given sender resolver, which resolves parameters at index 0 that may be potentially a custom sender implementation.<T> @NotNull CommandHandler
registerValueResolver
(int priority, @NotNull Class<T> type, @NotNull ValueResolver<T> resolver) Registers a parameter resolver that gets its value from the command arguments.<T> @NotNull CommandHandler
registerValueResolver
(@NotNull Class<T> type, @NotNull ValueResolver<T> resolver) Registers a parameter resolver that gets its value from the command arguments.@NotNull CommandHandler
registerValueResolverFactory
(int priority, @NotNull ValueResolverFactory factory) Registers aValueResolverFactory
to this handler@NotNull CommandHandler
registerValueResolverFactory
(@NotNull ValueResolverFactory factory) Registers aValueResolverFactory
to this handlersetArgumentParser
(@NotNull ArgumentParser parser) Sets theArgumentParser
responsible for controlling the logic of parsing strings.@NotNull CommandHandler
setExceptionHandler
(@NotNull CommandExceptionHandler handler) Sets theCommandExceptionHandler
to use for handling any exceptions that are thrown from the command.@NotNull CommandHandler
setFlagPrefix
(@NotNull String prefix) Sets the prefix that all parameters annotated withFlag
will be checked against.<T> @NotNull CommandHandler
setHelpWriter
(@NotNull CommandHelpWriter<T> helpWriter) Sets theCommandHelpWriter
responsible for generating help pagesvoid
Sets the locale of this handler.@NotNull CommandHandler
setMessagePrefix
(@NotNull String prefix) Returns the prefix that should preced all messages sent withCommandActor.reply(String)
andCommandActor.error(String)
.@NotNull CommandHandler
setMethodCallerFactory
(@NotNull MethodCallerFactory factory) Sets theMethodCallerFactory
responsible for generating access to reflection methods.@NotNull CommandHandler
setSwitchPrefix
(@NotNull String prefix) Sets the prefix that all parameters annotated withSwitch
will be checked against.boolean
unregister
(@NotNull String commandPath) Unregisters the given path and all the sub-paths that belong to itboolean
unregister
(@NotNull CommandPath path) Unregisters the given path and all the sub-paths that belong to itvoid
Unregisters all the command instances in this command handler.
-
Method Details
-
register
Registers the specified command from an instance. This will automatically set allDependency
-annotated fields with their values.- Parameters:
commands
- The commands object instances. Can be a class if methods are static.- Returns:
- This command handler
-
getLocale
Gets the current, default locale used by this handler- Returns:
- The default locale
-
setLocale
Sets the locale of this handler.- Parameters:
locale
- The locale of this handler
-
getTranslator
Returns the translator of this command handler- Returns:
- The message translator
-
setMethodCallerFactory
@NotNull @NotNull CommandHandler setMethodCallerFactory(@NotNull @NotNull MethodCallerFactory factory) Sets theMethodCallerFactory
responsible for generating access to reflection methods.This method allows using alternative strategy for accessing methods reflectively.
- Parameters:
factory
- Factory to set- Returns:
- This command handler
- See Also:
-
getArgumentParser
Returns theArgumentParser
responsible for controlling the logic of parsing strings.- Returns:
- The argument parser.
-
parseArgumentsForCompletion
Parses the string and returns anArgumentStack
for it. This method behaves exactly likeparseArguments(String[])
, however it returns a singleton list of an empty string when the text is empty, suitable for auto-completion.- Parameters:
arguments
- Strings to parse. These will get joined to a string separated by spaces.- Returns:
- The argument stack.
- Throws:
ArgumentParseException
-
parseArguments
Parses the string array and returns anArgumentStack
for it.- Parameters:
arguments
- String array to parse. This will be joined as a single string with spaces.- Returns:
- The argument stack.
- Throws:
ArgumentParseException
- See Also:
-
setArgumentParser
Sets theArgumentParser
responsible for controlling the logic of parsing strings.- Parameters:
parser
- The argument parser to use.- Returns:
- This command handler
-
setExceptionHandler
@NotNull @NotNull CommandHandler setExceptionHandler(@NotNull @NotNull CommandExceptionHandler handler) Sets theCommandExceptionHandler
to use for handling any exceptions that are thrown from the command.If not set, a default one will be used.
- Parameters:
handler
- The exception handler- Returns:
- This command handler
- See Also:
-
registerExceptionHandler
@NotNull <T extends Throwable> @NotNull CommandHandler registerExceptionHandler(@NotNull @NotNull Class<T> exceptionType, @NotNull @NotNull BiConsumer<CommandActor, T> handler) Convenient method to register exception handlers. These will have higher priority overCommandExceptionHandler
.- Parameters:
exceptionType
- The exception classhandler
- The exception handler- Returns:
- This command handler
- See Also:
-
setSwitchPrefix
Sets the prefix that all parameters annotated withSwitch
will be checked against. If not set,-
will be used- Parameters:
prefix
- New prefix to set- Returns:
- This command handler
- Throws:
IllegalArgumentException
- if the prefix is empty
-
setFlagPrefix
Sets the prefix that all parameters annotated withFlag
will be checked against. If not set,-
will be used- Parameters:
prefix
- New prefix to set- Returns:
- This command handler
- Throws:
IllegalArgumentException
- if the prefix is empty
-
setMessagePrefix
Returns the prefix that should preced all messages sent withCommandActor.reply(String)
andCommandActor.error(String)
.Note that the prefix will NOT be followed by spaces, it is your responsibility to include it in the prefix you set.
- Parameters:
prefix
- Message prefix- Returns:
- This command handler
-
setHelpWriter
@NotNull <T> @NotNull CommandHandler setHelpWriter(@NotNull @NotNull CommandHelpWriter<T> helpWriter) Sets theCommandHelpWriter
responsible for generating help pages- Type Parameters:
T
- The help entry type.- Parameters:
helpWriter
- Help writer to use- Returns:
- This command handler
- See Also:
-
disableStackTraceSanitizing
Disables stacktrace sanitization.By default, printed stack-trace is sanitized and stripped from internal, extra trace elements. This helps to keep the trace clean and readable, and removes away unnecessary paths. When disabled, full stacktrace will be printed.
- Returns:
- This command handler
-
failOnTooManyArguments
Sets the command to fail when too many arguments are specified in the command.- Returns:
- This command handler
- See Also:
-
registerSenderResolver
Registers the given sender resolver, which resolves parameters at index 0 that may be potentially a custom sender implementation.See
SenderResolver
for more information.- Parameters:
resolver
- Resolver to register- Returns:
- This command handler
- See Also:
-
registerPermissionReader
@NotNull @NotNull CommandHandler registerPermissionReader(@NotNull @NotNull PermissionReader reader) Registers the given permission reader, which allows registering customCommandPermission
implementations with annotations.- Parameters:
reader
- Permission reader to register- Returns:
- This command handler
- See Also:
-
registerValueResolver
@NotNull <T> @NotNull CommandHandler registerValueResolver(@NotNull @NotNull Class<T> type, @NotNull @NotNull ValueResolver<T> resolver) Registers a parameter resolver that gets its value from the command arguments.See
ValueResolver
for more information- Parameters:
type
- The parameter type to resolveresolver
- The resolver- Returns:
- This command handler
- See Also:
-
registerValueResolver
@NotNull <T> @NotNull CommandHandler registerValueResolver(int priority, @NotNull @NotNull Class<T> type, @NotNull @NotNull ValueResolver<T> resolver) Registers a parameter resolver that gets its value from the command arguments.See
ValueResolver
for more information- Parameters:
priority
- The resolver priority. Zero represents the highest.type
- The parameter type to resolveresolver
- The resolver- Returns:
- This command handler
- See Also:
-
registerContextResolver
@NotNull <T> @NotNull CommandHandler registerContextResolver(@NotNull @NotNull Class<T> type, @NotNull @NotNull ContextResolver<T> resolver) Registers a parameter resolver that gets its value from the command context.See
ContextResolver
for more information- Parameters:
type
- The parameter type to resolveresolver
- The resolver- Returns:
- This command handler
- See Also:
-
registerContextResolver
@NotNull <T> @NotNull CommandHandler registerContextResolver(int priority, @NotNull @NotNull Class<T> type, @NotNull @NotNull ContextResolver<T> resolver) Registers a parameter resolver that gets its value from the command context.See
ContextResolver
for more information- Parameters:
priority
- The resolver priority. Zero represents the highest.type
- The parameter type to resolveresolver
- The resolver- Returns:
- This command handler
- See Also:
-
registerContextValue
@NotNull <T> @NotNull CommandHandler registerContextValue(@NotNull @NotNull Class<T> type, @Nullable T value) Registers a parameter type to always be a static value. This is useful for registering singletons as parameters.This is equivalent to calling
registerContextResolver(type, ContextResolver.of(type))
See
ContextResolver
for more information- Parameters:
type
- The parameter type to resolvevalue
- The value to retrun- Returns:
- This command handler
- See Also:
-
registerContextValue
@NotNull <T> @NotNull CommandHandler registerContextValue(int priority, @NotNull @NotNull Class<T> type, @NotNull T value) Registers a parameter type to always be a static value. This is useful for registering singletons as parameters.This is equivalent to calling
registerContextResolver(priority, type, ContextResolver.of(value))
See
ContextResolver
for more information- Parameters:
priority
- The resolver priority. Zero represents the highest.type
- The parameter type to resolvevalue
- The value to retrun- Returns:
- This command handler
- See Also:
-
registerValueResolverFactory
@NotNull @NotNull CommandHandler registerValueResolverFactory(@NotNull @NotNull ValueResolverFactory factory) Registers aValueResolverFactory
to this handler- Parameters:
factory
- Factory to register- Returns:
- This command handler
- See Also:
-
registerValueResolverFactory
@NotNull @NotNull CommandHandler registerValueResolverFactory(int priority, @NotNull @NotNull ValueResolverFactory factory) Registers aValueResolverFactory
to this handler- Parameters:
priority
- The resolver priority. Zero represents the highest.factory
- Factory to register- Returns:
- This command handler
- See Also:
-
registerContextResolverFactory
@NotNull @NotNull CommandHandler registerContextResolverFactory(@NotNull @NotNull ContextResolverFactory factory) Registers aContextResolverFactory
to this handler- Parameters:
factory
- Factory to register- Returns:
- This command handler
- See Also:
-
registerContextResolverFactory
@NotNull @NotNull CommandHandler registerContextResolverFactory(int priority, @NotNull @NotNull ContextResolverFactory factory) Registers aContextResolverFactory
to this handler- Parameters:
priority
- The resolver priority. Zero represents the highest.factory
- Factory to register- Returns:
- This command handler
- See Also:
-
registerCondition
Registers the specified condition in which all commands will be validated with.- Parameters:
condition
- Condition to register- Returns:
- This command handler
-
registerDependency
@NotNull <T> @NotNull CommandHandler registerDependency(@NotNull @NotNull Class<T> type, @NotNull @NotNull Supplier<T> supplier) Registers a dependency for dependency injection.Any fields in the command class or instance with the
Dependency
annotation will have their value set from this supplier.- Type Parameters:
T
- The dependency type- Parameters:
type
- The dependency class type. This must match the field type.supplier
- The dependency supplier- Returns:
- This command handler
- See Also:
-
registerDependency
Registers a (static) dependency for dependency injection.Any fields in the command class or instance with the
Dependency
annotation will have their value set to this value.- Type Parameters:
T
- The dependency type- Parameters:
type
- The dependency class type. This must match the field typevalue
- The dependency value- Returns:
- This command handler
- See Also:
-
registerParameterValidator
@NotNull <T> @NotNull CommandHandler registerParameterValidator(@NotNull @NotNull Class<T> type, @NotNull @NotNull ParameterValidator<T> validator) Registers aParameterValidator
for the specified parameter type. Parameter validators can access all information about a parameter, including the name and annotations.- Type Parameters:
T
- The parameter type- Parameters:
type
- The parameter typevalidator
- The validator for this parameter- Returns:
- This command handler
-
registerResponseHandler
@NotNull <T> @NotNull CommandHandler registerResponseHandler(@NotNull @NotNull Class<T> responseType, @NotNull @NotNull ResponseHandler<T> handler) Registers a response handler for the specified response type. Response handlers do post-handling with results returned from command methods.Note that response handlers are captured by
ExecutableCommand
s when they are registered, so they should be registered before the command itself is registered.- Type Parameters:
T
- The response type- Parameters:
responseType
- The response classhandler
- The response handler implementation- Returns:
- This command handler
-
registerAnnotationReplacer
@NotNull <T extends Annotation> @NotNull CommandHandler registerAnnotationReplacer(@NotNull @NotNull Class<T> annotationType, @NotNull @NotNull AnnotationReplacer<T> replacer) Registers an annotation replacer. Annotation replacers allow to dynamically generate annotations at runtime using APIs such asAnnotations
. -
accept
Accepts the givenCommandHandlerVisitor
and allows it to visit this command handler.- Parameters:
visitor
- Visitor to accept- Returns:
- This command handler
- See Also:
-
getAutoCompleter
Returns the auto-completion handler of this command handler- Returns:
- The auto-completion handler
-
getCommand
Returns the givenExecutableCommand
that matches the given path. This can return null if no command exists at such a path.Note that
CommandPath
s are, by default, case-insensitive.- Parameters:
path
- Path to look for- Returns:
- The command at the given path
-
getCategory
Returns the givenCommandCategory
that matches the given path. This can return null if no category exists at such a path.Note that
CommandPath
s are, by default, case-insensitive.- Parameters:
path
- Path to look for- Returns:
- The category at the given path
-
getCommands
Returns an unmodifiable view of all the registered commands in this command handler.- Returns:
- The registered commands
-
getCategories
Returns an unmodifiable view of all the registered categories in this command handler.- Returns:
- The registered categories
-
getExceptionHandler
Returns the command exception handler currently used by this command handler- Returns:
- The command exception handler
-
getMethodCallerFactory
Returns theMethodCallerFactory
responsible for generating reflective calls.- Returns:
- The method caller factory
-
getHelpWriter
Returns theCommandHelpWriter
of this command handler. This can be null if no writer is registered.- Type Parameters:
T
- Command help entries type- Returns:
- The help writer of this handler
-
unregister
Unregisters the given path and all the sub-paths that belong to it- Parameters:
path
- Path to unregister- Returns:
- True if one or more elements were removed by this call.
-
unregister
Unregisters the given path and all the sub-paths that belong to it- Parameters:
commandPath
- Path to unregister- Returns:
- True if one or more elements were removed by this call.
-
unregisterAllCommands
void unregisterAllCommands()Unregisters all the command instances in this command handler. -
getRootPaths
Returns all the root commands or categories paths in this command handler.- Returns:
- All root command paths
-
getSwitchPrefix
Returns the prefix that comes before allSwitch
parameters when they are fetched from the command.- Returns:
- The switch prefix
-
getFlagPrefix
Returns the prefix that comes before allFlag
parameters when they are fetched from the command.- Returns:
- The switch prefix
-
getMessagePrefix
Returns the prefix that preceds all messages sent byCommandActor.reply(String)
andCommandActor.error(String)
.Set with
setMessagePrefix(String)
- Returns:
- The message prefix
-
getDependency
Returns the dependency registered for the given type- Type Parameters:
T
- Dependency type- Parameters:
dependencyType
- Dependency type to look for- Returns:
- The dependency, or null if not found.
-
getDependency
Returns the dependency registered for the given type, otherwise returns the givendef
value.- Type Parameters:
T
- Dependency type- Parameters:
dependencyType
- Dependency type to look fordef
- Default value if no dependency is registered for the given type.- Returns:
- The dependency, or null if not found.
-
dispatch
@NotNull <T> @NotNull Optional<@Nullable T> dispatch(@NotNull @NotNull CommandActor actor, @NotNull @NotNull ArgumentStack arguments) Evaluates the command from the given arguments- Parameters:
actor
- Actor to execute asarguments
- Arguments to invoke the command with- Returns:
- The result returned from invoking the command method. The optional value may be null if an exception was thrown.
-
dispatch
@NotNull <T> @NotNull Optional<@Nullable T> dispatch(@NotNull @NotNull CommandActor actor, @NotNull @NotNull String commandInput) Evaluates the command from the given input- Parameters:
actor
- Actor to execute ascommandInput
- Input to invoke with
-