Class TypeParserRegistry<S>
java.lang.Object
dev.ua.theroer.magicutils.commands.TypeParserRegistry<S>
- Type Parameters:
S- sender type
Registry for managing type parsers that handle both parsing and suggestions.
-
Method Summary
Modifier and TypeMethodDescriptionstatic <S> TypeParserRegistry<S> createWithDefaults(CommandLogger logger) Factory to register built-in parsers after construction.@Nullable TypeParser<S, ?> findParserForType(@NotNull Class<?> targetType) Finds the first parser that can handle the given type.List<TypeParser<S, ?>> Gets all registered parsers.getSuggestionsForArgument(@NotNull CommandArgument argument, S sender) Gets suggestions for the provided argument.getSuggestionsForArgumentFiltered(@NotNull CommandArgument argument, @NotNull String currentInput, S sender, @NotNull Map<String, Object> previousParsedArguments) Gets filtered suggestions for the provided argument.getSuggestionsForType(@NotNull Class<?> targetType, S sender) Gets suggestions for a specific type.getSuggestionsForTypeFiltered(@NotNull Class<?> targetType, @NotNull String currentInput, S sender, @NotNull Map<String, Object> previousParsedArguments) Gets filtered suggestions for a specific type.booleanisSpecialSuggestion(@NotNull String source) Checks if a string is a special suggestion source that can be parsed.<T> TParses a value to the specified type using registered parsers.<T> @NotNull TypeParseResult<T> parseDetailed(@Nullable String value, @NotNull Class<T> targetType, S sender) Parses a value to the specified type using registered parsers and returns a detailed outcome.parseSuggestion(@NotNull String source, S sender) Parses suggestions from a special source (like @players, {on,off}, etc).parseSuggestionFiltered(@NotNull String source, @NotNull String currentInput, S sender) Parses suggestions with filtering by current input.voidregister(@NotNull TypeParser<S, ?> parser) Registers a new type parser.voidregisterAll(@NotNull List<TypeParser<S, ?>> parsers) Registers a list of type parsers.booleanunregister(@NotNull TypeParser<S, ?> parser) Removes a parser from the registry.intunregisterByClass(@NotNull Class<? extends TypeParser<S, ?>> parserClass) Removes all parsers of a specific class from the registry.
-
Method Details
-
createWithDefaults
Factory to register built-in parsers after construction.- Type Parameters:
S- sender type- Parameters:
logger- command logger- Returns:
- registry preloaded with default parsers
-
register
Registers a new type parser.- Parameters:
parser- the parser to register
-
registerAll
Registers a list of type parsers.- Parameters:
parsers- the list of parsers to register
-
parse
@Nullable public <T> T parse(@Nullable @Nullable String value, @NotNull @NotNull Class<T> targetType, @NotNull S sender) Parses a value to the specified type using registered parsers.- Type Parameters:
T- the type to parse to- Parameters:
value- the string value to parsetargetType- the target class typesender- the command sender for context- Returns:
- the parsed object or null if no suitable parser found
-
parseDetailed
@NotNull public <T> @NotNull TypeParseResult<T> parseDetailed(@Nullable @Nullable String value, @NotNull @NotNull Class<T> targetType, @NotNull S sender) Parses a value to the specified type using registered parsers and returns a detailed outcome.- Type Parameters:
T- the type to parse to- Parameters:
value- the string value to parsetargetType- the target class typesender- the command sender for context- Returns:
- detailed parse result
-
getSuggestionsForType
-
getSuggestionsForArgument
@NotNull public @NotNull List<String> getSuggestionsForArgument(@NotNull @NotNull CommandArgument argument, @NotNull S sender) Gets suggestions for the provided argument.- Parameters:
argument- the command argument metadatasender- the command sender for context- Returns:
- list of suggestions
-
parseSuggestion
-
parseSuggestionFiltered
@NotNull public @NotNull List<String> parseSuggestionFiltered(@NotNull @NotNull String source, @NotNull @NotNull String currentInput, @NotNull S sender) Parses suggestions with filtering by current input.- Parameters:
source- the suggestion sourcecurrentInput- current user inputsender- the command sender for context- Returns:
- filtered list of suggestions
-
getSuggestionsForTypeFiltered
@NotNull public @NotNull List<String> getSuggestionsForTypeFiltered(@NotNull @NotNull Class<?> targetType, @NotNull @NotNull String currentInput, @NotNull S sender, @NotNull @NotNull Map<String, Object> previousParsedArguments) Gets filtered suggestions for a specific type.- Parameters:
targetType- the target class typecurrentInput- current user inputsender- the command sender for contextpreviousParsedArguments- a map of argument names to their parsed values that appeared before this argument.- Returns:
- filtered list of suggestions
-
getSuggestionsForArgumentFiltered
@NotNull public @NotNull List<String> getSuggestionsForArgumentFiltered(@NotNull @NotNull CommandArgument argument, @NotNull @NotNull String currentInput, @NotNull S sender, @NotNull @NotNull Map<String, Object> previousParsedArguments) Gets filtered suggestions for the provided argument.- Parameters:
argument- the command argument metadatacurrentInput- current user inputsender- the command senderpreviousParsedArguments- a map of argument names to their parsed values that appeared before this argument.- Returns:
- filtered list of suggestions
-
isSpecialSuggestion
Checks if a string is a special suggestion source that can be parsed.- Parameters:
source- the source string- Returns:
- true if any parser can handle this source
-
getParsers
Gets all registered parsers.- Returns:
- an unmodifiable list of parsers
-
findParserForType
Finds the first parser that can handle the given type.- Parameters:
targetType- class to resolve- Returns:
- parser or null if none match
-
unregister
Removes a parser from the registry.- Parameters:
parser- the parser to remove- Returns:
- true if the parser was removed
-
unregisterByClass
Removes all parsers of a specific class from the registry.- Parameters:
parserClass- the class of parsers to remove- Returns:
- the number of parsers removed
-