Class SimpleTypeResolver<S extends CommandSource,T>

java.lang.Object
studio.mevera.imperat.command.arguments.type.SimpleTypeResolver<S,T>
Type Parameters:
S - the source type
T - the argument type
All Implemented Interfaces:
ArgumentTypeHandler<S>, Prioritizable

public final class SimpleTypeResolver<S extends CommandSource,T> extends Object implements ArgumentTypeHandler<S>
An ArgumentTypeHandler that wraps a simple Supplier for non-generic types.

This handler is used for basic types like String, Boolean, UUID, etc., where the resolution doesn't require any recursive type lookups.

  • Constructor Details

    • SimpleTypeResolver

      public SimpleTypeResolver(@NotNull @NotNull Type targetType, @NotNull @NotNull Supplier<ArgumentType<S,T>> supplier)
      Creates a new SimpleTypeResolver with Priority.HIGH.
      Parameters:
      targetType - the type this resolver handles
      supplier - the supplier that creates ArgumentType instances
    • SimpleTypeResolver

      public SimpleTypeResolver(@NotNull @NotNull Type targetType, @NotNull @NotNull Supplier<ArgumentType<S,T>> supplier, @NotNull @NotNull Priority priority)
      Creates a new SimpleTypeResolver with the specified priority.
      Parameters:
      targetType - the type this resolver handles
      supplier - the supplier that creates ArgumentType instances
      priority - the priority of this resolver
    • SimpleTypeResolver

      public SimpleTypeResolver(@NotNull @NotNull Type targetType, @NotNull @NotNull Supplier<ArgumentType<S,T>> supplier, @NotNull @NotNull Priority priority, boolean matchRelated)
      Creates a new SimpleTypeResolver with full configuration.
      Parameters:
      targetType - the type this resolver handles
      supplier - the supplier that creates ArgumentType instances
      priority - the priority of this resolver
      matchRelated - if true, also matches subtypes of the target type
  • Method Details

    • canHandle

      public boolean canHandle(@NotNull @NotNull Type type, @NotNull @NotNull TypeWrap<?> wrap)
      Description copied from interface: ArgumentTypeHandler
      Determines if this handler can resolve the given type.
      Specified by:
      canHandle in interface ArgumentTypeHandler<S extends CommandSource>
      Parameters:
      type - the raw type to check
      wrap - the wrapped type for convenience, providing additional type introspection
      Returns:
      true if this handler can handle the type
    • resolve

      @Nullable public <R> @Nullable ArgumentType<S,R> resolve(@NotNull @NotNull Type type, @NotNull @NotNull TypeWrap<?> wrap, @NotNull @NotNull ArgumentTypeLookup<S> lookup)
      Description copied from interface: ArgumentTypeHandler
      Resolves an ArgumentType for the given type.

      This method is called only if ArgumentTypeHandler.canHandle(Type, TypeWrap) returns true. The provided ArgumentTypeLookup can be used to recursively resolve component types for generic types (e.g., the element type of a collection).

      Specified by:
      resolve in interface ArgumentTypeHandler<S extends CommandSource>
      Type Parameters:
      R - the resolved type
      Parameters:
      type - the type to resolve
      wrap - the wrapped type for convenience
      lookup - the lookup function for resolving nested/component types
      Returns:
      the resolved ArgumentType, or null if resolution fails despite canHandle returning true
    • getPriority

      @NotNull public @NotNull Priority getPriority()
      Specified by:
      getPriority in interface Prioritizable
    • getTargetType

      public Type getTargetType()
      Returns the target type this resolver handles.
      Returns:
      the target type