HI, I'm trying to create a plugin for my pocketmine server that would have a "proxy" server that redirect players to different lobby. but the problem is that I try a lot of technique but I can't do it. PHP: public function onLogin(PlayerLoginEvent $event){ $player = $event->getPlayer(); $json_string = 'http://ced23.alwaysdata.net/'; $jsondata = file_get_contents($json_string); $online1 = json_decode($jsondata,1)['Serveur']; $array = array(19133 => $online1[0],19134 => $online1[1],19135 => $online1[2]); if($array[19133] <= 19){ $player->transfer("127.0.0.1", 19133); }elseif($array[19134] <= 19){ $player->transfer("127.0.0.1", 19134); }}
Code: [09:07:15] [Server thread/INFO]: ced2300[/127.0.0.1:59090] logged out due to transfer [09:07:15] [Server thread/CRITICAL]: Error: "Call to a member function getString() on null" (EXCEPTION) in "src/pocketmine/Player" at line 2086 [09:07:15] [RakLibServer thread/NOTICE]: Blocked 127.0.0.1 for 5 seconds
Maybe it helps to cancel the PlayerLoginEvent when transferring the player otherwhise the server wants to complete the login sequence for a closed player object. Next thing I see is that you want to transfer the player to 127.0.0.1 which would direct him to his own client and not the target server. You need to specify the public IP address or FQDN of the target server.
it works! But it doesn't transfer me I'm just kick! Code: [21:48:35] [Server thread/INFO]: ced2300[/127.0.0.1:54038] logged out due to transfer
Now it works! PHP: public $lobby1; public $lobby2; public $lobby3; public function onEnable() { $this->getLogger()->info("§aStarting Proxy plugin..."); $this->getServer()->getPluginManager()->registerEvents($this, $this); } public function onPreLogin(PlayerPreLoginEvent $event){ $player = $event->getPlayer(); $json_string = 'http://ced23.alwaysdata.net/'; $jsondata = file_get_contents($json_string); $players1 = json_decode($jsondata,1)['Serveur']['19133']; $players2 = json_decode($jsondata,1)['Serveur']['19134']; $players3 = json_decode($jsondata,1)['Serveur']['19135']; $this->lobby1 = $players1; $this->lobby2 = $players2; $this->lobby3 = $players3;}public function onJoin(PlayerJoinEvent $event){ $player = $event->getPlayer(); if($this->lobby1 <= 19 && !($this->lobby1 == "offline")){ $player->transfer("YOUR.SERVER.IP", 19133); $this->getServer()->broadcastMessage($player->getName()." send to Lobby1 with ".$this->lobby1." players"); }elseif($this->lobby2 <= 19 && !($this->lobby2 == "offline")){ $player->transfer("YOUR.SERVER.IP", 19134); $this->getServer()->broadcastMessage($player->getName()." send to Lobby2 with ".$this->lobby2." players"); }elseif($this->lobby3 <= 19 && !($this->lobby3 == "offline")){ $player->transfer("YOUR.SERVER.IP", 19135); $this->getServer()->broadcastMessage($player->getName()." send to Lobby3 with ".$this->lobby3." players");}}
Lol, i have an easier Idea for you just create timer for player (CoolDown) on join event and then after (5) second transfer player to other servers, (use this if you have Auth plugin in your server). or you can just transfer players Random (on Join Event) to other servers easily.
also you can do it easier, just count players in the Lobby#1 in your server and if players in Lobby#1 is >= 15, transfer therm to Lobby#2 and transfer to other servers. if you need help tag me.