Interface Parameter.Value.Builder<T>
-
- All Superinterfaces:
Buildable.Builder<Parameter.Value<T>>
,Builder<Parameter.Value<T>,Parameter.Value.Builder<T>>
,ResettableBuilder<Parameter.Value<T>,Parameter.Value.Builder<T>>
- Enclosing interface:
- Parameter.Value<T>
public static interface Parameter.Value.Builder<T> extends Builder<Parameter.Value<T>,Parameter.Value.Builder<T>>
Builds aParameter
from constituent components.
-
-
Method Summary
All Methods Instance Methods Abstract Methods Default Methods Modifier and Type Method Description default <V extends ValueParser<? extends T>>
Parameter.Value.Builder<T>addParser(@NonNull DefaultedRegistryReference<V> parser)
TheValueParser
that will extract the value(s) from the parameters.Parameter.Value.Builder<T>
addParser(ValueParser<? extends T> parser)
TheValueParser
that will extract the value(s) from the parameters.Parameter.Value<T>
build()
Creates aParameter
from the builder.Parameter.Value.Builder<T>
completer(@Nullable ValueCompleter completer)
Provides a function that provides tab completionsParameter.Value.Builder<T>
consumeAllRemaining()
If set, this parameter will repeat until the argument string has been parsed.Parameter.Value.Builder<T>
key(String key)
The key that the parameter will place parsed values into.Parameter.Value.Builder<T>
key(Parameter.Key<T> key)
The key that the parameter will place parsed values into.Parameter.Value.Builder<T>
modifier(@Nullable ValueParameterModifier<T> modifier)
Provides a modifier that allows for the modification of the outcome of an argument parse or a completion.Parameter.Value.Builder<T>
optional()
Marks this parameter as optional, such that if an argument does not exist or cannot be parsed, an exception is not thrown, and no value is returned.Parameter.Value.Builder<T>
requiredPermission(@Nullable String permission)
Parameter.Value.Builder<T>
requirements(@Nullable Predicate<CommandCause> executionRequirements)
Sets a function that determines what is required of the providedCause
before this parameter attempts to parse.Parameter.Value.Builder<T>
terminal()
Marks this parameter as a terminal parameter.Parameter.Value.Builder<T>
usage(@Nullable ValueUsage usage)
Sets the usage.
-
-
-
Method Detail
-
key
Parameter.Value.Builder<T> key(String key)
The key that the parameter will place parsed values into.This is a mandatory element.
- Parameters:
key
- The key.- Returns:
- This builder, for chaining
-
key
Parameter.Value.Builder<T> key(Parameter.Key<T> key)
The key that the parameter will place parsed values into.This is a mandatory element.
- Parameters:
key
- The key.- Returns:
- This builder, for chaining
-
addParser
Parameter.Value.Builder<T> addParser(ValueParser<? extends T> parser)
TheValueParser
that will extract the value(s) from the parameters. If this is aValueParameter
, the object's complete and usage methods will be used for completion and usage unless this builder'scompleter(ValueCompleter)
} andusage(ValueUsage)
methods are specified.- Parameters:
parser
- TheValueParameter
to use- Returns:
- This builder, for chaining
-
addParser
default <V extends ValueParser<? extends T>> Parameter.Value.Builder<T> addParser(@NonNull DefaultedRegistryReference<V> parser)
TheValueParser
that will extract the value(s) from the parameters. If this is aValueParameter
, the object's complete and usage methods will be used for completion and usage unless this builder'scompleter(ValueCompleter)
} andusage(ValueUsage)
methods are specified.- Type Parameters:
V
- TheValueParser
to be used as a parser- Parameters:
parser
- TheValueParser
to use- Returns:
- This builder, for chaining
-
completer
Parameter.Value.Builder<T> completer(@Nullable ValueCompleter completer)
Provides a function that provides tab completionsOptional. If this is
null
(or never set), completions will either be done via the suppliedaddParser(ValueParser)
or will just return an empty list. If this is supplied, no modifiers will run on completion.- Parameters:
completer
- TheValueCompleter
- Returns:
- This builder, for chaining
-
modifier
Parameter.Value.Builder<T> modifier(@Nullable ValueParameterModifier<T> modifier)
Provides a modifier that allows for the modification of the outcome of an argument parse or a completion. This is primarily intended for use with Mojang/Sponge standard parameters, allowing developers to tweak the input of a standard parameter without having to worry about completion types.Developers should only use this when they use a parameter type that they do not control. If you are using this with a
ValueParameter
,ValueParser
orValueCompleter
that you control (that is, able to modify the source of), it is strongly recommended that you do that instead. For more information about how a modifier should be used, read theValueParameterModifier
docs instead.Optional. If this is
null
(or never set), any outcomes will not be modified.- Parameters:
modifier
- The modifier- Returns:
- This builder, for chaning
-
usage
Parameter.Value.Builder<T> usage(@Nullable ValueUsage usage)
Sets the usage. TheFunction
accepts the parameter key and the callingCause
.Optional. If this is
null
(or never set), the usage string will either be provided via the suppliedaddParser(ValueParser)
or will just return the parameter's key. If this is supplied, no modifiers will run on usage.- Parameters:
usage
- The function- Returns:
- This builder, for chaining
-
requiredPermission
Parameter.Value.Builder<T> requiredPermission(@Nullable String permission)
Sets a function that determines what is required of the appropriateSubject
in the providedCause
before this parameter is parsed.If the source does not have this permission, this parameter will simply be skipped. Consider combining this with
optional()
so that those with permission can also skip this parameter.- Parameters:
permission
- The permission to check for, ornull
for no check.- Returns:
- This builder, for chaining
-
requirements
Parameter.Value.Builder<T> requirements(@Nullable Predicate<CommandCause> executionRequirements)
Sets a function that determines what is required of the providedCause
before this parameter attempts to parse.If this is set to
null
, this parameter will always attempt to parse, subject to other modifiers.Note: this will overwrite any requirements set using
requiredPermission(String)
}.- Parameters:
executionRequirements
- A function that sets the- Returns:
- This builder, for chaining
-
consumeAllRemaining
Parameter.Value.Builder<T> consumeAllRemaining()
If set, this parameter will repeat until the argument string has been parsed.For example, if you have the argument string,
1 2 3 4
and you use
ResourceKeyedValueParameters.INTEGER
without setting this method, this parameter will parse the first element, 1, and the remaining elements will be left for the next parameter in the chain. If you call this method, the resultingParameter.Value
will continuously parse the argument string until either:- The entire argument string has been parsed, in which case the parsing is considered complete and command execution will continue
- A part of the argument string could not be parsed, in which
case an exception will be raised. If this element is also marked
as
optional()
, then parsing will continue as if nothing has been parsed.
Unless marked as optional, this element must be able to consume at least one argument. This will automatically mark the element as
terminal
.- Returns:
- This builder, for chaining
-
optional
Parameter.Value.Builder<T> optional()
Marks this parameter as optional, such that if an argument does not exist or cannot be parsed, an exception is not thrown, and no value is returned.- Returns:
- This builder, for chaining
-
terminal
Parameter.Value.Builder<T> terminal()
Marks this parameter as a terminal parameter. Any terminal parameter can be considered as a point where argument parsing can stop, allowing control to pass to the command's associatedCommandExecutor
.Note that a parameter may be considered terminal even if this isn't set, including if the parameter will consume the rest of the argument string, or if all following arguments are
optional()
. In these scenarios, the built parameter may not be aware of its terminal status.- Returns:
- This builder, for chaining.
-
build
Parameter.Value<T> build()
Creates aParameter
from the builder.- Specified by:
build
in interfaceBuildable.Builder<T>
- Returns:
- The
Parameter
-
-