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

    • 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. Instead of returning the object directly, this returns a Holder, which allows for lazy initialization and safe cross-referencing during static init.
      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 triggers the instantiation of all Holder objects and handles secondary registration for blocks and items.
    • 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.