Interface Command.Parameterized
-
- All Superinterfaces:
Command
- Enclosing interface:
- Command
public static interface Command.Parameterized extends Command
ACommand
that has distinct steps for parsing arguments and executing a command based on those arguments.Plugins must not attempt to create their own instance of this interface, and instead must use
Command.builder()
to do so.
-
-
Nested Class Summary
-
Nested classes/interfaces inherited from interface org.spongepowered.api.command.Command
Command.Builder, Command.Parameterized, Command.Raw
-
-
Method Summary
All Methods Instance Methods Abstract Methods Default Methods Modifier and Type Method Description java.util.function.Predicate<CommandCause>
executionRequirements()
Gets aPredicate
that backsCommand.canExecute(CommandCause)
.java.util.Optional<CommandExecutor>
executor()
Gets theCommandExecutor
for this command, if one exists.java.util.List<Flag>
flags()
boolean
isTerminal()
Gets whetherCommand.Builder.terminal(boolean)
was explicitly set totrue
, such that this command will execute without any arguments, regardless of the command'sparameters
orsubcommands
.java.util.List<Parameter>
parameters()
CommandContext
parseArguments(CommandCause cause, ArgumentReader.Mutable arguments)
Parses the parameters based on the providedparameters()
default CommandResult
process(CommandCause cause, ArgumentReader.Mutable arguments)
Processes the command by parsing the arguments, then executing command based on these arguments.java.util.List<Parameter.Subcommand>
subcommands()
AList
of directsubcommands
that this command contains.-
Methods inherited from interface org.spongepowered.api.command.Command
canExecute, complete, extendedDescription, help, shortDescription, usage
-
-
-
-
Method Detail
-
subcommands
java.util.List<Parameter.Subcommand> subcommands()
AList
of directsubcommands
that this command contains.A direct subcommand is one that is specified directly after the literal the invokes this command, e.g. on the command
/foo
,bar
is a direct subcommand if it was specified inCommand.Builder.addChild(Parameterized, String...)
orCommand.Builder.addChildren(Map)
with the aliasbar
. This will not contain any subcommands that were registered viaCommand.Builder.addParameter(Parameter)
- Returns:
- A copy of the collection of subcommands.
-
isTerminal
boolean isTerminal()
Gets whetherCommand.Builder.terminal(boolean)
was explicitly set totrue
, such that this command will execute without any arguments, regardless of the command'sparameters
orsubcommands
.- Returns:
- if this
Command.Parameterized
is terminal.
-
executionRequirements
java.util.function.Predicate<CommandCause> executionRequirements()
Gets aPredicate
that backsCommand.canExecute(CommandCause)
.- Returns:
- The predicate.
-
parseArguments
CommandContext parseArguments(CommandCause cause, ArgumentReader.Mutable arguments) throws ArgumentParseException
Parses the parameters based on the providedparameters()
- Parameters:
cause
- TheCause
of this parsearguments
- The argumentString
- Returns:
- The
CommandContext
- Throws:
ArgumentParseException
- if a parameter could not be parsed
-
executor
java.util.Optional<CommandExecutor> executor()
Gets theCommandExecutor
for this command, if one exists.- Returns:
- The
CommandExecutor
, if it exists.
-
process
default CommandResult process(CommandCause cause, ArgumentReader.Mutable arguments) throws CommandException
Processes the command by parsing the arguments, then executing command based on these arguments.By default, this will call
parseArguments(CommandCause, ArgumentReader.Mutable)
and pass the resultingCommandContext
toCommandExecutor.execute(CommandContext)
, if this command has an executor. If it does not, this will throw aCommandException
.- Specified by:
process
in interfaceCommand
- Parameters:
cause
- TheCause
of the commandarguments
- The raw arguments for this command- Returns:
- The result of a command being processed
- Throws:
CommandException
- Thrown on a command error
-
-