Class MappedArgumentParser<C,I,O>
- Type Parameters:
C
- sender typeI
- base output typeO
- mapped output type
- All Implemented Interfaces:
ArgumentParser<C,
O>
- Since:
- 1.5.0
-
Field Summary
Fields inherited from interface cloud.commandframework.arguments.parser.ArgumentParser
DEFAULT_ARGUMENT_COUNT
-
Method Summary
Modifier and TypeMethodDescriptionboolean
Get the parser this one is derived from.int
Get the amount of arguments that this parsers seeks to consumeint
hashCode()
boolean
Check whether or not this argument parser is context free.<O1> @NonNull ArgumentParser<C,
O1> map
(BiFunction<CommandContext<C>, O, ArgumentParseResult<O1>> mapper) Create a derived argument parser preserving all properties of this parser, but converting the output type.@NonNull ArgumentParseResult<@NonNull O>
parse
(@NonNull CommandContext<@NonNull C> commandContext, @NonNull Queue<@NonNull String> inputQueue) Parse command input into a command result.suggestions
(@NonNull CommandContext<C> commandContext, @NonNull String input) Get a list of suggested arguments that would be correctly parsed by this parsertoString()
-
Method Details
-
getBaseParser
Get the parser this one is derived from.- Returns:
- the base parser
-
parse
public @NonNull ArgumentParseResult<@NonNull O> parse(@NonNull CommandContext<@NonNull C> commandContext, @NonNull Queue<@NonNull String> inputQueue) Description copied from interface:ArgumentParser
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 (usingCommandManager.suggest(Object, String)
). It is possible to useCommandContext.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
.- Specified by:
parse
in interfaceArgumentParser<C,
I> - Parameters:
commandContext
- Command contextinputQueue
- The queue of arguments- Returns:
- Parsed command result
-
suggestions
public @NonNull List<@NonNull String> suggestions(@NonNull CommandContext<C> commandContext, @NonNull String input) Description copied from interface:ArgumentParser
Get a list of suggested arguments that would be correctly parsed by this parserThis 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
- Specified by:
suggestions
in interfaceArgumentParser<C,
I> - Parameters:
commandContext
- Command contextinput
- Input string- Returns:
- List of suggestions
-
map
public <O1> @NonNull ArgumentParser<C,O1> map(BiFunction<CommandContext<C>, O, ArgumentParseResult<O1>> mapper) Description copied from interface:ArgumentParser
Create a derived argument parser preserving all properties of this parser, but converting the output type.- Specified by:
map
in interfaceArgumentParser<C,
I> - Type Parameters:
O1
- the result type- Parameters:
mapper
- the mapper to apply- Returns:
- a derived parser.
-
isContextFree
public boolean isContextFree()Description copied from interface:ArgumentParser
Check whether or not this argument parser is context free. A context free parser will not use the provided command context, and so supports impromptu parsing- Specified by:
isContextFree
in interfaceArgumentParser<C,
I> - Returns:
true
if the parser is context free, elsefalse
-
getRequestedArgumentCount
public int getRequestedArgumentCount()Description copied from interface:ArgumentParser
Get the amount of arguments that this parsers seeks to consume- Specified by:
getRequestedArgumentCount
in interfaceArgumentParser<C,
I> - Returns:
- The number of arguments tha the parser expects
-
hashCode
public int hashCode() -
equals
-
toString
-