I need help with my plugin, I wanted to find out the count of players from my network because I am using a Proxy and with the function getOnlinePlayers () I can only get the PlayerCount from the current Server.
There are three methods you could use. (Maybe more) 1) Create socket and send UnconnectedPing to target server. Then handle UnconnectedPong... PHP: /** @var UnconnectedPong $pong */$data = explode(";", $pong->serverName);$playerCount = $data[4];$maxPlayerCount = $data[5]; This method works when players are online and too when players are offline. 2) You can use this awesome plugin by @Alemiz. However it depends another plugin on waterdog server 3) I'm using waterdog api on my server. It's quite buggy, but it works. It's used in this plugin And as usual.. you can use queryapi by xpaw.
Try this => https://github.com/xxAROX/NetworkPlayerCount edit waterdog config location and server address.
PHP: function pingServer() { $targetIp = "mc.bedrockplay.eu"; // target server address $targetPort = 19132; // target server port $port = 1212; // random empty port $targetIp = gethostbyname($targetIp); $socket = socket_create(AF_INET, SOCK_DGRAM, SOL_UDP); if(!socket_bind($socket, "0.0.0.0", $port)) { echo "Couldn't bind to 0.0.0.0:$port"; return; } $ping = new \raklib\protocol\UnconnectedPing(); $ping->pingID = rand(100000, 555555); // random long $ping->encode(); socket_sendto($socket, $ping->buffer, strlen($ping->buffer), 0, $targetIp, $targetPort); receivingPong: $pongBuffer = socket_recvfrom($socket, $buffer, 65535, 0, $ip, $port); if($targetIp != $ip || $targetPort != $port) { goto receivingPong; } $pong = new \raklib\protocol\UnconnectedPong($pongBuffer); $pong->decode(); $data = explode(";", $pong->serverName); $playerCount = $data[4]; $maxPlayerCount = $data[5];} I'd recommend to put this in AsyncTask
it's easy to get the number of players just use: PHP: $PlayerCount = sizeof($this->getServer()->getOnlinePlayers());