Class ArrayArgumentTypeHandler<S extends CommandSource>
java.lang.Object
studio.mevera.imperat.command.arguments.type.handlers.ArrayArgumentTypeHandler<S>
- Type Parameters:
S- the source type
- All Implemented Interfaces:
ArgumentTypeHandler<S>,Prioritizable
public final class ArrayArgumentTypeHandler<S extends CommandSource>
extends Object
implements ArgumentTypeHandler<S>
Handler for resolving
ArgumentType instances for array types.
This handler supports all array types and provides optimized initializers for primitive wrapper arrays. Custom array initializers can be registered for specific component types.
-
Constructor Summary
ConstructorsConstructorDescriptionCreates a new ArrayArgumentTypeHandler with default initializers. -
Method Summary
Modifier and TypeMethodDescriptionbooleanDetermines if this handler can resolve the given type.@NotNull Priority<T> voidonRegisteringResolver(@NotNull SimpleTypeResolver<S, T> resolver) <T> voidregisterInitializer(@NotNull Class<T> componentType, @NotNull Function<Integer, T[]> initializer) Registers a custom array initializer for a specific component type.<T> @NotNull ArgumentType<S,T> resolve(@NotNull Type type, @NotNull TypeWrap<?> wrap, @NotNull ArgumentTypeLookup<S> lookup) Resolves anArgumentTypefor the given type.
-
Constructor Details
-
ArrayArgumentTypeHandler
public ArrayArgumentTypeHandler()Creates a new ArrayArgumentTypeHandler with default initializers.
-
-
Method Details
-
registerInitializer
public <T> void registerInitializer(@NotNull @NotNull Class<T> componentType, @NotNull @NotNull Function<Integer, T[]> initializer) Registers a custom array initializer for a specific component type.- Type Parameters:
T- the component type- Parameters:
componentType- the component type of the arrayinitializer- the function that creates new arrays of the specified size
-
canHandle
Description copied from interface:ArgumentTypeHandlerDetermines if this handler can resolve the given type.- Specified by:
canHandlein interfaceArgumentTypeHandler<S extends CommandSource>- Parameters:
type- the raw type to checkwrap- the wrapped type for convenience, providing additional type introspection- Returns:
- true if this handler can handle the type
-
resolve
@NotNull public <T> @NotNull ArgumentType<S,T> resolve(@NotNull @NotNull Type type, @NotNull @NotNull TypeWrap<?> wrap, @NotNull @NotNull ArgumentTypeLookup<S> lookup) Description copied from interface:ArgumentTypeHandlerResolves anArgumentTypefor the given type.This method is called only if
ArgumentTypeHandler.canHandle(Type, TypeWrap)returns true. The providedArgumentTypeLookupcan be used to recursively resolve component types for generic types (e.g., the element type of a collection).- Specified by:
resolvein interfaceArgumentTypeHandler<S extends CommandSource>- Type Parameters:
T- the resolved type- Parameters:
type- the type to resolvewrap- the wrapped type for conveniencelookup- the lookup function for resolving nested/component types- Returns:
- the resolved ArgumentType, or null if resolution fails despite canHandle returning true
-
onRegisteringResolver
- Specified by:
onRegisteringResolverin interfaceArgumentTypeHandler<S extends CommandSource>
-
getPriority
- Specified by:
getPriorityin interfacePrioritizable
-