Overview
TheEventListener interface enables objects to register and handle events. It provides lifecycle management and integrates with the parent-child hierarchy system.
Package: net.ccbluex.liquidbounce.event
Interface Declaration
Properties
Whether the listener is actively processing events.Handlers only execute when
running is true.Methods
Returns the parent event listener in the hierarchy.Default:
nullUsed to inherit running state from parent.Returns child event listeners.Default:
emptyList()Children are unregistered when parent is unregistered.Unregisters all event handlers and children.This decision is final - handlers cannot be restored.
Creating Event Handlers
handler
once
repeated
until
computedOn
Implementing EventListener
Basic Implementation
With Parent
With Children
With Toggle State
Usage in Modules
AllClientModule instances implement EventListener:
Sequence Handlers
For coroutine-based handlers:Tick Handlers
Simplified tick event handler:Handler Lifecycle
Best Practices
- Store handlers as fields - Prevents garbage collection
- Implement
runningproperly - Controls when handlers execute - Use parent/child hierarchy - Automatic lifecycle management
- Unregister when no longer needed - Frees resources
- Handle errors in handlers - Errors are logged but don’t crash
- Use specific event types - More efficient than generic events
- Consider handler frequency - Some events fire very often
Common Patterns
Conditional Handler
Delayed Initialization
Temporary Handler
Multiple Events
See Also
- EventManager - Event system core
- Event Types - All available events
- ClientModule - Module implementation