Class TypeParserRegistry
java.lang.Object
com.ultikits.ultitools.abstracts.command.parser.TypeParserRegistry
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
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionprivate static classSimple implementation of TypeParser using a parsing function. -
Field Summary
FieldsModifier and TypeFieldDescriptionprivate static TypeParserRegistryprivate static final Objectprivate final List<TypeParser<?>> private final Map<Class<?>, TypeParser<?>> -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionList<TypeParser<?>> Gets all registered parsers.static TypeParserRegistryGets the singleton instance of the registry.<T> TypeParser<T> Gets a parser for the specified type.booleanChecks if a parser is registered for the specified type.<T> TParses a value to the specified type.<T> T[]parseArray(String[] values, Class<T> type) Parses values to an array of the specified type.<T> voidregister(TypeParser<T> parser) Registers a type parser.private voidRegisters all built-in parsers.<T> voidunregister(TypeParser<T> parser) Unregisters a type parser.
-
Field Details
-
instance
-
LOCK
-
parsers
-
orderedParsers
-
-
Constructor Details
-
TypeParserRegistry
private TypeParserRegistry()
-
-
Method Details
-
getInstance
Gets the singleton instance of the registry.- Returns:
- the registry instance
-
register
Registers a type parser.- Type Parameters:
T- the type the parser handles- Parameters:
parser- the parser to register
-
unregister
Unregisters a type parser.- Type Parameters:
T- the type the parser handles- Parameters:
parser- the parser to unregister
-
getParser
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
Parses a value to the specified type.- Type Parameters:
T- the type- Parameters:
value- the string value to parsetype- the target type- Returns:
- the parsed value
- Throws:
TypeParseException- if no parser found or parsing fails
-
parseArray
Parses values to an array of the specified type.- Type Parameters:
T- the type- Parameters:
values- the string values to parsetype- the target component type- Returns:
- the parsed array
- Throws:
TypeParseException- if no parser found or parsing fails
-
hasParser
Checks if a parser is registered for the specified type.- Parameters:
type- the type to check- Returns:
- true if a parser is registered
-
getAllParsers
Gets all registered parsers.- Returns:
- unmodifiable list of parsers
-
registerBuiltInParsers
private void registerBuiltInParsers()Registers all built-in parsers.
-