Class DeferredRegistry<T>

java.lang.Object
com.github.darksoulq.abyssallib.server.registry.DeferredRegistry<T>
Type Parameters:
T - The type of objects handled by this registry.

public final class DeferredRegistry<T> extends Object
A specialized registry utility that defers object registration until the server is ready. This pattern allows developers to define registry entries in static fields before the underlying Registry is fully initialized. When apply() is called, all queued entries are instantiated and moved into the main registry.
  • Method Details

    • registerModifier

      public static void registerModifier(Supplier<DeferredRegistryModifier> modifierFactory)
      Registers a custom modifier factory to dynamically intercept and handle external registration side effects (e.g., blocks automatically registering item forms).
      Parameters:
      modifierFactory - The supplier providing instances of the custom modifier.
    • create

      public static <T> DeferredRegistry<T> create(Registry<T> registry, String pluginId)
      Factory method to create a new deferred registry instance.
      Type Parameters:
      T - The registry type.
      Parameters:
      registry - The base Registry instance.
      pluginId - The namespace for the objects.
      Returns:
      A new DeferredRegistry instance.
    • register

      public T register(String name, Function<net.kyori.adventure.key.Key, T> supplier)
      Queues an object for registration.
      Parameters:
      name - The unique name (path) within this registry's namespace.
      supplier - A function that creates the object using the generated Key.
      Returns:
      A T registered object.
      Throws:
      IllegalStateException - If the name has already been registered in this deferred registry.
    • apply

      public void apply()
      Finalizes the registration process by moving all deferred entries into the master registry. This method runs all mapped DeferredRegistryModifier rules.
    • getEntries

      public Collection<Holder<T>> getEntries()
      Retrieves an unmodifiable collection of all pending holders in this registry.
      Returns:
      A collection of Holder entries.
    • getPluginId

      public String getPluginId()
      Retrieves the namespace associated with this deferred registry.
      Returns:
      The plugin or mod namespace string.