Class CommandManager<C>
- Type Parameters:
C
- Command sender type
- Direct Known Subclasses:
LockableCommandManager
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic enum
Configurable command related settingsstatic enum
The point in the registration lifecycle for this commands manager -
Constructor Summary
ConstructorsModifierConstructorDescriptionprotected
CommandManager
(@NonNull Function<@NonNull CommandTree<C>, @NonNull CommandExecutionCoordinator<C>> commandExecutionCoordinator, @NonNull CommandRegistrationHandler commandRegistrationHandler) Create a new command manager instance -
Method Summary
Modifier and TypeMethodDescription<T> @NonNull CommandArgument.Builder<C,
T> argumentBuilder
(@NonNull Class<T> type, @NonNull String name) Create a new command argument builder.@NonNull Collection<@NonNull CloudCapability>
Returns an unmodifiable snapshot of the currently registeredcapabilities
.final @NonNull CaptionRegistry<C>
Returns the caption registry.final void
captionRegistry
(@NonNull CaptionRegistry<C> captionRegistry) Replaces the caption registry.@NonNull CaptionVariableReplacementHandler
Get the caption variable replacement handler.void
captionVariableReplacementHandler
(@NonNull CaptionVariableReplacementHandler captionVariableReplacementHandler) Sets the caption variable replacement handler.@NonNull CommandManager<C>
command
(@NonNull Command.Builder<C> command) Register a new command@NonNull CommandManager<C>
Register a new command to the command manager and insert it into the underlying command tree.@NonNull Command.Builder<C>
commandBuilder
(@NonNull String name, @NonNull ArgumentDescription description, @NonNull String... aliases) Create a new command builder using default command meta created bycreateDefaultCommandMeta()
.@NonNull Command.Builder<C>
commandBuilder
(@NonNull String name, @NonNull Description description, @NonNull String... aliases) Deprecated.for removal since 1.4.0.@NonNull Command.Builder<C>
commandBuilder
(@NonNull String name, @NonNull CommandMeta meta, @NonNull ArgumentDescription description, @NonNull String... aliases) Create a new command builder.@NonNull Command.Builder<C>
commandBuilder
(@NonNull String name, @NonNull CommandMeta meta, @NonNull Description description, @NonNull String... aliases) Deprecated.for removal since 1.4.0.@NonNull Command.Builder<C>
commandBuilder
(@NonNull String name, @NonNull CommandMeta meta, @NonNull String... aliases) Create a new command builder with an empty description.@NonNull Command.Builder<C>
commandBuilder
(@NonNull String name, @NonNull String... aliases) Create a new command builder using default command meta created bycreateDefaultCommandMeta()
, and an empty description.@NonNull Command.Builder<C>
commandBuilder
(@NonNull String name, @NonNull Collection<String> aliases, @NonNull ArgumentDescription description, @NonNull CommandMeta meta) Create a new command builder.@NonNull Command.Builder<C>
commandBuilder
(@NonNull String name, @NonNull Collection<String> aliases, @NonNull Description description, @NonNull CommandMeta meta) Deprecated.for removal since 1.4.0.@NonNull Command.Builder<C>
commandBuilder
(@NonNull String name, @NonNull Collection<String> aliases, @NonNull CommandMeta meta) Create a new command builder with an empty description.@NonNull CommandExecutionCoordinator<C>
Returns the command execution coordinator used in this manager@NonNull CommandRegistrationHandler
Returns the command registration handler.protected final void
commandRegistrationHandler
(@NonNull CommandRegistrationHandler commandRegistrationHandler) final @NonNull Collection<@NonNull Command<C>>
commands()
Returns an unmodifiable view of all registered commands.@NonNull CommandSuggestionProcessor<C>
Returns the command suggestion processor used in this command manager.void
commandSuggestionProcessor
(@NonNull CommandSuggestionProcessor<C> commandSuggestionProcessor) Sets the command suggestion processor.@NonNull CommandSyntaxFormatter<C>
Returns the command syntax formatter.void
commandSyntaxFormatter
(@NonNull CommandSyntaxFormatter<C> commandSyntaxFormatter) Sets the command syntax formatter.@NonNull CommandTree<C>
Returns the internal command tree.final @NonNull CommandHelpHandler<C>
Creates a new command help handler instance.final @NonNull CommandHelpHandler<C>
createCommandHelpHandler
(@NonNull Predicate<Command<C>> commandPredicate) Creates a new command help handler instance.abstract @NonNull CommandMeta
Construct a default command meta instancevoid
deleteRootCommand
(@NonNull String rootCommand) Deletes the givenrootCommand
.@NonNull CompletableFuture<CommandResult<C>>
executeCommand
(@NonNull C commandSender, @NonNull String input) Execute a command and get a future that completes with the result.@NonNull CommandFlag.Builder<Void>
flagBuilder
(@NonNull String name) Create a new command flag builderfinal @NonNull CaptionRegistry<C>
Deprecated.for removal since 1.7.0.final @NonNull CommandHelpHandler<C>
Deprecated.for removal since 1.7.0.final @NonNull CommandHelpHandler<C>
getCommandHelpHandler
(@NonNull Predicate<Command<C>> commandPredicate) Deprecated.for removal since 1.7.0.@NonNull CommandRegistrationHandler
Deprecated.for removal since 1.7.0.final @NonNull Collection<@NonNull Command<C>>
Deprecated.for removal since 1.7.0.@NonNull CommandSuggestionProcessor<C>
Deprecated.for removal since 1.7.0.@NonNull CommandSyntaxFormatter<C>
Deprecated.for removal since 1.7.0.@NonNull CommandTree<C>
Deprecated.for removal since 1.7.0.final <E extends Exception>
@Nullable BiConsumer<@NonNull C,@NonNull E> getExceptionHandler
(@NonNull Class<E> clazz) Get the exception handler for an exception type, if one has been registered@NonNull ParserRegistry<C>
Deprecated.for removal since 1.7.0.final @NonNull CommandManager.RegistrationState
Deprecated.for removal since 1.7.0.boolean
getSetting
(@NonNull CommandManager.ManagerSettings setting) Get a command manager settingfinal <E extends Exception>
voidhandleException
(@NonNull C sender, @NonNull Class<E> clazz, @NonNull E exception, @NonNull BiConsumer<C, E> defaultHandler) Handle an exception using the registered exception handler for the exception type, or using the provided default handler if no exception handler has been registered for the exception typeboolean
hasCapability
(@NonNull CloudCapability capability) Checks whether the cloud implementation has the givencapability
.boolean
hasPermission
(@NonNull C sender, @NonNull CommandPermission permission) Check if the command sender has the required permission.abstract boolean
hasPermission
(@NonNull C sender, @NonNull String permission) Check if the command sender has the required permission.boolean
Check if command registration is allowed.protected final void
Transition the command manager from eitherCommandManager.RegistrationState.BEFORE_REGISTRATION
orCommandManager.RegistrationState.REGISTERING
toCommandManager.RegistrationState.AFTER_REGISTRATION
.final @NonNull ParameterInjectorRegistry<C>
Get the parameter injector registry instance@NonNull ParserRegistry<C>
Returns the parser registry intance.cloud.commandframework.services.State
postprocessContext
(@NonNull CommandContext<C> context, @NonNull Command<C> command) Postprocess a command context instancecloud.commandframework.services.State
preprocessContext
(@NonNull CommandContext<C> context, @NonNull LinkedList<@NonNull String> inputQueue) Preprocess a command context instanceprotected final void
registerCapability
(@NonNull CloudCapability capability) Registers the givencapability
.void
registerCommandPostProcessor
(@NonNull CommandPostprocessor<C> processor) Register a new command postprocessor.void
registerCommandPreProcessor
(@NonNull CommandPreprocessor<C> processor) Register a new command preprocessor.final void
registerDefaultCaptions
(@NonNull CaptionRegistry<C> captionRegistry) Deprecated.UsecaptionRegistry(CaptionRegistry)
These methods are identical.final <E extends Exception>
voidregisterExceptionHandler
(@NonNull Class<E> clazz, @NonNull BiConsumer<@NonNull C, @NonNull E> handler) Register an exception handler for an exception type.final @NonNull CommandManager.RegistrationState
Returns the active registration state for this manager.protected final void
requireState
(@NonNull CommandManager.RegistrationState expected) Require that the commands manager is in a certain state.@NonNull Collection<@NonNull String>
Returns all root command names.final void
setCaptionRegistry
(@NonNull CaptionRegistry<C> captionRegistry) Deprecated.for removal since 1.7.0.protected final void
setCommandRegistrationHandler
(@NonNull CommandRegistrationHandler commandRegistrationHandler) Deprecated.void
setCommandSuggestionProcessor
(@NonNull CommandSuggestionProcessor<C> commandSuggestionProcessor) Deprecated.for removal since 1.7.0.void
setCommandSyntaxFormatter
(@NonNull CommandSyntaxFormatter<C> commandSyntaxFormatter) Deprecated.for removal since 1.7.0.void
setSetting
(@NonNull CommandManager.ManagerSettings setting, boolean value) Update a command manager settingGet command suggestions for the "next" argument that would yield a correctly parsing command input.protected final boolean
transitionIfPossible
(@NonNull CommandManager.RegistrationState in, @NonNull CommandManager.RegistrationState out) Transition from thein
state to theout
state, if the manager is not already in that state.protected final void
transitionOrThrow
(@NonNull CommandManager.RegistrationState in, @NonNull CommandManager.RegistrationState out) Transition from thein
state to theout
state, if the manager is not already in that state.
-
Constructor Details
-
CommandManager
protected CommandManager(@NonNull Function<@NonNull CommandTree<C>, @NonNull CommandExecutionCoordinator<C>> commandExecutionCoordinator, @NonNull CommandRegistrationHandler commandRegistrationHandler) Create a new command manager instance- Parameters:
commandExecutionCoordinator
- Execution coordinator instance. The coordinator is in charge of executing incoming commands. Some considerations must be made when picking a suitable execution coordinator for your platform. For example, an entirely asynchronous coordinator is not suitable when the parsers used in that particular platform are not thread safe. If you have commands that perform blocking operations, however, it might not be a good idea to use a synchronous execution coordinator. In most cases you will want to pick betweenCommandExecutionCoordinator.simpleCoordinator()
andAsynchronousCommandExecutionCoordinator
commandRegistrationHandler
- Command registration handler. This will get called every time a new command is registered to the command manager. This may be used to forward command registration to the platform.
-
-
Method Details
-
executeCommand
public @NonNull CompletableFuture<CommandResult<C>> executeCommand(@NonNull C commandSender, @NonNull String input) Execute a command and get a future that completes with the result. The command may be executed immediately or at some point in the future, depending on theCommandExecutionCoordinator
used in the command manager.The command may also be filtered out by preprocessors (see
CommandPreprocessor
) before they are parsed, or by theCommandArgument
command arguments during parsing. The execution may also be filtered out after parsing by aCommandPostprocessor
. In the case that a command was filtered out at any of the execution stages, the future will complete withnull
.The future may also complete exceptionally. The command manager contains some utilities that allow users to register exception handlers (
registerExceptionHandler(Class, BiConsumer)
and these can be retrieved usinggetExceptionHandler(Class)
, or used withhandleException(Object, Class, Exception, BiConsumer)
. It is highly recommended that these methods are used in the command manager, as it allows users of the command manager to override the exception handling as they wish.- Parameters:
commandSender
- Sender of the commandinput
- Input provided by the sender. Prefixes should be removed before the method is being called, and the input here will be passed directly to the command parsing pipeline, after having been tokenized.- Returns:
- future that completes with the command result, or
null
if the execution was cancelled at any of the processing stages.
-
suggest
Get command suggestions for the "next" argument that would yield a correctly parsing command input. The command suggestions provided by the command argument parsers will be filtered using theCommandSuggestionProcessor
before being returned.- Parameters:
commandSender
- Sender of the commandinput
- Input provided by the sender. Prefixes should be removed before the method is being called, and the input here will be passed directly to the command parsing pipeline, after having been tokenized.- Returns:
- List of suggestions
-
command
Register a new command to the command manager and insert it into the underlying command tree. The command will be forwarded to theCommandRegistrationHandler
and will, depending on the platform, be forwarded to the platform.Different command manager implementations have different requirements for the command registration. It is possible that a command manager may only allow registration during certain stages of the application lifetime. Read the platform command manager documentation to find out more about your particular platform
- Parameters:
command
- Command to register- Returns:
- The command manager instance. This is returned so that these method calls may be chained. This will always
return
this
.
-
command
Register a new command- Parameters:
command
- Command to register.Command.Builder.build()
} will be invoked.- Returns:
- The command manager instance
-
captionVariableReplacementHandler
@API(status=STABLE, since="1.7.0") public @NonNull CaptionVariableReplacementHandler captionVariableReplacementHandler()Get the caption variable replacement handler.- Returns:
- the caption variable replacement handler
- Since:
- 1.7.0
- See Also:
-
captionVariableReplacementHandler
@API(status=STABLE, since="1.7.0") public void captionVariableReplacementHandler(@NonNull CaptionVariableReplacementHandler captionVariableReplacementHandler) Sets the caption variable replacement handler.- Parameters:
captionVariableReplacementHandler
- new replacement handler- Since:
- 1.7.0
- See Also:
-
getCommandSyntaxFormatter
@Deprecated @API(status=DEPRECATED, since="1.7.0") public @NonNull CommandSyntaxFormatter<C> getCommandSyntaxFormatter()Deprecated.for removal since 1.7.0. Use the non-prefixed gettercommandSyntaxFormatter()
instead.Get the command syntax formatter- Returns:
- Command syntax formatter
-
commandSyntaxFormatter
@API(status=STABLE, since="1.7.0") public @NonNull CommandSyntaxFormatter<C> commandSyntaxFormatter()Returns the command syntax formatter.- Returns:
- the syntax formatter
- Since:
- 1.7.0
- See Also:
-
setCommandSyntaxFormatter
@Deprecated @API(status=DEPRECATED, since="1.7.0") public void setCommandSyntaxFormatter(@NonNull CommandSyntaxFormatter<C> commandSyntaxFormatter) Deprecated.for removal since 1.7.0. Use the non-prefixed settercommandSyntaxFormatter(CommandSyntaxFormatter)
instead.Set the command syntax formatter- Parameters:
commandSyntaxFormatter
- New formatter
-
commandSyntaxFormatter
@API(status=STABLE, since="1.7.0") public void commandSyntaxFormatter(@NonNull CommandSyntaxFormatter<C> commandSyntaxFormatter) Sets the command syntax formatter.The command syntax formatter is used to format the command syntax hints that are used in help and error messages.
- Parameters:
commandSyntaxFormatter
- new formatter- Since:
- 1.7.0
- See Also:
-
getCommandRegistrationHandler
@Deprecated @API(status=DEPRECATED, since="1.7.0") public @NonNull CommandRegistrationHandler getCommandRegistrationHandler()Deprecated.for removal since 1.7.0. Use the non-prefixed gettercommandRegistrationHandler()
instead.Get the command registration handler- Returns:
- Command registration handler
-
commandRegistrationHandler
Returns the command registration handler.The command registration handler is able to intercept newly created/deleted commands, in order to propagate these changes to the native command handler of the platform.
In platforms without a native command concept, this is likely to return
CommandRegistrationHandler.nullCommandRegistrationHandler()
.- Returns:
- the command registration handler
- Since:
- 1.7.0
-
setCommandRegistrationHandler
@Deprecated @API(status=DEPRECATED, since="1.7.0") protected final void setCommandRegistrationHandler(@NonNull CommandRegistrationHandler commandRegistrationHandler) Deprecated. -
commandRegistrationHandler
@API(status=STABLE, since="1.7.0") protected final void commandRegistrationHandler(@NonNull CommandRegistrationHandler commandRegistrationHandler) -
registerCapability
@API(status=STABLE, since="1.7.0") protected final void registerCapability(@NonNull CloudCapability capability) Registers the givencapability
.- Parameters:
capability
- the capability- Since:
- 1.7.0
- See Also:
-
hasCapability
@API(status=STABLE, since="1.7.0") public boolean hasCapability(@NonNull CloudCapability capability) Checks whether the cloud implementation has the givencapability
.- Parameters:
capability
- the capability- Returns:
true
if the implementation has thecapability
,false
if not- Since:
- 1.7.0
- See Also:
-
capabilities
@API(status=STABLE, since="1.7.0") public @NonNull Collection<@NonNull CloudCapability> capabilities()Returns an unmodifiable snapshot of the currently registeredcapabilities
.- Returns:
- the currently registered capabilities
- Since:
- 1.7.0
- See Also:
-
hasPermission
Check if the command sender has the required permission. If the permission node is empty, this should returntrue
- Parameters:
sender
- Command senderpermission
- Permission node- Returns:
true
if the sender has the permission, elsefalse
-
getCaptionRegistry
@Deprecated @API(status=DEPRECATED, since="1.7.0") public final @NonNull CaptionRegistry<C> getCaptionRegistry()Deprecated.for removal since 1.7.0. Use the non-prefixed gettercaptionRegistry()
instead.Get the caption registry- Returns:
- Caption registry
-
captionRegistry
Returns the caption registry.- Returns:
- the caption registry
- Since:
- 1.7.0
- See Also:
-
setCaptionRegistry
@Deprecated @API(status=DEPRECATED, since="1.7.0") public final void setCaptionRegistry(@NonNull CaptionRegistry<C> captionRegistry) Deprecated.for removal since 1.7.0. Use the non-prefixed settercaptionRegistry(CaptionRegistry)
instead.Replace the caption registry. Some platforms may inject their own captions into the default registry, and so you may need to insert these captions yourself if you do decide to replace the caption registry.- Parameters:
captionRegistry
- New caption registry
-
captionRegistry
@API(status=STABLE, since="1.7.0") public final void captionRegistry(@NonNull CaptionRegistry<C> captionRegistry) Replaces the caption registry.Some platforms may inject their own captions into the default caption registry, and so you may need to insert these captions yourself, if you do decide to replace the caption registry.
- Parameters:
captionRegistry
- new caption registry.- Since:
- 1.7.0
- See Also:
-
registerDefaultCaptions
@Deprecated @API(status=DEPRECATED) public final void registerDefaultCaptions(@NonNull CaptionRegistry<C> captionRegistry) Deprecated.UsecaptionRegistry(CaptionRegistry)
These methods are identical.Replace the default caption registry- Parameters:
captionRegistry
- Caption registry to use
-
hasPermission
Check if the command sender has the required permission. If the permission node is empty, this should returntrue
- Parameters:
sender
- Command senderpermission
- Permission node- Returns:
true
if the sender has the permission, elsefalse
-
deleteRootCommand
@API(status=EXPERIMENTAL, since="1.7.0") public void deleteRootCommand(@NonNull String rootCommand) throws CloudCapability.CloudCapabilityMissingException Deletes the givenrootCommand
.This will delete all chains that originate at the root command.
- Parameters:
rootCommand
- The root command to delete- Throws:
CloudCapability.CloudCapabilityMissingException
- IfCloudCapability.StandardCapabilities.ROOT_COMMAND_DELETION
is missing- Since:
- 1.7.0
-
rootCommands
Returns all root command names.- Returns:
- Root command names.
- Since:
- 1.7.0
-
commandBuilder
@Deprecated @API(status=DEPRECATED, since="1.4.0") public @NonNull Command.Builder<C> commandBuilder(@NonNull String name, @NonNull Collection<String> aliases, @NonNull Description description, @NonNull CommandMeta meta) Deprecated.for removal since 1.4.0. UsecommandBuilder(String, Collection, ArgumentDescription, CommandMeta)
instead.Create a new command builder. This will also register the creating manager in the command builder usingCommand.Builder.manager(CommandManager)
, so that the command builder is associated with the creating manager. This allows for parser inference based on the type, with the help of theparser registry
This method will not register the command in the manager. To do that,
command(Command.Builder)
orcommand(Command)
has to be invoked with either theCommand.Builder
instance, or the constructedcommand
instance- Parameters:
name
- Command namealiases
- Command aliasesdescription
- Description for the root literalmeta
- Command meta- Returns:
- Builder instance
-
commandBuilder
@API(status=STABLE, since="1.4.0") public @NonNull Command.Builder<C> commandBuilder(@NonNull String name, @NonNull Collection<String> aliases, @NonNull ArgumentDescription description, @NonNull CommandMeta meta) Create a new command builder. This will also register the creating manager in the command builder usingCommand.Builder.manager(CommandManager)
, so that the command builder is associated with the creating manager. This allows for parser inference based on the type, with the help of theparser registry
This method will not register the command in the manager. To do that,
command(Command.Builder)
orcommand(Command)
has to be invoked with either theCommand.Builder
instance, or the constructedcommand
instance- Parameters:
name
- Command namealiases
- Command aliasesdescription
- Description for the root literalmeta
- Command meta- Returns:
- Builder instance
- Since:
- 1.4.0
-
commandBuilder
public @NonNull Command.Builder<C> commandBuilder(@NonNull String name, @NonNull Collection<String> aliases, @NonNull CommandMeta meta) Create a new command builder with an empty description.This will also register the creating manager in the command builder using
Command.Builder.manager(CommandManager)
, so that the command builder is associated with the creating manager. This allows for parser inference based on the type, with the help of theparser registry
This method will not register the command in the manager. To do that,
command(Command.Builder)
orcommand(Command)
has to be invoked with either theCommand.Builder
instance, or the constructedcommand
instance- Parameters:
name
- Command namealiases
- Command aliasesmeta
- Command meta- Returns:
- Builder instance
-
commandBuilder
@Deprecated @API(status=DEPRECATED, since="1.4.0") public @NonNull Command.Builder<C> commandBuilder(@NonNull String name, @NonNull CommandMeta meta, @NonNull Description description, @NonNull String... aliases) Deprecated.for removal since 1.4.0. UsecommandBuilder(String, CommandMeta, ArgumentDescription, String...)
instead.Create a new command builder. This will also register the creating manager in the command builder usingCommand.Builder.manager(CommandManager)
, so that the command builder is associated with the creating manager. This allows for parser inference based on the type, with the help of theparser registry
This method will not register the command in the manager. To do that,
command(Command.Builder)
orcommand(Command)
has to be invoked with either theCommand.Builder
instance, or the constructedcommand
instance- Parameters:
name
- Command namemeta
- Command metadescription
- Description for the root literalaliases
- Command aliases- Returns:
- Builder instance
-
commandBuilder
@API(status=STABLE, since="1.4.0") public @NonNull Command.Builder<C> commandBuilder(@NonNull String name, @NonNull CommandMeta meta, @NonNull ArgumentDescription description, @NonNull String... aliases) Create a new command builder. This will also register the creating manager in the command builder usingCommand.Builder.manager(CommandManager)
, so that the command builder is associated with the creating manager. This allows for parser inference based on the type, with the help of theparser registry
This method will not register the command in the manager. To do that,
command(Command.Builder)
orcommand(Command)
has to be invoked with either theCommand.Builder
instance, or the constructedcommand
instance- Parameters:
name
- Command namemeta
- Command metadescription
- Description for the root literalaliases
- Command aliases- Returns:
- Builder instance
- Since:
- 1.4.0
-
commandBuilder
public @NonNull Command.Builder<C> commandBuilder(@NonNull String name, @NonNull CommandMeta meta, @NonNull String... aliases) Create a new command builder with an empty description.This will also register the creating manager in the command builder using
Command.Builder.manager(CommandManager)
, so that the command builder is associated with the creating manager. This allows for parser inference based on the type, with the help of theparser registry
This method will not register the command in the manager. To do that,
command(Command.Builder)
orcommand(Command)
has to be invoked with either theCommand.Builder
instance, or the constructedcommand
instance- Parameters:
name
- Command namemeta
- Command metaaliases
- Command aliases- Returns:
- Builder instance
-
commandBuilder
@Deprecated @API(status=DEPRECATED, since="1.4.0") public @NonNull Command.Builder<C> commandBuilder(@NonNull String name, @NonNull Description description, @NonNull String... aliases) Deprecated.for removal since 1.4.0. UsecommandBuilder(String, ArgumentDescription, String...)
instead.Create a new command builder using default command meta created bycreateDefaultCommandMeta()
.This will also register the creating manager in the command builder using
Command.Builder.manager(CommandManager)
, so that the command builder is associated with the creating manager. This allows for parser inference based on the type, with the help of theparser registry
This method will not register the command in the manager. To do that,
command(Command.Builder)
orcommand(Command)
has to be invoked with either theCommand.Builder
instance, or the constructedcommand
instance- Parameters:
name
- Command namedescription
- Description for the root literalaliases
- Command aliases- Returns:
- Builder instance
- Throws:
UnsupportedOperationException
- If the command manager does not support default command meta creation- See Also:
-
commandBuilder
@API(status=STABLE, since="1.4.0") public @NonNull Command.Builder<C> commandBuilder(@NonNull String name, @NonNull ArgumentDescription description, @NonNull String... aliases) Create a new command builder using default command meta created bycreateDefaultCommandMeta()
.This will also register the creating manager in the command builder using
Command.Builder.manager(CommandManager)
, so that the command builder is associated with the creating manager. This allows for parser inference based on the type, with the help of theparser registry
This method will not register the command in the manager. To do that,
command(Command.Builder)
orcommand(Command)
has to be invoked with either theCommand.Builder
instance, or the constructedcommand
instance- Parameters:
name
- Command namedescription
- Description for the root literalaliases
- Command aliases- Returns:
- Builder instance
- Throws:
UnsupportedOperationException
- If the command manager does not support default command meta creation- Since:
- 1.4.0
- See Also:
-
commandBuilder
Create a new command builder using default command meta created bycreateDefaultCommandMeta()
, and an empty description.This will also register the creating manager in the command builder using
Command.Builder.manager(CommandManager)
, so that the command builder is associated with the creating manager. This allows for parser inference based on the type, with the help of theparser registry
This method will not register the command in the manager. To do that,
command(Command.Builder)
orcommand(Command)
has to be invoked with either theCommand.Builder
instance, or the constructedcommand
instance- Parameters:
name
- Command namealiases
- Command aliases- Returns:
- Builder instance
- Throws:
UnsupportedOperationException
- If the command manager does not support default command meta creation- See Also:
-
argumentBuilder
public <T> @NonNull CommandArgument.Builder<C,T> argumentBuilder(@NonNull Class<T> type, @NonNull String name) Create a new command argument builder.This will also invoke
CommandArgument.Builder.manager(CommandManager)
so that the argument is associated with the calling command manager. This allows for parser inference based on the type, with the help of theparser registry
.- Type Parameters:
T
- Generic argument name- Parameters:
type
- Argument typename
- Argument name- Returns:
- Argument builder
-
flagBuilder
Create a new command flag builder- Parameters:
name
- Flag name- Returns:
- Flag builder
-
getCommandTree
Deprecated.for removal since 1.7.0. Use the non-prefixed gettercommandTree()
instead.Get the internal command tree. This should not be accessed unless you know what you are doing- Returns:
- Command tree
-
commandTree
Returns the internal command tree.Be careful when accessing the command tree. Do not interact with it, unless you absolutely know what you're doing.
- Returns:
- the command tree
- Since:
- 1.7.0
-
createDefaultCommandMeta
Construct a default command meta instance- Returns:
- Default command meta
- Throws:
UnsupportedOperationException
- If the command manager does not support this operation
-
registerCommandPreProcessor
Register a new command preprocessor. The order they are registered in is respected, and they are called in LIFO order- Parameters:
processor
- Processor to register- See Also:
-
registerCommandPostProcessor
Register a new command postprocessor. The order they are registered in is respected, and they are called in LIFO order- Parameters:
processor
- Processor to register- See Also:
-
preprocessContext
public cloud.commandframework.services.State preprocessContext(@NonNull CommandContext<C> context, @NonNull LinkedList<@NonNull String> inputQueue) Preprocess a command context instance- Parameters:
context
- Command contextinputQueue
- Command input as supplied by sender- Returns:
State.ACCEPTED
if the command should be parsed and executed, elseState.REJECTED
- See Also:
-
postprocessContext
public cloud.commandframework.services.State postprocessContext(@NonNull CommandContext<C> context, @NonNull Command<C> command) Postprocess a command context instance- Parameters:
context
- Command contextcommand
- Command instance- Returns:
State.ACCEPTED
if the command should be parsed and executed, elseState.REJECTED
- See Also:
-
getCommandSuggestionProcessor
@Deprecated @API(status=DEPRECATED, since="1.7.0") public @NonNull CommandSuggestionProcessor<C> getCommandSuggestionProcessor()Deprecated.for removal since 1.7.0. Use the non-prefixed gettercommandSuggestionProcessor()
instead.Get the command suggestions processor instance currently used in this command manager- Returns:
- Command suggestions processor
- See Also:
-
commandSuggestionProcessor
@API(status=STABLE, since="1.7.0") public @NonNull CommandSuggestionProcessor<C> commandSuggestionProcessor()Returns the command suggestion processor used in this command manager.- Returns:
- the command suggestion processor
- Since:
- 1.7.0
- See Also:
-
setCommandSuggestionProcessor
@Deprecated @API(status=DEPRECATED, since="1.7.0") public void setCommandSuggestionProcessor(@NonNull CommandSuggestionProcessor<C> commandSuggestionProcessor) Deprecated.for removal since 1.7.0. Use the non-prefixed settercommandSuggestionProcessor(CommandSuggestionProcessor)
instead.Set the command suggestions processor for this command manager. This will be called every timesuggest(Object, String)
is called, to process the list of suggestions before it's returned to the caller- Parameters:
commandSuggestionProcessor
- New command suggestions processor
-
commandSuggestionProcessor
@API(status=STABLE, since="1.7.0") public void commandSuggestionProcessor(@NonNull CommandSuggestionProcessor<C> commandSuggestionProcessor) Sets the command suggestion processor.This will be called ever time
suggest(Object, String)
is called, in order to process the list of suggestions before it's returned to the caller.- Parameters:
commandSuggestionProcessor
- the new command sugesstion processor- Since:
- 1.7.0
- See Also:
-
getParserRegistry
@Deprecated @API(status=STABLE, since="1.7.0") public @NonNull ParserRegistry<C> getParserRegistry()Deprecated.for removal since 1.7.0. Use the non-prefixed getterparserRegistry()
instead.Get the parser registry instance. The parser registry contains default mappings toArgumentParser
and allows for the registration of custom mappings. The parser registry also contains mappings of annotations toParserParameter
which allows for annotations to be used to customize parser settings.When creating a new parser type, it is recommended to register it in the parser registry. In particular, default parser types (shipped with cloud implementations) should be registered in the constructor of the platform
CommandManager
- Returns:
- Parser registry instance
-
parserRegistry
Returns the parser registry intance.The parser registry contains default mappings to
argument parsers
and allows for the registryion of custom mappings. The parser registry also contains mappings between annotations andParserParameter
, which allows for the customization of parser settings by using annotations.When creating a new parser type, it is highly recommended to register it in the parser registry. In particular, default parser types (shipped with cloud implementations) should be registered in the constructor of the platform
CommandManager
.- Returns:
- the parser registry instance
- Since:
- 1.7.0
-
parameterInjectorRegistry
Get the parameter injector registry instance- Returns:
- Parameter injector registry
- Since:
- 1.3.0
-
getExceptionHandler
public final <E extends Exception> @Nullable BiConsumer<@NonNull C,@NonNull E> getExceptionHandler(@NonNull Class<E> clazz) Get the exception handler for an exception type, if one has been registered- Type Parameters:
E
- Exception type- Parameters:
clazz
- Exception class- Returns:
- Exception handler, or
null
- See Also:
-
registerExceptionHandler
public final <E extends Exception> void registerExceptionHandler(@NonNull Class<E> clazz, @NonNull BiConsumer<@NonNull C, @NonNull E> handler) Register an exception handler for an exception type. This will then be used whenhandleException(Object, Class, Exception, BiConsumer)
is called for the particular exception type- Type Parameters:
E
- Exception type- Parameters:
clazz
- Exception classhandler
- Exception handler
-
handleException
public final <E extends Exception> void handleException(@NonNull C sender, @NonNull Class<E> clazz, @NonNull E exception, @NonNull BiConsumer<C, E> defaultHandler) Handle an exception using the registered exception handler for the exception type, or using the provided default handler if no exception handler has been registered for the exception type- Type Parameters:
E
- Exception type- Parameters:
sender
- Executing command senderclazz
- Exception classexception
- Exception instancedefaultHandler
- Default exception handler. Will be called if there is no exception handler stored for the exception type
-
getCommands
@Deprecated @API(status=DEPRECATED, since="1.7.0") public final @NonNull Collection<@NonNull Command<C>> getCommands()Deprecated.for removal since 1.7.0. Use the non-prefixed gettercommands()
instead.Get a collection containing all registered commands.- Returns:
- Unmodifiable view of all registered commands
-
commands
Returns an unmodifiable view of all registered commands.- Returns:
- unmodifiable view of all registered commands
- Since:
- 1.7.0
-
getCommandHelpHandler
@Deprecated @API(status=DEPRECATED, since="1.7.0") public final @NonNull CommandHelpHandler<C> getCommandHelpHandler()Deprecated.for removal since 1.7.0. UsecreateCommandHelpHandler()
instead.Get a command help handler instance. This can be used to assist in the production of command help menus, etc. This command help handler instance will display all commands registered in this command manager.- Returns:
- Command help handler. A new instance will be created each time this method is called.
-
createCommandHelpHandler
@API(status=STABLE, since="1.7.0") public final @NonNull CommandHelpHandler<C> createCommandHelpHandler()Creates a new command help handler instance.The command helper handler can be used to assist in the production of commad help menus, etc.
This command help handler instance will display all commands registered in this command manager.
- Returns:
- a new command helper handler instance
- Since:
- 1.7.0
-
getCommandHelpHandler
@Deprecated @API(status=DEPRECATED, since="1.7.0") public final @NonNull CommandHelpHandler<C> getCommandHelpHandler(@NonNull Predicate<Command<C>> commandPredicate) Deprecated.for removal since 1.7.0. UsecreateCommandHelpHandler(Predicate)
instead.Get a command help handler instance. This can be used to assist in the production of command help menus, etc. A predicate can be specified to filter what commands registered in this command manager are visible in the help menu.- Parameters:
commandPredicate
- Predicate that filters what commands are displayed in the help menu.- Returns:
- Command help handler. A new instance will be created each time this method is called.
-
createCommandHelpHandler
@API(status=STABLE, since="1.7.0") public final @NonNull CommandHelpHandler<C> createCommandHelpHandler(@NonNull Predicate<Command<C>> commandPredicate) Creates a new command help handler instance.The command helper handler can be used to assist in the production of commad help menus, etc.
A predicate can be specified to filter what commands registered in this command manager are visible in the help menu.
- Parameters:
commandPredicate
- predicate that filters what commands are displayed in the help menu.- Returns:
- a new command helper handler instance
- Since:
- 1.7.0
-
getSetting
Get a command manager setting- Parameters:
setting
- Setting- Returns:
true
if the setting is activated orfalse
if it's not- See Also:
-
setSetting
Update a command manager setting- Parameters:
setting
- Setting to updatevalue
- Value. In most casestrue
will enable a feature, whereasfalse
will disable it. The value passed to the method will be reflected ingetSetting(ManagerSettings)
- See Also:
-
commandExecutionCoordinator
@API(status=STABLE, since="1.6.0") public @NonNull CommandExecutionCoordinator<C> commandExecutionCoordinator()Returns the command execution coordinator used in this manager- Returns:
- Command execution coordinator
- Since:
- 1.6.0
-
transitionOrThrow
@API(status=STABLE, since="1.2.0") protected final void transitionOrThrow(@NonNull CommandManager.RegistrationState in, @NonNull CommandManager.RegistrationState out) Transition from thein
state to theout
state, if the manager is not already in that state.- Parameters:
in
- The starting stateout
- The ending state- Throws:
IllegalStateException
- if the manager is in any state butin
orout
- Since:
- 1.2.0
-
transitionIfPossible
@API(status=STABLE, since="1.2.0") protected final boolean transitionIfPossible(@NonNull CommandManager.RegistrationState in, @NonNull CommandManager.RegistrationState out) Transition from thein
state to theout
state, if the manager is not already in that state.- Parameters:
in
- The starting stateout
- The ending state- Returns:
true
if the state transition was successful, or the manager was already in the desired state- Since:
- 1.2.0
-
requireState
@API(status=STABLE, since="1.2.0") protected final void requireState(@NonNull CommandManager.RegistrationState expected) Require that the commands manager is in a certain state.- Parameters:
expected
- The required state- Throws:
IllegalStateException
- if the manager is not in the expected state- Since:
- 1.2.0
-
lockRegistration
@API(status=STABLE, since="1.4.0") protected final void lockRegistration()Transition the command manager from eitherCommandManager.RegistrationState.BEFORE_REGISTRATION
orCommandManager.RegistrationState.REGISTERING
toCommandManager.RegistrationState.AFTER_REGISTRATION
.- Throws:
IllegalStateException
- if the manager is not in the expected state- Since:
- 1.4.0
-
getRegistrationState
@Deprecated @API(status=DEPRECATED, since="1.7.0") public final @NonNull CommandManager.RegistrationState getRegistrationState()Deprecated.for removal since 1.7.0. Use the non-prefixed getterregistrationState()
instead.Get the active registration state for this manager.If this state is
CommandManager.RegistrationState.AFTER_REGISTRATION
, commands can no longer be registered- Returns:
- The current state
- Since:
- 1.2.0
-
registrationState
@API(status=STABLE, since="1.7.0") public final @NonNull CommandManager.RegistrationState registrationState()Returns the active registration state for this manager.If the state is
CommandManager.RegistrationState.AFTER_REGISTRATION
, commands can no longer be registered.- Returns:
- the current state
- Since:
- 1.7.0
-
isCommandRegistrationAllowed
@API(status=STABLE, since="1.2.0") public boolean isCommandRegistrationAllowed()Check if command registration is allowed.On platforms where unsafe registration is possible, this can be overridden by enabling the
CommandManager.ManagerSettings.ALLOW_UNSAFE_REGISTRATION
setting.- Returns:
true
if the registration is allowed, elsefalse
- Since:
- 1.2.0
-