Skip to main content
The Connection API handles the lifecycle and state management of player connections to backend Minecraft servers.

Overview

Key components:
  • ConnectionRequest - Request to connect a player to a server
  • ConnectionResult - Result of a connection attempt
  • ServerConnection - Active connection between player and server
  • Connection states and lifecycle management
Source: pkg/edition/java/proxy/server.go

Connection Request

A ConnectionRequest represents an intent to connect a player to a backend server.

Creating Connection Requests

RegisteredServer
required
The backend server to connect to.

Executing Connection Requests

Connect the player to the server:
context.Context
required
Context for the connection operation. Use for timeouts and cancellation.
*ConnectionResult
The result of the connection attempt.
error
Error if the connection operation failed. Check the result for more details.

Connection Result

The ConnectionResult contains the outcome of a connection attempt.

Checking Success

bool
Returns true if the connection was successful and the player is now on the server.

Connection Attempt Status

Check if a connection was attempted:
bool
Returns true if a connection to the server was actually attempted (even if it failed).

Getting Connection Reason

Retrieve the component explaining the connection result:
component.Component
Returns the component explaining the result, or nil if no reason is available.

Server Connection

A ServerConnection represents an active connection between a player and a backend server. Source: pkg/edition/java/proxy/server.go:217

Getting Server Connection

Connection Properties

Access connection details:
RegisteredServer
The backend server this connection is connected to.
Player
The player associated with this connection.

Connection State Management

The connection system manages various states during the connection lifecycle.

Connection Phases

Connections go through several phases:
  1. Handshake - Initial connection setup
  2. Login - Authentication with backend server
  3. Play - Active gameplay state
  4. Config - Configuration state (1.20.2+)

Graceful Disconnection

Connections track whether they were gracefully disconnected:

Connection Events

The connection system fires events during the lifecycle:

Server Pre-Connect Event

Called before a connection is attempted:

Server Connected Event

Called when a player successfully connects:

Server Disconnect Event

Called when a player disconnects from a server:

Connection Timeout

Configure connection timeouts using context:

Plugin Messages via Connection

Send plugin messages through the server connection:
message.ChannelIdentifier
required
The plugin message channel.
[]byte
required
The message payload.

Complete Example

See Also