Registry
Registry<T extends Registration>
Section titled “Registry<T extends Registration>”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.
Type Parameter
Section titled “Type Parameter”T extends Registration— the type of registration handle managed by this registry.
Constructor
Section titled “Constructor”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
BooleanConsumercallbacks. Each registration appends an enable/disable callback to this list. On shutdown, every callback in this list is invoked withfalseto disable registrations. - precondition — a supplier that returns
truewhen registration is allowed (e.g., the plugin is inSETUP,START, orENABLEDstate). Checked on every call toregister(). - preconditionMessage — the error message included in the
IllegalStateExceptionif the precondition fails. May benull. - wrappingFunction — a function that wraps each registration with lifecycle tracking. See RegistrationWrapFunction.
Methods
Section titled “Methods”checkPrecondition
Section titled “checkPrecondition”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.
isEnabled
Section titled “isEnabled”public boolean isEnabled()Returns true if the registry has not been shut down. After shutdown() is called, this returns false.
enable
Section titled “enable”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.
shutdown
Section titled “shutdown”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.
register
Section titled “register”public T register(@Nonnull T registration)Registers a new item with this registry. The method:
- Calls
checkPrecondition()to verify registration is allowed. - Wraps the registration using the configured
wrappingFunction, passing:- The original registration object.
- The registry’s
isEnabledsupplier (so the registration knows when the registry shuts down). - An unregister callback that is appended to the shared registrations list.
- 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.
getRegistrations
Section titled “getRegistrations”@Nonnullpublic 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.
Inner Interface: RegistrationWrapFunction
Section titled “Inner Interface: RegistrationWrapFunction”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
BooleanSupplierrepresenting the registry’s enabled state. - var3 — a
Runnableunregister 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).
Lifecycle Integration
Section titled “Lifecycle Integration”The Registry class participates in the plugin lifecycle as follows:
-
Plugin construction — PluginBase 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, orENABLED). -
Registration — when a plugin calls a registration method (e.g.,
getEventRegistry().register(...)), the subclass checks the precondition, delegates to the server-level manager, and callssuper.register()to wrap the result. -
Manual unregister — calling
registration.unregister()on the returned handle removes the shutdown callback and unregisters from the server-level manager. -
Plugin shutdown —
PluginBase.cleanup()callsshutdown()on each registry (settingenabled = false), then iterates the shared shutdown tasks in reverse order (LIFO), invoking each callback to unregister any remaining registrations.
Known Subclasses
Section titled “Known Subclasses”| Class | Package | Purpose |
|---|---|---|
| EventRegistry | com.hypixel.hytale.event | Event listener registration |
| CommandRegistry | com.hypixel.hytale.server.core.command.system | Command registration |
BlockStateRegistry | com.hypixel.hytale.server.core.universe.world.meta | Block state registration |
EntityRegistry | com.hypixel.hytale.server.core.modules.entity | Entity type registration |
TaskRegistry | com.hypixel.hytale.server.core.task | Task scheduling registration |
AssetRegistry | com.hypixel.hytale.server.core.registry | Asset registration |
ClientFeatureRegistry | com.hypixel.hytale.server.core.registry | Client feature registration |
ComponentRegistryProxy | com.hypixel.hytale.server.core.registry | ECS component registration |
Related Types
Section titled “Related Types”- Registration — the base handle class managed by this registry
- PluginBase — creates and owns registry instances; calls
shutdown()during cleanup - EventRegistry — concrete subclass for event subscriptions
- CommandRegistry — concrete subclass for commands
- Registry System Overview — architectural overview of the registry system