Class DeferredRegistry<M>

java.lang.Object
org.geysermc.geyser.registry.DeferredRegistry<M>
Type Parameters:
M - the value being held by the registry

public final class DeferredRegistry<M> extends Object
A deferred registry is a registry that is not loaded until it is needed. This is useful for registries that are not needed until after other parts of the lifecycle have been completed.

This class is slightly different from other registries in that it acts as a wrapper around another registry. This is to allow for any kind of registry type to be deferred.

  • Method Details

    • get

      public M get()
      Gets the underlying value held by this registry.
      Returns:
      the underlying value held by this registry
      Throws:
      IllegalStateException - if this deferred registry has not been loaded yet
    • set

      public void set(M mappings)
    • register

      public void register(Consumer<M> consumer)
      Registers what is specified in the given Consumer into the underlying value.
      Parameters:
      consumer - the consumer
      Throws:
      IllegalStateException - if this deferred registry has not been loaded yet
    • load

      public void load()
      Loads the registry.
    • loaded

      public boolean loaded()
      Whether this registry was loaded.
    • create

      public static <I, M> DeferredRegistry<M> create(Function<RegistryLoader<I,M>,Registry<M>> registryLoader, RegistryLoader<I,M> deferredLoader)
      Creates a new deferred registry.
      Type Parameters:
      I - the input type
      M - the registry type
      Parameters:
      registryLoader - the registry loader
      deferredLoader - the deferred loader
      Returns:
      the new deferred registry
    • create

      public static <I, M> DeferredRegistry<M> create(Function<RegistryLoader<I,M>,Registry<M>> registryLoader, Supplier<RegistryLoader<I,M>> deferredLoader)
      Creates a new deferred registry.
      Type Parameters:
      I - the input type
      M - the registry type
      Parameters:
      registryLoader - the registry loader
      deferredLoader - the deferred loader
      Returns:
      the new deferred registry
    • create

      public static <I, M> DeferredRegistry<M> create(I input, org.geysermc.geyser.registry.DeferredRegistry.RegistryInitializer<M> registryInitializer, RegistryLoader<I,M> deferredLoader)
      Creates a new deferred registry.
      Type Parameters:
      I - the input type
      M - the registry type
      Parameters:
      registryInitializer - the registry initializer
      deferredLoader - the deferred loader
      Returns:
      the new deferred registry
    • create

      public static <I, M> DeferredRegistry<M> create(I input, org.geysermc.geyser.registry.DeferredRegistry.RegistryInitializer<M> registryInitializer, Supplier<RegistryLoader<I,M>> deferredLoader)
      Creates a new deferred registry.
      Type Parameters:
      I - the input type
      M - the registry type
      Parameters:
      registryInitializer - the registry initializer
      deferredLoader - the deferred loader
      Returns:
      the new deferred registry