Interface ParameterType<S extends Source,T>
- Type Parameters:
S- The type of the command source.T- The type of the parameter value.
- All Known Implementing Classes:
BaseParameterType,ConstrainedParameterTypeDecorator,ParameterArray,ParameterBoolean,ParameterCollection,ParameterCommand,ParameterCompletableFuture,ParameterEnum,ParameterFlag,ParameterMap,ParameterNumber,ParameterOptional,ParameterString,ParameterUUID
public interface ParameterType<S extends Source,T>
Represents a type handler for command parameters, providing methods for
type resolution, input matching, and suggestions.
-
Method Summary
Modifier and TypeMethodDescriptiondefault booleanequalsExactly(Type type) Checks if the given type exactly matches this parameter type.default intReturns the number of arguments consumed by this parameter type.Gets the suggestion resolver for this parameter type.default booleanisGreedy(CommandParameter<S> parameter) Determines if this parameter type is greedy, meaning it consumes multiple arguments.default booleanisRelatedToType(Type type) Checks if the given type is related to this parameter type.booleanmatchesInput(int rawPosition, Context<S> context, CommandParameter<S> parameter) Checks if the given input string matches this parameter type for the specified parameter.resolve(@NotNull ExecutionContext<S> context, @NotNull CommandInputStream<S> inputStream, @NotNull String input) Resolves the parameter value from the given input string, using the provided execution context and input stream.default OptionalValueSupplierReturns the default value supplier for the given source and command parameter.type()Gets the JavaTypethis parameter type handles.@NotNull ParameterType<S,T> withSuggestions(String... suggestions) Returns a newParameterTypeinstance with the specified suggestions.Gets aTypeWrapfor the handled type.
-
Method Details
-
type
Type type()Gets the JavaTypethis parameter type handles.- Returns:
- the handled type.
-
resolve
@Nullable T resolve(@NotNull @NotNull ExecutionContext<S> context, @NotNull @NotNull CommandInputStream<S> inputStream, @NotNull @NotNull String input) throws ImperatException Resolves the parameter value from the given input string, using the provided execution context and input stream.- Parameters:
context- the execution context.inputStream- the command input stream.input- the raw input string.- Returns:
- the resolved value, or
nullif resolution fails. - Throws:
ImperatException- if resolution fails due to an error.
-
getSuggestionResolver
SuggestionResolver<S> getSuggestionResolver()Gets the suggestion resolver for this parameter type.- Returns:
- the suggestion resolver.
-
matchesInput
Checks if the given input string matches this parameter type for the specified parameter.- Parameters:
rawPosition- the raw position of the argument in the input.context- the context to be matched.parameter- the command parameter.- Returns:
trueif the input matches,falseotherwise.
-
supplyDefaultValue
Returns the default value supplier for the given source and command parameter. By default, this returns an empty supplier, indicating no default value.- Returns:
- an
OptionalValueSupplierproviding the default value, or empty if none.
-
isRelatedToType
Checks if the given type is related to this parameter type.- Parameters:
type- the type to check.- Returns:
trueif the types are related,falseotherwise.
-
equalsExactly
Checks if the given type exactly matches this parameter type.- Parameters:
type- the type to check.- Returns:
trueif the types match exactly,falseotherwise.
-
withSuggestions
Returns a newParameterTypeinstance with the specified suggestions.- Parameters:
suggestions- the suggestions to use.- Returns:
- a new parameter type with suggestions.
-
wrappedType
Gets aTypeWrapfor the handled type.- Returns:
- the wrapped type.
-
isGreedy
Determines if this parameter type is greedy, meaning it consumes multiple arguments. By default, returnsfalse.- Parameters:
parameter- the command parameter.- Returns:
trueif greedy,falseotherwise.
-
getConsumedArguments
@AvailableSince("2.1.0") default int getConsumedArguments()Returns the number of arguments consumed by this parameter type. By default, returns1.- Returns:
- the number of consumed arguments.
-