I been working on a CTF plugin for a while now, and I been testing this queue task that is fired when an arena is queued through a function. Players that join the queued match are added into a queue array. The task foreaches all the player usernames in the queue array and sends a popup to them. They are removed from the array once they leave the server or teleport to the lobby, however when they leave the server, the server crashes, most likely because the task runs before they are removed from the array and it results in the server crashing. I keep on getting call to member function onOnline() on null in crash dumps... Also checking if the foreached player is an instance of a Player doesn't work (I also think that would be a slow method...) Below is the code and I appreciate any help. Thanks! PHP: public function onRun($tick) { $queue = $this->plugin->game[$this->arena]["queue"]; if($queue < 1) { return false; } foreach($queue as $p) { $player = $this->server->getPlayerExact($p); if($player->isOnline()) { if(count($queue) < 2) { $player->sendPopup("§8- §3Waiting for more players to start match."); } else { $player->sendPopup("§8(§c" . count($queue) . "§8/§c12§8)"); } } } }
Tried that, it didn't work. It doesn't send the popup messages if I use I check if it is an instance of player.
I got it to work. Thanks! Here is the updated code. PHP: public function onRun($tick) { $queue = $this->plugin->game[$this->arena]["queue"]; if(count($queue) < 1) { return false; } foreach($queue as $p) { $player = $this->server->getPlayer($p); if($player instanceof Player) { if(count($queue) < 2) { $player->sendPopup("§8- §3Waiting for more players to start match."); } else { $player->sendPopup("§8(§c" . count($queue) . "§8/§c12§8)"); } } } }
It's not an error, he simply was calling Player::isOnline() on a string which just happened to be the player name.
i thought it was Player::isConnected() and why do you need Player::isOnline() ? when they quit it unset them so...?
http://docs.pocketmine.net/df/d2c/classpocketmine_1_1_player.html#a4a7c75b930d02d4f0d499eb5e5e6e7a2 There is..
Oh i see. Theres the difference public function isOnline(){ return $this->connected === true and $this->loggedIn === true; } public function isConnected(){ return $this->connected === true; }