Event Architecture
Gate’s event system is built on thegithub.com/robinbraemer/event package, providing a type-safe, high-performance event bus for Go applications.
Key Components
Event Manager
Theevent.Manager is the central component that handles event subscriptions and dispatching. You can access it from the proxy instance:
- Managing event subscriptions
- Dispatching events to registered handlers
- Handling event priorities
- Managing the event lifecycle
Event Types
Gate defines numerous event types inpkg/edition/java/proxy/events.go. Each event is a Go struct that contains relevant data and methods for that specific event. Common event categories include:
- Connection Events:
ConnectionEvent,ConnectionHandshakeEvent - Authentication Events:
PreLoginEvent,LoginEvent,PostLoginEvent - Player Events:
DisconnectEvent,PlayerChatEvent,PlayerSettingsChangedEvent - Server Events:
ServerPreConnectEvent,ServerConnectedEvent,ServerPostConnectEvent - Lifecycle Events:
ReadyEvent,PreShutdownEvent,ShutdownEvent - Plugin Message Events:
PluginMessageEvent,PlayerChannelRegisterEvent
Subscribing to Events
To handle an event, you subscribe a handler function to the event manager usingevent.Subscribe:
Subscription Syntax
Theevent.Subscribe function has the following signature:
- manager: The event manager instance (from
proxy.Event()) - priority: Handler execution order (lower values execute first)
- handler: Your event handler function that receives the event
Event Priorities
Event handlers are executed in order of their priority, from lowest to highest. This allows you to control the execution order when multiple handlers are registered for the same event.- Negative priorities (-100, -50): Early/pre-processing handlers
- Priority 0: Normal/default handlers
- Positive priorities (50, 100): Late/post-processing handlers
Event Cancellation
Many events support cancellation or modification of their behavior. Events typically provide methods to allow, deny, or modify the default action:Modifying Events
Some events allow you to modify data before it’s processed:Fire Events
While most events are fired automatically by Gate, you can also fire custom events or trigger existing event types:Fire method:
- Executes all registered handlers in priority order
- Blocks until all handlers complete
- Passes the event to each handler
Event Handling Best Practices
1. Keep Handlers Fast
Event handlers should execute quickly, especially for high-frequency events likePingEvent:
2. Handle Errors Gracefully
3. Use Type Safety
Gate’s event system is fully type-safe. You always receive the correct event type:4. Check for Nil Values
Some event fields may be nil depending on the context:Next Steps
- Learn about Lifecycle Events
- Explore Player Events
- Discover Server Events
- View all available events in the source code

