Class AutoRegisterRegistry

java.lang.Object
de.craftsblock.craftsnet.autoregister.AutoRegisterRegistry

public class AutoRegisterRegistry extends Object
The AutoRegisterRegistry is responsible for managing and invoking AutoRegisterHandler instances based on the provided AutoRegisterInfo. The registry allows registering and unregistering handlers and ensures that the appropriate handlers are invoked when AutoRegister information is processed.

This registry supports handling different classes based on their parent types, invoking handlers that match the parent type of the AutoRegisterInfo. Handlers are registered using a generic approach and are responsible for performing the actual registration logic.

Since:
3.2.0-SNAPSHOT
See Also:
  • Constructor Details

    • AutoRegisterRegistry

      public AutoRegisterRegistry(CraftsNet craftsNet)
      Constructs an AutoRegisterRegistry that will register default handlers.
      Parameters:
      craftsNet - The main CraftsNet instance.
  • Method Details

    • register

      public <T> void register(AutoRegisterHandler<? extends T> handler)
      Registers a custom AutoRegisterHandler. This handler will be used to handle AutoRegisterInfo of the specified type.
      Type Parameters:
      T - The type of handler to register.
      Parameters:
      handler - The handler to register.
    • unregister

      public <T> AutoRegisterHandler<T> unregister(Class<T> type)
      Unregisters an AutoRegisterHandler by its type.
      Type Parameters:
      T - The type of handler.
      Parameters:
      type - The class type of the handler to unregister.
      Returns:
      The unregistered handler, or null if no handler was registered for this type.
    • unregister

      public <T> boolean unregister(AutoRegisterHandler<T> handler)
      Unregisters the specified AutoRegisterHandler.
      Type Parameters:
      T - The type of handler.
      Parameters:
      handler - The handler to unregister.
      Returns:
      true if the handler was unregistered, false if the handler was not found.
    • handleAll

      public void handleAll(List<AutoRegisterInfo> infos, Object... args)
      Handles a list of AutoRegisterInfo by delegating to the appropriate handlers. Each AutoRegisterInfo is passed to the matching handler based on its parent types.
      Parameters:
      infos - The list of AutoRegisterInfo to handle.
      args - The args that should be applied to the AutoRegisterHandler.
    • handle

      public boolean handle(AutoRegisterInfo info, Object... args)
      Handles a single AutoRegisterInfo by invoking the appropriate handler(s) based on its parent types.
      Parameters:
      info - The AutoRegisterInfo to handle.
      args - The args that should be applied to the AutoRegisterHandler.
      Returns:
      true if the AutoRegisterInfo was successfully handled, false otherwise.