EventRegistration
EventRegistration
Section titled “EventRegistration”Package: com.hypixel.hytale.event
public class EventRegistration<KeyType, EventType extends IBaseEvent<KeyType>> extends RegistrationA typed registration handle for event listeners. Extends Registration with a reference to the event class being listened to. Returned by all registration methods on EventRegistry and IEventRegistry.
Type Parameters
Section titled “Type Parameters”| Parameter | Constraint | Description |
|---|---|---|
KeyType | — | The event’s key type. Void for unkeyed events, or a specific type (e.g., String) for keyed events. |
EventType | extends IBaseEvent<KeyType> | The concrete event class being listened to. |
Fields
Section titled “Fields”@Nonnullprotected final Class<EventType> eventClassThe event class this registration listens to. Set during construction and accessible via getEventClass().
Constructors
Section titled “Constructors”Primary constructor
Section titled “Primary constructor”public EventRegistration(@Nonnull Class<EventType> eventClass, @Nonnull BooleanSupplier isEnabled, @Nonnull Runnable unregister)Creates a new event registration for the given event class.
- eventClass — the event type this registration listens to.
- isEnabled — the owning registry’s enabled state supplier (from Registration).
- unregister — the callback that removes the listener from the
EventBus(from Registration).
Copy constructor
Section titled “Copy constructor”public EventRegistration(@Nonnull EventRegistration<KeyType, EventType> registration, @Nonnull BooleanSupplier isEnabled, @Nonnull Runnable unregister)Creates a new registration that copies the event class from an existing EventRegistration but uses new lifecycle callbacks. Used internally by EventRegistry when wrapping a parent registration in the plugin-scoped lifecycle.
Methods
Section titled “Methods”getEventClass
Section titled “getEventClass”@Nonnullpublic Class<EventType> getEventClass()Returns the event class this registration listens to.
toString
Section titled “toString”@Nonnull@Overridepublic String toString()Returns a string representation including the event class and the inherited registration state.
combine (static)
Section titled “combine (static)”@Nonnull@SafeVarargspublic static <KeyType, EventType extends IBaseEvent<KeyType>> EventRegistration<KeyType, EventType> combine( @Nonnull EventRegistration<KeyType, EventType> thisRegistration, @Nonnull EventRegistration<KeyType, EventType>... containerRegistrations)Creates a composite registration that is enabled only when all of the provided registrations are enabled, and whose unregister() unregisters all of them. This allows grouping multiple event registrations into a single handle.
Behavior:
- isEnabled — returns
trueonly ifthisRegistrationand every element incontainerRegistrationsare enabled. - unregister — calls
unregister()onthisRegistrationand every element incontainerRegistrations.
Example:
EventRegistration<Void, BootEvent> bootReg = events.register(BootEvent.class, e -> { /* ... */ });EventRegistration<Void, ShutdownEvent> shutdownReg = events.register(ShutdownEvent.class, e -> { /* ... */ });
// Combine into a single handleEventRegistration<Void, BootEvent> combined = EventRegistration.combine(bootReg, shutdownReg);
// Unregistering the combined handle unregisters both listenerscombined.unregister();Inherited from Registration
Section titled “Inherited from Registration”This class inherits the following from Registration:
unregister()— removes this listener. Idempotent and shutdown-safe.isRegistered()— returnstrueif not explicitly unregistered and the owning registry is still active.
See Registration — Lifecycle for the full state diagram.
Usage Example
Section titled “Usage Example”@Overrideprotected void setup() { EventRegistry events = getEventRegistry();
// register() returns an EventRegistration handle EventRegistration<Void, BootEvent> reg = events.register(BootEvent.class, event -> { getLogger().info("Server booted!"); });
// Query which event class this registration is for Class<?> eventClass = reg.getEventClass(); getLogger().info("Listening to: " + eventClass.getSimpleName());
// Check if still active if (reg.isRegistered()) { getLogger().info("Listener is active."); }
// Manually unregister (optional -- auto-cleaned on plugin shutdown) reg.unregister();}Related Types
Section titled “Related Types”- Registration — base class providing lifecycle management (
unregister(),isRegistered()) - EventRegistry — plugin-scoped registry whose registration methods return
EventRegistrationhandles - EventPriority — priority enum for listener ordering
- Registry — abstract registry managing registration lifecycle
- PluginBase — provides
getEventRegistry() IEventRegistry— interface defining the registration contractIBaseEvent— base interface for all events- Events Overview — index of all documented events