Client Setup
A StarGate client connects to the StarGate server and communicates with it. In a Minecraft network the clients are the plugins running on your downstream game servers. StarGate ships with two official client implementations:
- StarGate-Universe — Java clients (currently for Nukkit).
- StarGate-Atlantis — a PHP client for PocketMine-MP (version 3).
Plugin configuration
Both clients use the same configuration file. One plugin can create several clients and connect to several different servers.
# Supports multiple connections
connections:
lobby1:
address: 192.168.0.50
port: 47007
password: 123456789
# Enable the debug logger
debug: true
# Minimum packet log level to print when debugging
logLevel: 0
# Client used when no clientName is given to an API method
defaultClient: "lobby1"
# Start clients automatically once the plugin is enabled
autoStart: true
# Interval (in ticks) at which buffered data is processed and packets decoded.
# Smaller = packets handled faster. Used only by StarGate-Atlantis.
tickInterval: 2- The
connectionsmap defines each client connection. - When
debugis enabled,debugmessages are shown in the console. - Each packet can have its own log level; packets whose level is equal to or higher than
logLevelare logged. - When
autoStartis enabled, all clients start and connect as soon as the plugin is enabled. tickIntervalis the interval, in ticks, between buffer-processing ticks. A smaller value handles packets faster. This option is only used by StarGate-Atlantis.
Session events
ClientCreationEvent— a new StarGate client is created (usually when the StarGate-Universe plugin enables). Use it to adjust theProtocolCodec. If your plugin loads after StarGate-Universe, you will miss this event.ClientConnectedEvent— a new session is created (not yet authenticated).ClientAuthenticatedEvent— a session has authenticated (aServerHandshakePacketwas received). Attach a custom packet handler here.ClientDisconnectedEvent— a session has disconnected or been closed.
Common plugin methods
All client plugins expose these methods:
getClient(String) : StarGateClient— the client matched by name.getDefaultClient() : StarGateClient— the default client from the config.getClientsCopy() : StarGateClient[]— a copy of the current clients; modifying it does not affect the original list. (CalledgetClients()in StarGate-Atlantis.)setLogLevel(int)— change the log level of all clients.getLogLevel() : int— the current log level.transferPlayer(Player, targetServer, clientName)— send aTransferPacketto the StarGate server to transfer a player to another downstream server. IfclientNameisnull, the default client is used. If it matches no client session, the packet is not sent.serverInfo(serverName, selfMode, clientName) : CompletableFuture— request information about another downstream server. IfselfModeistrue, data for the whole proxy is returned. IfclientNamematches no client session, the packet is not sent andnullis returned. The returned future completes when the response is received. (StarGate-Atlantis returns aPacketResponse. Some StarGate server implementations may not support this method.)
StarGate-Universe (Nukkit, Java)
Add the Maven dependency (you will usually want the StarGate common dependency too — see StarGate Modules):
<dependency>
<groupId>alemiz.sgu.nukkit</groupId>
<artifactId>sgu-nukkit</artifactId>
<version>2.1-SNAPSHOT</version>
<scope>provided</scope>
</dependency>Check the StarGate-Universe repository for the current version number, as it is released separately from the main StarGate project. Builds are published to the Waterdog repository.
Also add StarGate-Universe to your plugin.yml depends list.
Access the plugin instance with StarGate.getInstance(). If you disabled autoStart, start the clients yourself:
StarGateUniverse plugin = StarGate.getInstance();
for (StarGateClient client : plugin.getClientsCopy()) {
// You can adjust the ProtocolCodec here
client.start();
}StarGate-Atlantis (PocketMine-MP 3, PHP)
StarGate-Atlantis is the PHP client for PocketMine-MP (version 3 only). To let your IDE index its classes, use the phar from Poggit and include it as a dependency.
Access the plugin instance with StarGateAtlantis::getInstance(). If you disabled autoStart, start the clients yourself:
$plugin = StarGateAtlantis::getInstance();
foreach ($plugin->getClients() as $client) {
// You can adjust the ProtocolCodec here
$client->connect();
}