Class Command<C>
- Type Parameters:
C- command sender type
command components with an associated commandExecutionHandler().
The recommended way of creating a command is by using a command builder.
You may either create the command builder using newBuilder(String, CommandMeta, String...) or
CommandBuilderSource.commandBuilder(String, String...).
Getting a builder from the command manager means that the builder is linked to the manager.
When the command builder is linked to the manager, it is able to retrieve parsers from the associated
ParserRegistry in the case that only a parsed type is given to the builder,
and not a complete parser.
You may link any command builder to a command manager by using Command.Builder.manager(CommandManager).
All command flags added to a command builder will be collected into a single component.
If there are flags added to the command, then they may be retrieved from the flagComponent() or from the
flagParser().
Commands may have meta-data associated with them, which can be accessed using commandMeta().
A common way of using the command meta is by using it to filter out commands in post-processing.
A command may have a senderType() that is different from the sender type of the command manager.
The command tree will enforce this type when parsing the command.
-
Nested Class Summary
Nested Classes -
Constructor Summary
ConstructorsConstructorDescriptionCommand(@NonNull List<@NonNull CommandComponent<C>> commandComponents, @NonNull CommandExecutionHandler<@NonNull C> commandExecutionHandler, @Nullable Type senderType, @NonNull Permission permission, @NonNull CommandMeta commandMeta, @NonNull CommandDescription commandDescription) Constructs a new command instance. -
Method Summary
Modifier and TypeMethodDescriptionReturns the description of the command.Returns the command execution handler.Returns the meta-data associated with the command.Returns the permission required to execute the command.Returns a copy of the list of the components that make up this command.Returns the component that contains the flags belonging to the command.Returns the flag parser for this command, ofnullif the command has no flags.static <C> @NonNull Command.Builder<C> newBuilder(@NonNull String commandName, @NonNull CommandMeta commandMeta, @NonNull String @NonNull ... aliases) Creates a new command builder.static <C> @NonNull Command.Builder<C> newBuilder(@NonNull String commandName, @NonNull CommandMeta commandMeta, @NonNull Description description, @NonNull String @NonNull ... aliases) Creates a new command builder.Returns a mutable copy of the command components, ignoring flag arguments.Returns the first command component.Returns the specific command sender type for the command if one has been defined.final StringtoString()
-
Constructor Details
-
Command
@API(status=INTERNAL) public Command(@NonNull List<@NonNull CommandComponent<C>> commandComponents, @NonNull CommandExecutionHandler<@NonNull C> commandExecutionHandler, @Nullable Type senderType, @NonNull Permission permission, @NonNull CommandMeta commandMeta, @NonNull CommandDescription commandDescription) Constructs a new command instance.- Parameters:
commandComponents- command component argument and descriptioncommandExecutionHandler- execution handlersenderType- required sender type. May benullpermission- command permissioncommandMeta- command meta instancecommandDescription- description of the command
-
-
Method Details
-
newBuilder
@API(status=STABLE) public static <C> @NonNull Command.Builder<C> newBuilder(@NonNull String commandName, @NonNull CommandMeta commandMeta, @NonNull Description description, @NonNull String @NonNull ... aliases) Creates a new command builder.Is recommended to use the builder methods in
CommandManagerrather than invoking this method directly.- Type Parameters:
C- command sender type- Parameters:
commandName- base command argumentcommandMeta- command meta instancedescription- description of the root literalaliases- command aliases- Returns:
- command builder
-
newBuilder
public static <C> @NonNull Command.Builder<C> newBuilder(@NonNull String commandName, @NonNull CommandMeta commandMeta, @NonNull String @NonNull ... aliases) Creates a new command builder.Is recommended to use the builder methods in
CommandManagerrather than invoking this method directly.- Type Parameters:
C- command sender type- Parameters:
commandName- base command argumentcommandMeta- command meta instancealiases- command aliases- Returns:
- command builder
-
components
Returns a copy of the list of the components that make up this command.- Returns:
- modifiable copy of the component list
-
rootComponent
Returns the first command component.- Returns:
- the root component
-
nonFlagArguments
Returns a mutable copy of the command components, ignoring flag arguments.- Returns:
- argument list
-
flagComponent
Returns the component that contains the flags belonging to the command.- Returns:
- the flag component, or
nullif no flags have been registered
-
flagParser
Returns the flag parser for this command, ofnullif the command has no flags.- Returns:
- flag parser, or
nullif no flags have been registered
-
commandExecutionHandler
Returns the command execution handler.The command execution handler is invoked after a parsing a command. It has access to the
CommandContextwhich contains the parsed component values.- Returns:
- the command execution handler
-
senderType
Returns the specific command sender type for the command if one has been defined.A command may have a sender that is different from the sender type of the command manager. The command tree will enforce this type when parsing the command.
- Returns:
- the special sender type for the command, or
Optional.empty()if the command uses the same sender type as the command manager
-
commandPermission
Returns the permission required to execute the command.If the sender does not have the required permission a
NoPermissionExceptionwill be thrown when parsing the command.- Returns:
- the command permission
-
commandMeta
Returns the meta-data associated with the command.A common way of using the command meta is by using it to filter out commands in post-processing.
- Returns:
- Command meta
-
commandDescription
Returns the description of the command.This is not the same as the description of the root component. The command description used to be configured through the
commandMeta().- Returns:
- the command description
-
toString
-