Class ArgumentTypeRegistry<S extends CommandSource>
- Type Parameters:
S- the source type
ArgumentType instances, managing type resolution through a chain of handlers.
This registry uses a PriorityList of ArgumentTypeHandlers to resolve types.
Handlers are checked in priority order (highest first), and the first handler that can
handle a type is used to resolve it.
Simple types can be registered directly using registerResolver(Type, Supplier),
which internally creates a SimpleTypeResolver. Complex types like collections,
arrays, and maps are handled by specialized handlers that can be customized.
-
Method Summary
Modifier and TypeMethodDescriptionstatic <S extends CommandSource>
ArgumentTypeRegistry<S>Creates a new default ArgumentTypeRegistry with all built-in handlers registered.<T> Optional<ArgumentType<S,T>> getResolver(@NotNull Type type) Resolves anArgumentTypefor the given type.<C extends Collection<?>>
voidregisterCollectionInitializer(@NotNull Class<C> type, @NotNull Supplier<C> initializerFunction) Registers a custom collection initializer.<T> voidregisterDynamicArrayInitializer(@NotNull Class<T> componentType, @NotNull Function<Integer, T[]> initializerFunction) Registers a custom array initializer using raw/dynamic types.voidregisterHandler(@NotNull ArgumentTypeHandler<S> handler) Registers a customArgumentTypeHandler.<M extends Map<?,?>>
voidregisterMapInitializer(@NotNull Class<M> type, @NotNull Supplier<M> initializerFunction) Registers a custom map initializer.<T> voidregisterResolver(@NotNull Type type, @NotNull Supplier<ArgumentType<S, T>> supplier) Registers a simple type resolver for a specific type.<T> voidregisterResolver(@NotNull Type type, @NotNull Supplier<ArgumentType<S, T>> supplier, @NotNull Priority priority) Registers a simple type resolver for a specific type with a custom priority.
-
Method Details
-
createDefault
Creates a new default ArgumentTypeRegistry with all built-in handlers registered.- Type Parameters:
S- the source type- Returns:
- a new ArgumentTypeRegistry instance
-
registerHandler
Registers a customArgumentTypeHandler.The handler will be added to the priority list and checked during type resolution based on its priority.
- Parameters:
handler- the handler to register
-
registerResolver
public <T> void registerResolver(@NotNull @NotNull Type type, @NotNull @NotNull Supplier<ArgumentType<S, T>> supplier) Registers a simple type resolver for a specific type.This is a convenience method that creates a
SimpleTypeResolverinternally. Use this for non-generic types likeString,UUID, etc.- Type Parameters:
T- the resolved type- Parameters:
type- the type to registersupplier- the supplier that creates ArgumentType instances
-
registerResolver
public <T> void registerResolver(@NotNull @NotNull Type type, @NotNull @NotNull Supplier<ArgumentType<S, T>> supplier, @NotNull @NotNull Priority priority) Registers a simple type resolver for a specific type with a custom priority.- Type Parameters:
T- the resolved type- Parameters:
type- the type to registersupplier- the supplier that creates ArgumentType instancespriority- the priority for this resolver
-
registerCollectionInitializer
public <C extends Collection<?>> void registerCollectionInitializer(@NotNull @NotNull Class<C> type, @NotNull @NotNull Supplier<C> initializerFunction) Registers a custom collection initializer.This is a convenience method that delegates to
CollectionArgumentTypeHandler.- Type Parameters:
C- the collection type- Parameters:
type- the collection typeinitializerFunction- the supplier that creates new collection instances
-
registerDynamicArrayInitializer
public <T> void registerDynamicArrayInitializer(@NotNull @NotNull Class<T> componentType, @NotNull @NotNull Function<Integer, T[]> initializerFunction) Registers a custom array initializer using raw/dynamic types.This variant is useful when the component type is not known at compile time.
- Parameters:
componentType- the array component typeinitializerFunction- the function that creates new arrays of the specified size
-
registerMapInitializer
public <M extends Map<?,?>> void registerMapInitializer(@NotNull @NotNull Class<M> type, @NotNull @NotNull Supplier<M> initializerFunction) Registers a custom map initializer.This is a convenience method that delegates to
MapArgumentTypeHandler.- Type Parameters:
M- the map type- Parameters:
type- the map typeinitializerFunction- the supplier that creates new map instances
-
getResolver
Resolves anArgumentTypefor the given type.This method iterates through all registered handlers in priority order and returns the first successful resolution.
- Type Parameters:
T- the resolved type- Parameters:
type- the type to resolve- Returns:
- an optional containing the ArgumentType if found
-
getArrayHandler
-
getCollectionHandler
-
getMapHandler
-