Skip to main content
This example demonstrates how to create a simple Gate plugin from scratch, including plugin initialization, event handling, and command registration.

Overview

This example creates a plugin that:
  • Welcomes players when they join
  • Adds a /ping command to check player latency
  • Listens to server connection events
  • Shows proper plugin structure and initialization

Complete Example

Project Structure

go.mod

Create a new Go module for your plugin:
go.mod

main.go

main.go

Building and Running

Initialize the module

Build the plugin

Run the plugin

Gate will start with your plugin loaded. You can now:
  • Join the proxy to see the welcome message
  • Use /ping to check your latency
  • Connect to backend servers to see connection messages

Configuration

To configure backend servers, create a config.yml file:
config.yml

Key Concepts

Plugin Registration

Plugins are registered by appending to proxy.Plugins before calling gate.Execute()

Initialization Hook

The Init function is called after the proxy initializes but before it starts accepting connections

Event System

Use event.Subscribe() to listen to proxy events with a priority value (0 is normal)

Command Registration

Commands are registered using Brigadier’s fluent API via proxy.Command().Register()

Next Steps

The context.Context passed to the Init function is canceled when the proxy shuts down. Use it for graceful cleanup!