- Direct Known Subclasses:
SimpleCommand
The command works using a list of valid syntaxes. For instance we could build the command "/health set Notch 50" into multiple argument types "/health [set/add/remove] [username] [integer]"
All the default argument types can be found in ArgumentType
and the syntax be created/registered using addSyntax(CommandExecutor, Argument[])
.
If the command is executed with an incorrect syntax or without any argument, the default CommandExecutor
will be called,
you can set it using setDefaultExecutor(CommandExecutor)
.
Before any syntax to be successfully executed the CommandSender
needs to validated
the CommandCondition
sets with setCondition(CommandCondition)
(ignored if null).
Some Argument
could also require additional condition (eg: a number which need to be between 2 values),
in this case, if the whole syntax is correct but not the argument condition,
you can listen to its error code using setArgumentCallback(ArgumentCallback, Argument)
or Argument.setCallback(ArgumentCallback)
.
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionaddConditionalSyntax
(@Nullable CommandCondition commandCondition, CommandExecutor executor, Argument<?>... args) Adds a new syntax in the command.void
addSubcommand
(Command command) addSyntax
(CommandExecutor executor, String format) Creates a syntax from a formatted string.addSyntax
(CommandExecutor executor, Argument<?>... args) Adds a new syntax without condition.@Nullable String[]
Gets the command's aliases.@Nullable CommandCondition
Gets theCommandCondition
.@Nullable CommandExecutor
Gets the defaultCommandExecutor
which is called when there is no argument or if no corresponding syntax has been found.getName()
Gets the main command's name.String[]
getNames()
Gets all the possible names for this command.Gets all the syntaxes of this command.void
globalListener
(CommandSender sender, CommandContext context, String command) Called when aCommandSender
executes this command before any syntax callback.static boolean
isValidName
(Command command, String name) void
setArgumentCallback
(ArgumentCallback callback, Argument<?> argument) Sets anArgumentCallback
.void
setCondition
(@Nullable CommandCondition commandCondition) Sets theCommandCondition
.void
setDefaultExecutor
(@Nullable CommandExecutor executor) Sets the defaultCommandExecutor
.
-
Constructor Details
-
Method Details
-
getCondition
Gets theCommandCondition
.It is called after the parsing and just before the execution no matter the syntax used and can be used to check permissions or the
CommandSender
type.Worth mentioning that the condition is also used to know if the command known from a player (at connection).
- Returns:
- the command condition, null if not any
-
setCondition
Sets theCommandCondition
.- Parameters:
commandCondition
- the new command condition, null to do not call anything- See Also:
-
setArgumentCallback
Sets anArgumentCallback
.The argument callback is called when there's an error in the argument.
- Parameters:
callback
- the callback for the argumentargument
- the argument which get the callback
-
addSubcommand
-
getSubcommands
-
addConditionalSyntax
public Collection<CommandSyntax> addConditionalSyntax(@Nullable @Nullable CommandCondition commandCondition, CommandExecutor executor, Argument<?>... args) Adds a new syntax in the command.A syntax is simply a list of arguments and an executor called when successfully parsed.
- Parameters:
commandCondition
- the condition to use the syntaxexecutor
- the executor to call when the syntax is successfully receivedargs
- all the arguments of the syntax, the length needs to be higher than 0- Returns:
- the created
syntaxes
, there can be multiple of them when optional arguments are used
-
addSyntax
Adds a new syntax without condition.- See Also:
-
addSyntax
Creates a syntax from a formatted string.Currently in beta as the format is not final.
- Parameters:
executor
- the syntax executorformat
- the syntax format- Returns:
- the newly created
syntaxes
.
-
getName
Gets the main command's name.- Returns:
- the main command's name
-
getAliases
Gets the command's aliases.- Returns:
- the command aliases, can be null or empty
-
getNames
Gets all the possible names for this command.Include
getName()
andgetAliases()
.- Returns:
- this command names
-
getDefaultExecutor
Gets the defaultCommandExecutor
which is called when there is no argument or if no corresponding syntax has been found.- Returns:
- the default executor, null if not any
- See Also:
-
setDefaultExecutor
Sets the defaultCommandExecutor
.- Parameters:
executor
- the new default executor, null to remove it- See Also:
-
getSyntaxes
Gets all the syntaxes of this command.- Returns:
- a collection containing all this command syntaxes
- See Also:
-
globalListener
Called when aCommandSender
executes this command before any syntax callback.WARNING: the
CommandCondition
is not executed, and all theCommandSyntax
are not checked, this is called every time aCommandSender
send a command which start bygetName()
orgetAliases()
.Can be used if you wish to still suggest the player syntaxes but want to parse things mostly by yourself.
- Parameters:
sender
- theCommandSender
context
- the UNCHECKED context of the command, some can be null even when unexpectedcommand
- the raw UNCHECKED received command
-
getSyntaxesStrings
-
getSyntaxesTree
-
isValidName
-