Interface ArgumentParser<C,T>

Type Parameters:
C - Command sender type
T - Value type
All Known Implementing Classes:
BooleanArgument.BooleanParser, ByteArgument.ByteParser, CharArgument.CharacterParser, DoubleArgument.DoubleParser, DurationArgument.Parser, EnumArgument.EnumParser, FlagArgument.FlagArgumentParser, FloatArgument.FloatParser, IntegerArgument.IntegerParser, LongArgument.LongParser, MappedArgumentParser, ShortArgument.ShortParser, StringArgument.StringParser, StringArrayArgument.StringArrayParser, UUIDArgument.UUIDParser
Functional Interface:
This is a functional interface and can therefore be used as the assignment target for a lambda expression or method reference.

@FunctionalInterface @API(status=STABLE) public interface ArgumentParser<C,T>
Parser that parses strings into values of a specific type
  • Field Details

    • DEFAULT_ARGUMENT_COUNT

      static final int DEFAULT_ARGUMENT_COUNT
      Default amount of arguments that the parser expects to consume
      See Also:
  • Method Details

    • parse

      @NonNull ArgumentParseResult<@NonNull T> parse(@NonNull CommandContext<@NonNull C> commandContext, @NonNull Queue<@NonNull String> inputQueue)
      Parse command input into a command result.

      This method may be called when a command chain is being parsed for execution (using CommandManager.executeCommand(Object, String)) or when a command is being parsed to provide context for suggestions (using CommandManager.suggest(Object, String)). It is possible to use CommandContext.isSuggestions()} to see what the purpose of the parsing is. Particular care should be taken when parsing for suggestions, as the parsing method is then likely to be called once for every character written by the command sender.

      This method should never throw any exceptions under normal circumstances. Instead, if the parsing for some reason cannot be done successfully ArgumentParseResult.failure(Throwable) should be returned. This then wraps any exception that should be forwarded to the command sender.

      The parser is assumed to be completely stateless and should not store any information about the command sender or the command context. Instead, information should be stored in the CommandContext.

      Parameters:
      commandContext - Command context
      inputQueue - The queue of arguments
      Returns:
      Parsed command result
    • suggestions

      default @NonNull List<@NonNull String> suggestions(@NonNull CommandContext<C> commandContext, @NonNull String input)
      Get a list of suggested arguments that would be correctly parsed by this parser

      This method is likely to be called for every character provided by the sender and so it may be necessary to cache results locally to prevent unnecessary computations

      Parameters:
      commandContext - Command context
      input - Input string
      Returns:
      List of suggestions
    • map

      @API(status=STABLE, since="1.5.0") default <O> @NonNull ArgumentParser<C,O> map(BiFunction<CommandContext<C>,T,ArgumentParseResult<O>> mapper)
      Create a derived argument parser preserving all properties of this parser, but converting the output type.
      Type Parameters:
      O - the result type
      Parameters:
      mapper - the mapper to apply
      Returns:
      a derived parser.
      Since:
      1.5.0
    • isContextFree

      default boolean isContextFree()
      Check whether this argument parser is context free. A context free parser will not use the provided command context, and so supports impromptu parsing
      Returns:
      true if the parser is context free, else false
    • getRequestedArgumentCount

      @API(status=STABLE, since="1.1.0") default int getRequestedArgumentCount()
      Get the amount of arguments that this parsers seeks to consume
      Returns:
      The number of arguments tha the parser expects
      Since:
      1.1.0