Tooday I rewrite my minigame. And when I Quit, server write Error: Code: [Server thread/CRITICAL]: [Network] Stopped interface pocketmine\network\RakLibInterface due to Call to a member function getName() on null And now I write my code: PHP: public function PlayerQuitEvent(PlayerQuitEvent $event){ $NumRoom = $event->getLevel()->getName(){3}; $name = $event->getPlayer()->getName(); $this->exit($name,$NumRoom); } public function exit($name,$NumRoom){ ///*** $this->CheckRoom($NumRoom); } public function CheckRoom($NumRoom){ //if game not start //if $playerInGame => $PlayerNeedToStart //start game //elseif $playerInGame == 0 $this->UnloadRoom($NumRoom); //end else //end if //end function public function UnloadRoom($NumRoom) $this->getServer()->unloadLevel( $this->getServer()->getLevelByName('TW'.$NumRoom),true ); $this->initRoom($NumRoom); } public function initRoom($NumRoom){ //This I am rewrite array } And after server unload level I have Error... But if I write this PHP: // $this->getServer()->unloadLevel($this->getServer()->getLevelByName('TW'.$NumRoom),true); Server don't write Error
Delay the unload, if not you will unload the level before the player save(when saving, it will fail to save becuz it cant get level the player was at)
I got this exact same problem on my SkyWars minigame. You know when you usually teleport them to spawn first before yoj unload the level? The trick is to add $player->setLevel($spawnWorld) so that you clearly switched the player's level to the spawn world This is much more efficient than a delayed task.