Class ArgumentTypeRegistry<S extends CommandSource>

java.lang.Object
studio.mevera.imperat.context.ArgumentTypeRegistry<S>
Type Parameters:
S - the source type

@Internal public final class ArgumentTypeRegistry<S extends CommandSource> extends Object
Registry for 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 Details

    • createDefault

      public static <S extends CommandSource> ArgumentTypeRegistry<S> createDefault()
      Creates a new default ArgumentTypeRegistry with all built-in handlers registered.
      Type Parameters:
      S - the source type
      Returns:
      a new ArgumentTypeRegistry instance
    • registerHandler

      public void registerHandler(@NotNull @NotNull ArgumentTypeHandler<S> handler)
      Registers a custom ArgumentTypeHandler.

      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 SimpleTypeResolver internally. Use this for non-generic types like String, UUID, etc.

      Type Parameters:
      T - the resolved type
      Parameters:
      type - the type to register
      supplier - 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 register
      supplier - the supplier that creates ArgumentType instances
      priority - 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 type
      initializerFunction - 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 type
      initializerFunction - 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 type
      initializerFunction - the supplier that creates new map instances
    • getResolver

      public <T> Optional<ArgumentType<S,T>> getResolver(@NotNull @NotNull Type type)
      Resolves an ArgumentType for 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

      public ArrayArgumentTypeHandler<S> getArrayHandler()
    • getCollectionHandler

      public CollectionArgumentTypeHandler<S> getCollectionHandler()
    • getMapHandler

      public MapArgumentTypeHandler<S> getMapHandler()