Skip to content

Registry

Package: com.hypixel.hytale.registry

public abstract class Registry<T extends Registration>

Abstract base class for all plugin-scoped registries. A Registry manages a collection of Registration objects that are tied to a plugin’s lifecycle. When the plugin shuts down, the registry disables itself and all registrations it contains are automatically cleaned up.

Each registry enforces a precondition (typically that the owning plugin is in an active state) before allowing new registrations. Attempting to register when the precondition is not met throws IllegalStateException.

  • T extends Registration — the type of registration handle managed by this registry.
protected Registry(@Nonnull List<BooleanConsumer> registrations, @Nonnull BooleanSupplier precondition, String preconditionMessage, @Nonnull Registry.RegistrationWrapFunction<T> wrappingFunction)

Constructs a registry with the given parameters:

  • registrations — a shared list of BooleanConsumer callbacks. Each registration appends an enable/disable callback to this list. On shutdown, every callback in this list is invoked with false to disable registrations.
  • precondition — a supplier that returns true when registration is allowed (e.g., the plugin is in SETUP, START, or ENABLED state). Checked on every call to register().
  • preconditionMessage — the error message included in the IllegalStateException if the precondition fails. May be null.
  • wrappingFunction — a function that wraps each registration with lifecycle tracking. See RegistrationWrapFunction.
protected void checkPrecondition()

Checks that the precondition supplier returns true. Throws IllegalStateException with the configured message if not. Called internally by register() and can be called by subclasses that need to enforce the precondition in custom registration methods.

public boolean isEnabled()

Returns true if the registry has not been shut down. After shutdown() is called, this returns false.

public void enable()

Re-enables the registry. Sets the internal enabled flag to true. Purpose unknown — inferred from usage context; no call sites found in the standard plugin lifecycle.

public void shutdown()

Disables the registry by setting the enabled flag to false. After this call, isEnabled() returns false and all wrapped registrations that check the enabled supplier will report themselves as unregistered. This method does not individually unregister each registration — it disables the shared enabled flag that all wrapped registrations reference.

public T register(@Nonnull T registration)

Registers a new item with this registry. The method:

  1. Calls checkPrecondition() to verify registration is allowed.
  2. Wraps the registration using the configured wrappingFunction, passing:
    • The original registration object.
    • The registry’s isEnabled supplier (so the registration knows when the registry shuts down).
    • An unregister callback that is appended to the shared registrations list.
  3. Returns the wrapped registration.

The wrapping step is key to lifecycle management. The wrapped registration combines the original registration’s own enabled state with the registry’s enabled state, so that when either the individual registration is unregistered or the entire registry shuts down, the registration reports itself as no longer active.

@Nonnull
public List<BooleanConsumer> getRegistrations()

Returns the shared list of registration callbacks. Each entry is a BooleanConsumer that accepts true to enable or false to disable the corresponding registration. Used internally during plugin cleanup.

public interface RegistrationWrapFunction<T extends Registration> {
T wrap(T var1, BooleanSupplier var2, Runnable var3);
}

A functional interface for wrapping registrations with lifecycle tracking. Implementations receive:

  • var1 — the original Registration to wrap.
  • var2 — a BooleanSupplier representing the registry’s enabled state.
  • var3 — a Runnable unregister callback to invoke when the registration is removed.

The implementation should return a new registration that delegates to the original but also checks the registry’s enabled state and invokes the unregister callback on cleanup. Each concrete Registration subclass typically provides a constructor matching this pattern (e.g., EventRegistration::new and CommandRegistration::new both serve as RegistrationWrapFunction implementations).

The Registry class participates in the plugin lifecycle as follows:

  1. Plugin constructionPluginBase creates registry instances, passing a shared callback list for shutdown tasks and a precondition that checks the plugin is in an active state (SETUP, START, or ENABLED).

  2. Registration — when a plugin calls a registration method (e.g., getEventRegistry().register(...)), the subclass checks the precondition, delegates to the server-level manager, and calls super.register() to wrap the result.

  3. Manual unregister — calling registration.unregister() on the returned handle removes the shutdown callback and unregisters from the server-level manager.

  4. Plugin shutdownPluginBase.cleanup() calls shutdown() on each registry (setting enabled = false), then iterates the shared shutdown tasks in reverse order (LIFO), invoking each callback to unregister any remaining registrations.

ClassPackagePurpose
EventRegistrycom.hypixel.hytale.eventEvent listener registration
CommandRegistrycom.hypixel.hytale.server.core.command.systemCommand registration
BlockStateRegistrycom.hypixel.hytale.server.core.universe.world.metaBlock state registration
EntityRegistrycom.hypixel.hytale.server.core.modules.entityEntity type registration
TaskRegistrycom.hypixel.hytale.server.core.taskTask scheduling registration
AssetRegistrycom.hypixel.hytale.server.core.registryAsset registration
ClientFeatureRegistrycom.hypixel.hytale.server.core.registryClient feature registration
ComponentRegistryProxycom.hypixel.hytale.server.core.registryECS component registration