Class TypeParserRegistry<S>

java.lang.Object
dev.ua.theroer.magicutils.commands.TypeParserRegistry<S>
Type Parameters:
S - sender type

public class TypeParserRegistry<S> extends Object
Registry for managing type parsers that handle both parsing and suggestions.
  • Method Details

    • createWithDefaults

      public static <S> TypeParserRegistry<S> createWithDefaults(CommandLogger logger)
      Factory to register built-in parsers after construction.
      Type Parameters:
      S - sender type
      Parameters:
      logger - command logger
      Returns:
      registry preloaded with default parsers
    • register

      public void register(@NotNull @NotNull TypeParser<S,?> parser)
      Registers a new type parser.
      Parameters:
      parser - the parser to register
    • registerAll

      public void registerAll(@NotNull @NotNull List<TypeParser<S,?>> parsers)
      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 parse
      targetType - the target class type
      sender - 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 parse
      targetType - the target class type
      sender - the command sender for context
      Returns:
      detailed parse result
    • getSuggestionsForType

      @NotNull public @NotNull List<String> getSuggestionsForType(@NotNull @NotNull Class<?> targetType, @NotNull S sender)
      Gets suggestions for a specific type.
      Parameters:
      targetType - the target class type
      sender - the command sender for context
      Returns:
      list of suggestions
    • 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 metadata
      sender - the command sender for context
      Returns:
      list of suggestions
    • parseSuggestion

      @NotNull public @NotNull List<String> parseSuggestion(@NotNull @NotNull String source, @NotNull S sender)
      Parses suggestions from a special source (like @players, {on,off}, etc).
      Parameters:
      source - the suggestion source
      sender - the command sender for context
      Returns:
      list of suggestions
    • 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 source
      currentInput - current user input
      sender - 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 type
      currentInput - current user input
      sender - the command sender for context
      previousParsedArguments - 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 metadata
      currentInput - current user input
      sender - the command sender
      previousParsedArguments - a map of argument names to their parsed values that appeared before this argument.
      Returns:
      filtered list of suggestions
    • isSpecialSuggestion

      public boolean isSpecialSuggestion(@NotNull @NotNull String source)
      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

      public List<TypeParser<S,?>> getParsers()
      Gets all registered parsers.
      Returns:
      an unmodifiable list of parsers
    • findParserForType

      @Nullable public @Nullable TypeParser<S,?> findParserForType(@NotNull @NotNull Class<?> targetType)
      Finds the first parser that can handle the given type.
      Parameters:
      targetType - class to resolve
      Returns:
      parser or null if none match
    • unregister

      public boolean unregister(@NotNull @NotNull TypeParser<S,?> parser)
      Removes a parser from the registry.
      Parameters:
      parser - the parser to remove
      Returns:
      true if the parser was removed
    • unregisterByClass

      public int unregisterByClass(@NotNull @NotNull Class<? extends TypeParser<S,?>> parserClass)
      Removes all parsers of a specific class from the registry.
      Parameters:
      parserClass - the class of parsers to remove
      Returns:
      the number of parsers removed