Class TypeParserRegistry

java.lang.Object
com.ultikits.ultitools.abstracts.command.parser.TypeParserRegistry

public final class TypeParserRegistry extends Object
Registry for type parsers. Supports custom parser registration and provides built-in parsers. Thread-safe singleton implementation.

Built-in coverage: String (highest priority), the primitive wrapper types and their primitive/array forms (Boolean, Integer, Double, Float, Long, Short, Byte), the core Bukkit types Player, OfflinePlayer, Material, UUID, and the extended Bukkit types World, Location, GameMode, Enchantment. Register additional types with register(TypeParser).

Since:
6.2.0
Version:
2.0.0
Author:
wisdomme
  • Field Details

  • Constructor Details

    • TypeParserRegistry

      private TypeParserRegistry()
  • Method Details

    • getInstance

      public static TypeParserRegistry getInstance()
      Gets the singleton instance of the registry.
      Returns:
      the registry instance
    • register

      public <T> void register(TypeParser<T> parser)
      Registers a type parser.
      Type Parameters:
      T - the type the parser handles
      Parameters:
      parser - the parser to register
    • unregister

      public <T> void unregister(TypeParser<T> parser)
      Unregisters a type parser.
      Type Parameters:
      T - the type the parser handles
      Parameters:
      parser - the parser to unregister
    • getParser

      @Nullable public <T> TypeParser<T> getParser(Class<T> type)
      Gets a parser for the specified type.
      Type Parameters:
      T - the type
      Parameters:
      type - the type to get a parser for
      Returns:
      the parser, or null if none found
    • parse

      public <T> T parse(String value, Class<T> type) throws TypeParseException
      Parses a value to the specified type.
      Type Parameters:
      T - the type
      Parameters:
      value - the string value to parse
      type - the target type
      Returns:
      the parsed value
      Throws:
      TypeParseException - if no parser found or parsing fails
    • parseArray

      public <T> T[] parseArray(String[] values, Class<T> type) throws TypeParseException
      Parses values to an array of the specified type.
      Type Parameters:
      T - the type
      Parameters:
      values - the string values to parse
      type - the target component type
      Returns:
      the parsed array
      Throws:
      TypeParseException - if no parser found or parsing fails
    • hasParser

      public boolean hasParser(Class<?> type)
      Checks if a parser is registered for the specified type.
      Parameters:
      type - the type to check
      Returns:
      true if a parser is registered
    • getAllParsers

      public List<TypeParser<?>> getAllParsers()
      Gets all registered parsers.
      Returns:
      unmodifiable list of parsers
    • registerBuiltInParsers

      private void registerBuiltInParsers()
      Registers all built-in parsers.