Class ArgumentType<S extends CommandSource,T>
java.lang.Object
studio.mevera.imperat.util.TypeCapturer
studio.mevera.imperat.command.arguments.type.ArgumentType<S,T>
- Type Parameters:
S- The type of the source from which the command originates.T- The type of the parameter being handled.
- All Implemented Interfaces:
Prioritizable
- Direct Known Subclasses:
ArrayArgument,BooleanArgument,CharacterArgument,CollectionArgument,CommandArgument,CompletableFutureArgument,EitherArgument,EnumArgument,FlagArgumentType,MapArgument,NumberArgument,OptionalArgument,StringArgument,UUIDArgument
public abstract class ArgumentType<S extends CommandSource,T>
extends TypeCapturer
implements Prioritizable
Base class for defining parameter types in a command processing framework.
This class handles the basic functionality for managing type information and
suggestions for parameters.
-
Field Summary
FieldsModifier and TypeFieldDescriptionA list storing suggestions for parameter types in a command processing framework.protected final TypeEncapsulates type information for the parameter being handled. -
Constructor Summary
ConstructorsConstructorDescriptionConstructs a new BaseArgumentType with an automatedTypeWrapArgumentType(Class<T> type) Constructs a new BaseArgumentType with the given TypeWrap.ArgumentType(Type type) Constructs a new BaseArgumentType with the given TypeWrap. -
Method Summary
Modifier and TypeMethodDescriptionvoidaddStaticSuggestions(String... suggestions) Adds the provided suggestions to the current list of suggestions for this parameter type.final booleanequalsExactly(Type type) Checks if the given type exactly matches this parameter type.Returns the default value supplier for the given source and command parameter.intgetNumberOfParametersToConsume(Argument<S> argument) Returns the number of arguments consumed by this parameter type.@NotNull PriorityReturns the suggestion resolver associated with this parameter type.booleanDetermines if this parameter type is greedy, meaning it consumes multiple arguments.final booleanisRelatedToType(Type type) Checks if the given type is related to this parameter type.abstract TParses the argument value from the given input string, using the provided execution context.parse(@NotNull ExecutionContext<S> context, @NotNull Cursor<S> cursor) Parses the argument value from the current position of the cursor, using the provided execution context.type()Retrieves the Type associated with this BaseArgumentType.Gets aTypeWrapfor the handled type.Methods inherited from class studio.mevera.imperat.util.TypeCapturer
extractType, extractType
-
Field Details
-
type
Encapsulates type information for the parameter being handled. This instance is used to collect and manage type-related information and operations specific to the parameter type. -
suggestions
A list storing suggestions for parameter types in a command processing framework.
-
-
Constructor Details
-
ArgumentType
public ArgumentType()Constructs a new BaseArgumentType with an automatedTypeWrap -
ArgumentType
Constructs a new BaseArgumentType with the given TypeWrap.- Parameters:
type- The type of the parameter.
-
ArgumentType
Constructs a new BaseArgumentType with the given TypeWrap.- Parameters:
type- The type of the parameter.
-
-
Method Details
-
type
Retrieves the Type associated with this BaseArgumentType.- Returns:
- the Type associated with this parameter type.
-
parse
public abstract T parse(@NotNull @NotNull CommandContext<S> context, @NotNull @NotNull Argument<S> argument, @NotNull @NotNull String input) throws CommandException Parses the argument value from the given input string, using the provided execution context. This method is responsible for converting the raw input into the appropriate type, handling any necessary validation or error handling during the parsing process.- Parameters:
context- the execution context.argument- the argument with this type.input- the raw input string to parse.- Returns:
- the resolved value of type T.
- Throws:
CommandException- if parsing fails.
-
parse
public T parse(@NotNull @NotNull ExecutionContext<S> context, @NotNull @NotNull Cursor<S> cursor) throws CommandException Parses the argument value from the current position of the cursor, using the provided execution context. This method fetches the input from the cursor and delegates toparse(CommandContext, Argument, String). This is the main entry point for argument parsing during command execution.- Parameters:
context- the execution context.cursor- the command input stream.- Returns:
- the resolved value of type T.
- Throws:
CommandException- if parsing fails.
-
getSuggestionProvider
Returns the suggestion resolver associated with this parameter type.- Returns:
- the suggestion resolver for generating suggestions based on the parameter type.
-
getDefaultValueProvider
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
DefaultValueProviderproviding 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.
-
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.
-
getNumberOfParametersToConsume
Returns the number of arguments consumed by this parameter type. By default, returns1.- Returns:
- the number of consumed arguments.
-
addStaticSuggestions
Adds the provided suggestions to the current list of suggestions for this parameter type.- Parameters:
suggestions- The array of suggestions to be added.
-
getPriority
- Specified by:
getPriorityin interfacePrioritizable
-