Interface Command.Builder
- All Superinterfaces:
AbstractBuilder<Command.Parameterized>
,Builder<Command.Parameterized,
,Command.Builder> ResettableBuilder<Command.Parameterized,
Command.Builder>
- Enclosing interface:
- Command
Command.Builder
for creating a
Command.Parameterized
.
When creating a command, ensure that a CommandExecutor
and/or a child command is specified.
-
Method Summary
Modifier and TypeMethodDescriptionaddChild
(Command.Parameterized child, Iterable<String> keys) Adds aCommand.Parameterized
as a child to this command, under the supplied keys.default Command.Builder
addChild
(Command.Parameterized child, String... keys) Adds aCommand.Parameterized
as a top-level child to this command, using the supplied keys.default Command.Builder
addChildren
(Map<? extends Iterable<String>, ? extends Command.Parameterized> children) Adds multipleCommand.Parameterized
as children to this command, under the supplied keys.Adds a flag to this command.default Command.Builder
Adds multipleflags
to this command.default Command.Builder
Adds multipleflags
to this command.addParameter
(Parameter parameter) Adds a parameter for use when parsing arguments.default Command.Builder
addParameters
(Iterable<Parameter> parameters) Adds parameters to use when parsing arguments.default Command.Builder
addParameters
(Parameter... parameters) Adds parameters to use when parsing arguments.build()
Builds this command, creating aCommand.Parameterized
object.executionRequirements
(@Nullable Predicate<CommandCause> executionRequirements) Sets a function that determines what is required of the providedCause
before this command executes.executor
(CommandExecutor executor) Provides the logic of the command.default Command.Builder
extendedDescription
(@Nullable Component extendedDescription) Provides the description for this command.extendedDescription
(Function<CommandCause, Optional<Component>> extendedDescriptionFunction) Provides the description for this command, which is dependent on theCause
that requests it.permission
(@Nullable String permission) default Command.Builder
permission
(PermissionDescription permission) default Command.Builder
shortDescription
(@Nullable Component description) Provides a simple description for this command, typically no more than one line.shortDescription
(Function<CommandCause, Optional<Component>> descriptionFunction) Provides a simple description for this command, typically no more than one line, which is dependent on theCause
that requests it.terminal
(boolean terminal) Sets whether this command is considered "terminal" in its own right, that is, can be executed on its own if no arguments are supplied when invoked, regardless of whether any suppliedParameter
s are mandatory.
-
Method Details
-
addChild
Adds aCommand.Parameterized
as a top-level child to this command, using the supplied keys. The keys are case insensitive.Children added here will be added to the beginning of the
Parameter
s. Note that if you wish to add a subcommand in the middle of the parameters, you can do so by creating aParameter.Subcommand
and adding that as aaddParameter(Parameter)
at the appropriate time.- Parameters:
child
- TheCommand
that is a child.keys
- The keys to register as a sub command.- Returns:
- This builder, for chaining
- Throws:
IllegalArgumentException
- thrown if a child key is already in the builder, or there are no keys supplied
-
addChild
Adds aCommand.Parameterized
as a child to this command, under the supplied keys. The keys are case insensitive.Children added here will be added to the beginning of the
Parameter
s. Note that if you wish to add a subcommand in the middle of the parameters, you can do so by creating aParameter.Subcommand
and adding that as aaddParameter(Parameter)
at the appropriate time.- Parameters:
child
- TheCommand
that is a child.keys
- The keys to register as a sub command.- Returns:
- This builder, for chaining
- Throws:
IllegalArgumentException
- thrown if a child key is already in the builder
-
addChildren
default Command.Builder addChildren(Map<? extends Iterable<String>, ? extends Command.Parameterized> children) Adds multipleCommand.Parameterized
as children to this command, under the supplied keys. The keys are case insensitive.Children added here will be added to the beginning of the
Parameter
s. Note that if you wish to add a subcommand in the middle of the parameters, you can do so by creating aParameter.Subcommand
and adding that as aaddParameter(Parameter)
at the appropriate time.- Parameters:
children
- TheMap
that contains a mapping of keys to their respectiveCommand
children.- Returns:
- This builder, for chaining
- Throws:
IllegalArgumentException
- thrown if a child key is already in the builder
-
addFlag
Adds a flag to this command. Flags are always the first arguments of a command. There are no set rules for the order of execution of flags (unlikeaddParameter(Parameter)
), and all flags are considered optional.Duplicate keys and/or duplicate aliases may not be provided.
- Parameters:
flag
- TheFlag
to support- Returns:
- Ths builder, for chaining
-
addFlags
Adds multipleflags
to this command.- Parameters:
flags
- The flags- Returns:
- This builder, for chaining
- See Also:
-
addFlags
Adds multipleflags
to this command.- Parameters:
flags
- The flags- Returns:
- This builder, for chaining
- See Also:
-
addParameter
Adds a parameter for use when parsing arguments. When executing a command, they will be executed in the order they are added to this builder.- Parameters:
parameter
- The parameter to add to the parameter list- Returns:
- This builder, for chaining
-
addParameters
Adds parameters to use when parsing arguments. Parameters will be used in the order provided here.- Parameters:
parameters
- TheParameter
s to use- Returns:
- This builder, for chaining
-
addParameters
Adds parameters to use when parsing arguments. Parameters will be used in the order provided here.- Parameters:
parameters
- TheParameter
s to use- Returns:
- This builder, for chaining
-
executor
Provides the logic of the command.This is only optional if child commands are specified. This will replace any previous executor that has been set.
- Parameters:
executor
- TheCommandExecutor
that will run the command- Returns:
- This builder, for chaining
-
extendedDescription
Command.Builder extendedDescription(Function<CommandCause, Optional<Component>> extendedDescriptionFunction) Provides the description for this command, which is dependent on theCause
that requests it.A one line summary should be provided to
shortDescription(Component)
It is recommended to use the default text color and style. Sections with text actions (e.g. hyperlinks) should be underlined.
- Parameters:
extendedDescriptionFunction
- A function that provides a relevant description based on the suppliedCause
- Returns:
- This builder, for chaining
-
extendedDescription
Provides the description for this command.A one line summary should be provided to
shortDescription(Component)
- Parameters:
extendedDescription
- The description to use, ornull
for no description.- Returns:
- This builder, for chaining
-
shortDescription
Provides a simple description for this command, typically no more than one line, which is dependent on theCause
that requests it.Fuller descriptions should be provided through
extendedDescription(Function)
- Parameters:
descriptionFunction
- A function that provides a relevant description based on the suppliedCause
- Returns:
- This builder, for chaining
-
shortDescription
Provides a simple description for this command, typically no more than one line.Fuller descriptions should be provided through
extendedDescription(Component)
It is recommended to use the default text color and style. Sections with text actions (e.g. hyperlinks) should be underlined.
- Parameters:
description
- The description to use, ornull
for no description- Returns:
- This builder, for chaining
-
permission
The permission that the responsibleSubject
in the givenCause
requires to run this command, ornull
if no permission is required. Calling this method will overwrite anything set viaexecutionRequirements(Predicate)
, or will replace the previous permission set by this method.Any permission checks set here will be performed during the
Command.canExecute(CommandCause)
.- Parameters:
permission
- The permission that is required, ornull
for no permission- Returns:
- This builder, for chaining
-
permission
The permission that the responsibleSubject
in the givenCause
requires to run this command.For more control over whether a command can be executed, use
executionRequirements(Predicate)
. However, note that setting a permission here will not override anything set inexecutionRequirements(Predicate)
, both will be checked during execution.Any permission checks set here will be performed during the
Command.canExecute(CommandCause)
.Calling this repeatedly will not add additional permission checks, instead replacing the permission check. If multiple permission checks are required, use
executionRequirements(Predicate)
.- Parameters:
permission
- The description for the required permission.- Returns:
- This builder, for chaining
-
executionRequirements
Sets a function that determines what is required of the providedCause
before this command executes. Calling this method will overwrite anything set viapermission(String)
or anything previously set via this method.Any requirements set here will be performed as part of
Command.canExecute(CommandCause)
.- Parameters:
executionRequirements
- A function that sets the- Returns:
- This builder, for chaining
-
terminal
Sets whether this command is considered "terminal" in its own right, that is, can be executed on its own if no arguments are supplied when invoked, regardless of whether any suppliedParameter
s are mandatory.- Parameters:
terminal
- Whether to mark this command as terminal- Returns:
- This builder, for chaining
- See Also:
-
build
Command.Parameterized build()Builds this command, creating aCommand.Parameterized
object.To build the command, one of the following is required:
- A
CommandExecutor
is provided usingexecutor(CommandExecutor)
- At least one
Command
is set to be a child command usingaddChild(Parameterized, Iterable)
oraddChildren(Map)
If these conditions are not fulfilled, an
IllegalStateException
will be thrown.- Specified by:
build
in interfaceAbstractBuilder<Command.Parameterized>
- Returns:
- The command, ready for registration
- Throws:
IllegalStateException
- if the builder is not complete
- A
-