Skip to content

Proxy networks 5.46.0 ​

When a server runs behind VanillaGate, plugins can see the whole network, move players between servers and send messages to plugins on other servers.

php
use pocketmine\network\proxy\ProxyNetwork;

$net = $this->getServer()->getProxyNetwork(); // null when the server is not behind a proxy

API: Server::getProxyNetwork(), ProxyNetwork, PlayerProxyTransferEvent, ProxyMessageReceiveEvent.

The network ​

The proxy pushes the state of the other servers about once a second, so these values can be slightly old.

MethodReturns
isConnected()Whether the proxy link is up right now.
getServerName()This server's name in the proxy.
getServers() / getGroups()Names of all servers / groups.
isServerOnline($server)Whether that server is linked.
isNetworkTarget($name)Whether a name is a server or group.
getGlobalPlayerCount()Players on the whole network.
getServerPlayerCount($server)Players on one server.
getOnlinePlayers()Player name → server name ("" while changing server).
findPlayer($name)Server of a player (case-insensitive), or null.

Moving players ​

php
// One of this server's players. Style: STYLE_DIMENSION, STYLE_SEAMLESS, STYLE_CINEMATIC, or "" for the proxy default.
$net->transfer($player, "survival", ProxyNetwork::STYLE_SEAMLESS);

// To the lobby (the proxy's fallback groups)
$net->transfer($player, ProxyNetwork::TARGET_HUB);

// Any player of the network, or everyone with "*"
$net->sendPlayer("Steve", "minigames");

transfer() returns false when the move was cancelled or the player did not come through the proxy. Player::transfer() with the name of a network server does the same thing.

Stopping or redirecting a move ​

PlayerProxyTransferEvent fires before a move requested on this server (/server, /hub, transfer()), and when a move requested elsewhere (/send, another server, the admin API) is about to take the player.

php
use pocketmine\event\player\PlayerProxyTransferEvent;

public function onTransfer(PlayerProxyTransferEvent $event) : void{
	if($this->isInCombat($event->getPlayer())){
		$event->cancel();
		$event->getPlayer()->sendMessage("You cannot leave during combat.");
	}
}

setTarget() and setStyle() change a local move; for moves requested elsewhere setTarget() has no effect. The event does not fire when the server stops and its players are sent to the lobby.

Messages between servers ​

php
// To every other server (or pass a server name as the third argument)
$net->sendMessage("myplugin:sync", json_encode(["balance" => 10]));
php
use pocketmine\event\server\ProxyMessageReceiveEvent;

public function onMessage(ProxyMessageReceiveEvent $event) : void{
	if($event->getChannel() === "myplugin:sync"){
		$data = json_decode($event->getData(), true);
		// $event->getSourceServer() is the sender
	}
}

Use a channel name with your plugin's name as prefix. broadcastAlert($message) shows a message on every server.

VanillaMine is a fork of PocketMine-MP, maintained by Luxury Nodes. Not affiliated with the PMMP team or Mojang.