Interface Parser<T>
- Type Parameters:
T- The type of object thatparse(StringReader)returns.
- All Known Subinterfaces:
ParserArgument<T>,ParserLiteral
- All Known Implementing Classes:
ParserArgument.WithSuggestions,ParserLiteral.WithSuggestions
- Functional Interface:
- This is a functional interface and can therefore be used as the assignment target for a lambda expression or method reference.
A
FunctionalInterface that reads input from a StringReader and interprets it as an object.
Use parse(StringReader) or listSuggestions(CommandContext, SuggestionsBuilder) to process input.
Parsers can be directly defined by implementing the abstract method getResult(StringReader) method. They may
also be defined with a slightly different interface by implementing ParserArgument.parse(StringReader)
or parse(StringReader). If you are trying to define one of these using a lambda and Java needs
extra hints to infer the lambda signature, you can use one of the following static methods:
-
Method Summary
Modifier and TypeMethodDescriptionstatic <T> ParserArgument<T> argument(ParserArgument<T> parser) Directly returns theParserArgumentgiven.getResult(com.mojang.brigadier.StringReader reader) Parses the given input.default <S> CompletableFuture<com.mojang.brigadier.suggestion.Suggestions> listSuggestions(com.mojang.brigadier.context.CommandContext<S> context, com.mojang.brigadier.suggestion.SuggestionsBuilder builder) Attempts to suggest how the remaining input could be completed or fixed to produce valid input for this parser.default Tparse(com.mojang.brigadier.StringReader reader) Parses the given input and either returns the corresponding object or throws an exception explaining why the input could not be interpreted.static <T> Parser<T> Directly returns theParsergiven.static ParserLiteralread(ParserLiteral reader) Directly returns theParserLiteralgiven.
-
Method Details
-
getResult
-
parse
default T parse(com.mojang.brigadier.StringReader reader) throws com.mojang.brigadier.exceptions.CommandSyntaxException Parses the given input and either returns the corresponding object or throws an exception explaining why the input could not be interpreted.- Parameters:
reader- TheStringReaderthat holds the input to parse.- Returns:
- The object represented by the given input.
- Throws:
com.mojang.brigadier.exceptions.CommandSyntaxException- If the input is malformed.
-
listSuggestions
default <S> CompletableFuture<com.mojang.brigadier.suggestion.Suggestions> listSuggestions(com.mojang.brigadier.context.CommandContext<S> context, com.mojang.brigadier.suggestion.SuggestionsBuilder builder) Attempts to suggest how the remaining input could be completed or fixed to produce valid input for this parser.- Type Parameters:
S- The type of object returned byCommandContext.getSource().- Parameters:
context- TheCommandContextthat holds information about the command that needs suggestions.builder- TheSuggestionsBuilderthat holds the input and position where suggestions should be given.- Returns:
- A
CompletableFuturethat holds the resultingSuggestions.
-
parse
Directly returns theParsergiven. This method can help Java infer the lambda signature of(StringReader) -> Result<T>.- Type Parameters:
T- The type of object thatparse(StringReader)returns.- Parameters:
parser- TheParserlambda.- Returns:
- The
Parserobject.
-
argument
Directly returns theParserArgumentgiven. This method can help Java infer the lambda signature of(StringReader) -> T throws CommandSyntaxException.- Type Parameters:
T- The type of object thatparse(StringReader)returns.- Parameters:
parser- TheParserArgumentlambda.- Returns:
- The
ParserArgumentobject.
-
read
Directly returns theParserLiteralgiven. This method can help Java infer the lambda signature of(StringReader) -> void throws CommandSyntaxException.- Parameters:
reader- TheParserLiterallambda.- Returns:
- The
ParserLiteralobject.
-