Class LockableCommandManager<C>
- java.lang.Object
-
- cloud.commandframework.CommandManager<C>
-
- cloud.commandframework.LockableCommandManager<C>
-
- Type Parameters:
C
- Command sender type
public abstract class LockableCommandManager<C> extends CommandManager<C>
CommandManager
implementation that allows you to lock command registrations. This should be used when the platform limits command registration to a certain point in time.To lock writes, use
lockWrites()
. To check if writing is allowed, useisCommandRegistrationAllowed()
. IfisCommandRegistrationAllowed()
isfalse
thencommand(Command)
will throwIllegalStateException
.- Since:
- 1.1.0
-
-
Nested Class Summary
-
Nested classes/interfaces inherited from class cloud.commandframework.CommandManager
CommandManager.ManagerSettings
-
-
Constructor Summary
Constructors Modifier Constructor Description protected
LockableCommandManager(@NonNull java.util.function.Function<@NonNull CommandTree<C>,@NonNull CommandExecutionCoordinator<C>> commandExecutionCoordinator, @NonNull CommandRegistrationHandler commandRegistrationHandler)
Create a new command manager instance
-
Method Summary
Modifier and Type Method Description @NonNull CommandManager<C>
command(@NonNull Command.Builder<C> command)
Register a new command@NonNull CommandManager<C>
command(@NonNull Command<C> command)
Register a new command to the command manager and insert it into the underlying command tree.boolean
isCommandRegistrationAllowed()
Check if command registration is allowedprotected void
lockWrites()
Lock writing.-
Methods inherited from class cloud.commandframework.CommandManager
argumentBuilder, commandBuilder, commandBuilder, commandBuilder, commandBuilder, commandBuilder, commandBuilder, createDefaultCommandMeta, executeCommand, flagBuilder, getCaptionRegistry, getCommandHelpHandler, getCommandRegistrationHandler, getCommands, getCommandSuggestionProcessor, getCommandSyntaxFormatter, getCommandTree, getExceptionHandler, getParserRegistry, getSetting, handleException, hasPermission, hasPermission, postprocessContext, preprocessContext, registerCommandPostProcessor, registerCommandPreProcessor, registerDefaultCaptions, registerExceptionHandler, setCaptionRegistry, setCommandRegistrationHandler, setCommandSuggestionProcessor, setCommandSyntaxFormatter, setSetting, suggest
-
-
-
-
Constructor Detail
-
LockableCommandManager
protected LockableCommandManager(@NonNull java.util.function.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
-
-
Method Detail
-
command
public final @NonNull CommandManager<C> command(@NonNull Command<C> 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
This should only be called when
isCommandRegistrationAllowed()
istrue
, elseIllegalStateException
will be called- Overrides:
command
in classCommandManager<C>
- Parameters:
command
- Command to register- Returns:
- The command manager instance
-
command
public final @NonNull CommandManager<C> command(@NonNull Command.Builder<C> command)
Register a new commandThis should only be called when
isCommandRegistrationAllowed()
istrue
, elseIllegalStateException
will be called- Overrides:
command
in classCommandManager<C>
- Parameters:
command
- Command to register.Command.Builder.build()
} will be invoked.- Returns:
- The command manager instance
-
lockWrites
protected final void lockWrites()
Lock writing. After this,isCommandRegistrationAllowed()
will returnfalse
-
isCommandRegistrationAllowed
public final boolean isCommandRegistrationAllowed()
Check if command registration is allowed- Returns:
true
if the registration is allowed, elsefalse
-
-