Ok, so Im trying to unload a level so the map can be reset in my skywars plugin. I run the function on the server startup (load the level, then unload straight away,) and this works perfectly fine. Here is the code to unload the map: PHP: public static function unloadLevelByName($name, $delete = false){if (!self::$server->isLevelLoaded($name)) { Utils::logToConsole("§cLevel $name is Already Unloaded!"); return true;}$level = self::$server->getLevelByName($name);if ($level === null) { Utils::logToConsole("§cLevel $name is NULL!"); return true;}if (!self::$server->unloadLevel($level, false)) { Utils::logToConsole("§cCouldn't Unload Level $name!");} else { Utils::logToConsole("§aSuccessfully Unloaded Level $name!");}if($delete) { Utils::logToConsole("§cDeleting level $name..."); Utils::deleteDir(MapManager::$worldsFolder . $name);}return true;} Strangely, when running this from my Game Class's end() function, I get this error: Code: Fatal error: Call to a member function getName() on null in phar: [...]src/pocketmine/level/Level__64bit.php on line 2734 Here is the end() function for my game class: PHP: public function end() {$winner = null;foreach($this->getPlayers() as $player) { $winner = $player;}if($winner instanceof GamePlayer) {$winner->addGamesWon();$winner->addCoins(10);$winner->leaveGame();}Server::getInstance()->broadcastMessage("§a§l" . $winner->getName() . " has Won SkyWars on Map: " . $this->map->getDisplayName() . "!");//$map is a custom map class.$this->map->delete();GameManager::restartGame($this->id);} Also the restartGame() call was also ran after in the test, which worked fine. I think there is an issue due to the fact that players have been spawned or chunks have been loaded, although all the players are removed before the delete function is called, with the line PHP: $player->leaveGame(); Any ideas? Thanks!
i think this happens if someplayer has spawnpoint in this level and when he disconnects after level unload
I have this issue when I assign a level object to a variable,say $level. Then I unload the level and load it again. And when I try to do something with $level, it will crash with your error. To fix, after you unload and load the level, you have to update $level with the new level object
it happens when some player has spawnpoint in this level. Look at save() function in player.php there is level->getName() Maybe there are more reasons but if you change player spawnpoint try this