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 Details

    • type

      protected final Type 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

      protected final List<String> suggestions
      A list storing suggestions for parameter types in a command processing framework.
  • Constructor Details

    • ArgumentType

      public ArgumentType()
      Constructs a new BaseArgumentType with an automated TypeWrap
    • ArgumentType

      public ArgumentType(Class<T> type)
      Constructs a new BaseArgumentType with the given TypeWrap.
      Parameters:
      type - The type of the parameter.
    • ArgumentType

      public ArgumentType(Type type)
      Constructs a new BaseArgumentType with the given TypeWrap.
      Parameters:
      type - The type of the parameter.
  • Method Details

    • type

      public Type 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 to parse(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

      public SuggestionProvider<S> getSuggestionProvider()
      Returns the suggestion resolver associated with this parameter type.
      Returns:
      the suggestion resolver for generating suggestions based on the parameter type.
    • getDefaultValueProvider

      @AvailableSince("1.9.1") public DefaultValueProvider 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 DefaultValueProvider providing the default value, or empty if none.
    • isRelatedToType

      public final boolean isRelatedToType(Type type)
      Checks if the given type is related to this parameter type.
      Parameters:
      type - the type to check.
      Returns:
      true if the types are related, false otherwise.
    • equalsExactly

      public final boolean equalsExactly(Type type)
      Checks if the given type exactly matches this parameter type.
      Parameters:
      type - the type to check.
      Returns:
      true if the types match exactly, false otherwise.
    • wrappedType

      public TypeWrap<T> wrappedType()
      Gets a TypeWrap for the handled type.
      Returns:
      the wrapped type.
    • isGreedy

      @AvailableSince("2.1.0") public boolean isGreedy(Argument<S> parameter)
      Determines if this parameter type is greedy, meaning it consumes multiple arguments. By default, returns false.
      Parameters:
      parameter - the command parameter.
      Returns:
      true if greedy, false otherwise.
    • getNumberOfParametersToConsume

      @AvailableSince("2.1.0") public int getNumberOfParametersToConsume(Argument<S> argument)
      Returns the number of arguments consumed by this parameter type. By default, returns 1.
      Returns:
      the number of consumed arguments.
    • addStaticSuggestions

      public void addStaticSuggestions(String... suggestions)
      Adds the provided suggestions to the current list of suggestions for this parameter type.
      Parameters:
      suggestions - The array of suggestions to be added.
    • getPriority

      @AvailableSince("3.0.0") @NotNull public @NotNull Priority getPriority()
      Specified by:
      getPriority in interface Prioritizable