Interface TypeParser<S,T>
- Type Parameters:
S- sender typeT- the type that this parser handles
- All Known Implementing Classes:
BooleanTypeParser, DiagnosticSuiteNameTypeParser, EnumTypeParser, ListTypeParser, NumberTypeParser, StringTypeParser
public interface TypeParser<S,T>
Unified interface for parsing command arguments and providing suggestions.
Combines functionality of ArgumentTypeParser and SuggestionParser.
-
Method Summary
Modifier and TypeMethodDescriptionbooleanChecks if this parser can handle the given type.default booleancanParseSuggestion(@NotNull String source) Checks if this parser can handle a special suggestion source.default intGets the priority of this parser.getSuggestions(S sender) Gets suggestions for this type.getSuggestions(S sender, @Nullable CommandArgument argument) Gets suggestions for this type with access to the argument metadata.getSuggestions(S sender, @Nullable CommandArgument argument, @NotNull Map<String, Object> previousParsedArguments, @Nullable String currentInput) Gets suggestions for this type with access to the argument metadata and previously parsed arguments.getSuggestionsFiltered(@Nullable String currentInput, S sender, @Nullable CommandArgument argument) Gets filtered suggestions based on current input.default booleanisEqual(S sender, @Nullable Object first, @Nullable Object second, @NotNull CompareMode mode) Compare two values under a given mode (parsers may override).default booleanisSender(S sender, @Nullable Object value, @NotNull CompareMode mode) Check if value refers to the sender (parsers may override).Parses the given value to the target type.default @NotNull TypeParseResult<T> parseDetailed(@Nullable String value, @NotNull Class<T> targetType, S sender) Parses the given value with a detailed outcome.parseSuggestion(@NotNull String source, S sender) Parses a special suggestion source and returns suggestions.
-
Method Details
-
canParse
Checks if this parser can handle the given type.- Parameters:
type- the class type to check- Returns:
- true if this parser can handle the type
-
parse
@Nullable T parse(@Nullable @Nullable String value, @NotNull @NotNull Class<T> targetType, @NotNull S sender) Parses the given value to the target type.- Parameters:
value- the string value to parsetargetType- the target class typesender- the command sender (for context like @sender)- Returns:
- the parsed object or null if parsing failed
-
parseDetailed
@NotNull default @NotNull TypeParseResult<T> parseDetailed(@Nullable @Nullable String value, @NotNull @NotNull Class<T> targetType, @NotNull S sender) Parses the given value with a detailed outcome.This preserves the legacy
parse(String, Class, Object)contract while allowing command binding to distinguish omitted input from invalid user input.- Parameters:
value- the string value to parsetargetType- the target class typesender- the command sender- Returns:
- detailed parse result
-
getSuggestions
-
getSuggestions
@NotNull default @NotNull List<String> getSuggestions(@NotNull S sender, @Nullable @Nullable CommandArgument argument) Gets suggestions for this type with access to the argument metadata.- Parameters:
sender- the command sender for contextargument- the command argument (may be null)- Returns:
- list of suggestions
-
getSuggestions
@NotNull default @NotNull List<String> getSuggestions(@NotNull S sender, @Nullable @Nullable CommandArgument argument, @NotNull @NotNull Map<String, Object> previousParsedArguments, @Nullable @Nullable String currentInput) Gets suggestions for this type with access to the argument metadata and previously parsed arguments.- Parameters:
sender- the command sender for contextargument- the command argument (may be null)previousParsedArguments- a map of argument names to their parsed values that appeared before this argument.currentInput- the current user input for filtering (optional)- Returns:
- list of suggestions
-
getSuggestionsFiltered
@NotNull default @NotNull List<String> getSuggestionsFiltered(@Nullable @Nullable String currentInput, @NotNull S sender, @Nullable @Nullable CommandArgument argument) Gets filtered suggestions based on current input.- Parameters:
currentInput- the current user input for filteringsender- the command sender for contextargument- the command argument for context- Returns:
- filtered list of suggestions
-
canParseSuggestion
Checks if this parser can handle a special suggestion source. This allows parsers to handle special syntax like @players, @worlds, etc.- Parameters:
source- the suggestion source to check- Returns:
- true if this parser can handle the source
-
parseSuggestion
-
isEqual
default boolean isEqual(@NotNull S sender, @Nullable @Nullable Object first, @Nullable @Nullable Object second, @NotNull @NotNull CompareMode mode) Compare two values under a given mode (parsers may override).- Parameters:
sender- command senderfirst- first valuesecond- second valuemode- compare strategy- Returns:
- true if equal under mode
-
isSender
default boolean isSender(@NotNull S sender, @Nullable @Nullable Object value, @NotNull @NotNull CompareMode mode) Check if value refers to the sender (parsers may override).- Parameters:
sender- command sendervalue- candidate valuemode- compare strategy- Returns:
- true if represents sender
-
getPriority
default int getPriority()Gets the priority of this parser. Higher priority parsers are checked first.- Returns:
- the priority value
-