Interface Command
- All Known Subinterfaces:
Command.Parameterized,Command.Raw
Most plugins are highly recommended (but not obligated)
to use builder() to create commands. The
Command.Builder allows plugins to take advantage of a higher level
of abstraction, such as argument parsers and simple child command handling,
removing the need for boilerplate code. Such Command.Parameterized commands
should register themselves during the RegisterCommandEvent<Command.Parameterized> event.
Plugins that do not want to use the Command.Builder or any third-party
command system should implement the Command.Raw sub-interface instead. Such
Command.Raw commands should register themselves during the
RegisterCommandEvent<Command.Raw>
event.
Plugins must not implement the Command.Parameterized
sub-interface themselves.
Upon execution, commands are provided with a CommandCause,
providing the Cause and EventContext that invoked the
command. See the CommandCause documentation for more information
of the structure of this cause.
-
Nested Class Summary
Nested ClassesModifier and TypeInterfaceDescriptionstatic interfaceA high levelCommand.Builderfor creating aCommand.Parameterized.static interfaceACommandthat has distinct steps for parsing arguments and executing a command based on those arguments.static interfaceA raw command that also contains aCommandTreeNodeto provide hints to the client for command completion. -
Method Summary
Modifier and TypeMethodDescriptionstatic Command.Builderbuilder()Gets a builder for building aCommand.booleancanExecute(CommandCause cause) Test whether this command can probably be executed given thisCause.complete(CommandCause cause, ArgumentReader.Mutable arguments) Gets a list of completions based on input.extendedDescription(CommandCause cause) Gets a longer formatted help message about this command.help(@NonNull CommandCause cause) Gets a longer formatted help message about this command.process(CommandCause cause, ArgumentReader.Mutable arguments) Execute the command based on input arguments.shortDescription(CommandCause cause) Gets a short one-line description of this command.usage(CommandCause cause) Gets the usage string of this command.
-
Method Details
-
builder
Gets a builder for building aCommand.- Returns:
- The
Command.Builder
-
process
Execute the command based on input arguments.The implementing class must perform the necessary permission checks.
- Parameters:
cause- TheCommandCauseof the invocation of commandarguments- The raw arguments for this command- Returns:
- The result of a command being processed
- Throws:
CommandException- Thrown on a command error
-
complete
List<CommandCompletion> complete(CommandCause cause, ArgumentReader.Mutable arguments) throws CommandException Gets a list of completions based on input.If a completion is chosen by the user, it will replace the last word.
- Parameters:
cause- TheCommandCauseof the commandarguments- The arguments entered up to this point- Returns:
- A list of suggestions
- Throws:
CommandException- Thrown if there was a parsing error
-
canExecute
Test whether this command can probably be executed given thisCause.If implementations are unsure if the command can be executed by the source,
trueshould be returned. Return values of this method may be used to determine whether this command is listed in command listings.- Parameters:
cause- TheCauseto check- Returns:
- Whether this command will execute
-
shortDescription
Gets a short one-line description of this command.The help system may display the description in the command list, or in any other function that displays a command list. It is therefore recommended that any description here is kept very short.
- Parameters:
cause- TheCommandCauseof the help request- Returns:
- A description
- See Also:
-
extendedDescription
Gets a longer formatted help message about this command.The help system may display this description when displaying details about this specific command. It should not contain the description provided by
shortDescription(CommandCause).- Parameters:
cause- TheCauseof the help request- Returns:
- A description
-
help
Gets a longer formatted help message about this command. This will typically comprise ofshortDescription(CommandCause)andextendedDescription(CommandCause)together.The help system may display this message when a source requests detailed information about a command.
- Parameters:
cause- TheCauseof the help request- Returns:
- A help text
- See Also:
-
usage
Gets the usage string of this command.A usage string may look like
[<world>] <var1> <var2>.The string must not contain the command alias.
- Parameters:
cause- TheCauseof the help request- Returns:
- A usage string
-