Skip to main content
This example demonstrates how to listen to various Gate events to create interactive and responsive proxy behavior.

Overview

This plugin listens to multiple events:
  • PreLoginEvent - Validate and allow/deny player logins
  • PostLoginEvent - Welcome players after successful login
  • ServerPostConnectEvent - Handle server switches
  • DisconnectEvent - Log player disconnections
  • PlayerChatEvent - Filter or modify chat messages
  • KickedFromServerEvent - Handle server kicks gracefully

Complete Example

Project Structure

go.mod

go.mod

main.go

main.go

Building and Running

Event Priority

Events are processed in priority order (highest first):

Common Event Patterns

Allow/Deny Pattern

Many events support allow/deny logic:

Modify and Forward

Some events let you modify data:

Result Pattern

Complex events use result objects:

Available Events

  • ConnectionEvent - Raw connection established
  • ConnectionHandshakeEvent - Handshake completed
  • PreLoginEvent - Before authentication
  • LoginEvent - During login process
  • PostLoginEvent - After successful login
  • DisconnectEvent - Player disconnected
  • PlayerChooseInitialServerEvent - Choose first server
  • ServerPreConnectEvent - Before connecting to server
  • ServerConnectedEvent - Connected to server
  • ServerPostConnectEvent - After server connection
  • KickedFromServerEvent - Kicked from backend server
  • PlayerChatEvent - Chat message sent
  • CommandExecuteEvent - Command executed
  • TabCompleteEvent - Tab completion requested
  • PluginMessageEvent - Plugin message received
  • PingEvent - Server list ping
  • ReadyEvent - Proxy ready to accept connections
  • PreShutdownEvent - Before proxy shutdown
  • ShutdownEvent - Proxy shutting down
  • PlayerSettingsChangedEvent - Player settings updated
  • PlayerModInfoEvent - Forge mod info received
  • GameProfileRequestEvent - Game profile setup
  • PermissionsSetupEvent - Permissions initialized

Best Practices

Non-Blocking

Event handlers should complete quickly. Use goroutines for long operations.

Error Handling

Always handle errors gracefully and provide user feedback.

Priority Order

Use appropriate priorities - only use high priority when necessary.

Nil Checks

Always check for nil values (e.g., PreviousServer, CurrentServer).
Some events like PreLoginEvent block the connection. Keep handlers fast to avoid timeouts!

Next Steps

Use fmt.Printf for debugging during development, but consider using the structured logger from context in production: logr.FromContextOrDiscard(ctx)