Skip to main content
The server API provides interfaces for representing backend Minecraft servers and managing their registration with the proxy.

Overview

The server API consists of three main components:
  • ServerInfo - Basic server information (name and address)
  • RegisteredServer - A server registered with the proxy
  • ServerConnection - An active player connection to a server
Source: pkg/edition/java/proxy/server.go

ServerInfo

ServerInfo represents basic information about a backend server.

Creating ServerInfo

string
required
The server name (e.g., “lobby”, “survival”).
net.Addr
required
The server network address.

ServerInfo Methods

string
Returns the server name.
net.Addr
Returns the server address.

Comparing ServerInfo

Check if two ServerInfo instances are equal:
ServerInfo
required
First ServerInfo to compare.
ServerInfo
required
Second ServerInfo to compare.
bool
Returns true if both ServerInfo instances have the same name, address string, and network. Always returns false if either is nil.

RegisteredServer

A RegisteredServer represents a backend server that has been registered with the proxy.

Getting RegisteredServer

RegisteredServer Methods

ServerInfo
Returns the server’s information.
Players
Returns the players connected to this server on THIS proxy instance only.

Comparing RegisteredServer

Check if two RegisteredServer instances are equal:
bool
Returns true if both servers have equal ServerInfo. Always returns false if either is nil.

Server Registration

Registering Servers

Register a backend server with the proxy:
ServerInfo
required
The server information to register. Must have a valid name and address.
RegisteredServer
The registered server instance.
error
Returns ErrServerAlreadyExists if a server with the same name is already registered. The existing server is also returned.

Unregistering Servers

Remove a server from the proxy:
ServerInfo
required
The ServerInfo that exactly matches the registered server.
bool
Returns true if the server was found and unregistered.
The ServerInfo must exactly match the registered server’s info (same name and address). Use ServerInfoEqual() to verify.

ServerConnection

ServerConnection represents an active connection from a player to a backend server. Source: pkg/edition/java/proxy/server.go:208

Getting ServerConnection

ServerConnection Methods

RegisteredServer
Returns the server that this connection is connected to.
Player
Returns the player associated with this connection.

Sending Plugin Messages

Send plugin messages to the backend server:
message.ChannelIdentifier
required
The plugin message channel identifier.
[]byte
required
The message data to send.
This sends the message to the backend server, not to the player’s client. To send to the client, use player.SendPluginMessage().

Custom Server Dialer

Implement custom connection logic for servers:
context.Context
required
Context for the dial operation.
Player
required
The player initiating the connection.
net.Conn
The established network connection to the server.

Custom Handshake Address

Customize the server address sent in the handshake packet:
string
The default virtual host from the player’s connection.
Player
required
The player connecting to the server.
string
The modified server address to use in the handshake packet.

Working with Players List

The Players interface provides safe concurrent access to server players:
int
Returns the number of players.
func(func(Player) bool)
Iterates through players. The callback returns false to stop iteration.

Broadcasting Messages

Broadcast plugin messages to all players on a server:

Complete Example

See Also