when i try to unload level i get this error message: Code: Fatal error: Call to a member function isChunkLoaded() on null in phar://C:/Users/Honza/Documents/PocketMine-MP/PocketMine-MP.phar/src/pocketmine/level/Level.php on line 2298 Call Stack: 0.0268 383176 1. {main}() C:\Users\Honza\Documents\PocketMine-MP\PocketMine-MP.phar:0 0.0313 377712 2. require_once('phar://C:/Users/Honza/Documents/PocketMine-MP/PocketMine-MP.phar/src/pocketmine/PocketMine.php') C:\Users\Honza\Documents\PocketMine-MP\PocketMine-MP.phar:1 1.1308 517928 3. pocketmine\Server->__construct() phar://C:/Users/Honza/Documents/PocketMine-MP/PocketMine-MP.phar/src/pocketmine/PocketMine.php:464 11.2477 17398216 4. pocketmine\Server->start() phar://C:/Users/Honza/Documents/PocketMine-MP/PocketMine-MP.phar/src/pocketmine/Server.php:1701 11.2622 17414648 5. pocketmine\Server->tickProcessor() phar://C:/Users/Honza/Documents/PocketMine-MP/PocketMine-MP.phar/src/pocketmine/Server.php:2101 249.1311 85046456 6. pocketmine\Server->tick() phar://C:/Users/Honza/Documents/PocketMine-MP/PocketMine-MP.phar/src/pocketmine/Server.php:2223 249.8261 29004856 7. pocketmine\Server->checkTickUpdates() phar://C:/Users/Honza/Documents/PocketMine-MP/PocketMine-MP.phar/src/pocketmine/Server.php:2483 249.8277 29005432 8. pocketmine\level\Level->doTick() phar://C:/Users/Honza/Documents/PocketMine-MP/PocketMine-MP.phar/src/pocketmine/Server.php:2325 249.8278 29005432 9. pocketmine\level\Level->unloadChunks() phar://C:/Users/Honza/Documents/PocketMine-MP/PocketMine-MP.phar/src/pocketmine/level/Level.php:683 249.8278 29005672 10. pocketmine\level\Level->unloadChunk() phar://C:/Users/Honza/Documents/PocketMine-MP/PocketMine-MP.phar/src/pocketmine/level/Level.php:2891 249.8278 29005704 11. pocketmine\level\Level->isChunkLoaded() phar://C:/Users/Honza/Documents/PocketMine-MP/PocketMine-MP.phar/src/pocketmine/level/Level.php:2570
or this error i get Code: Fatal error: Call to a member function getName() on null in phar://C:/Users/Honza/Documents/PocketMine-MP/PocketMine-MP.phar/src/pocketmine/level/Level.php on line 2731 Call Stack: 0.0283 383176 1. {main}() C:\Users\Honza\Documents\PocketMine-MP\PocketMine-MP.phar:0 0.0334 377712 2. require_once('phar://C:/Users/Honza/Documents/PocketMine-MP/PocketMine-MP.phar/src/pocketmine/PocketMine.php') C:\Users\Honza\Documents\PocketMine-MP\PocketMine-MP.phar:1 1.9130 517936 3. pocketmine\Server->__construct() phar://C:/Users/Honza/Documents/PocketMine-MP/PocketMine-MP.phar/src/pocketmine/PocketMine.php:464 10.8533 17359752 4. pocketmine\Server->start() phar://C:/Users/Honza/Documents/PocketMine-MP/PocketMine-MP.phar/src/pocketmine/Server.php:1701 10.8679 17376160 5. pocketmine\Server->tickProcessor() phar://C:/Users/Honza/Documents/PocketMine-MP/PocketMine-MP.phar/src/pocketmine/Server.php:2101 339.5125 81806000 6. pocketmine\Server->tick() phar://C:/Users/Honza/Documents/PocketMine-MP/PocketMine-MP.phar/src/pocketmine/Server.php:2223 339.5126 81806064 7. pocketmine\network\Network->processInterfaces() phar://C:/Users/Honza/Documents/PocketMine-MP/PocketMine-MP.phar/src/pocketmine/Server.php:2471 339.5126 81806064 8. pocketmine\network\RakLibInterface->process() phar://C:/Users/Honza/Documents/PocketMine-MP/PocketMine-MP.phar/src/pocketmine/network/Network.php:150 339.5126 81806096 9. raklib\server\ServerHandler->handlePacket() phar://C:/Users/Honza/Documents/PocketMine-MP/PocketMine-MP.phar/src/pocketmine/network/RakLibInterface.php:79 339.5127 81806400 10. pocketmine\network\RakLibInterface->closeSession() phar://C:/Users/Honza/Documents/PocketMine-MP/PocketMine-MP.phar/src/raklib/server/ServerHandler.php:122 339.5128 81807056 11. pocketmine\Player->close() phar://C:/Users/Honza/Documents/PocketMine-MP/PocketMine-MP.phar/src/pocketmine/network/RakLibInterface.php:100 339.5131 81808248 12. pocketmine\plugin\PluginManager->callEvent() phar://C:/Users/Honza/Documents/PocketMine-MP/PocketMine-MP.phar/src/pocketmine/Player.php:3022 339.5132 81808784 13. pocketmine\plugin\RegisteredListener->callEvent() phar://C:/Users/Honza/Documents/PocketMine-MP/PocketMine-MP.phar/src/pocketmine/plugin/PluginManager.php:673 339.5132 81808784 14. pocketmine\plugin\MethodEventExecutor->execute() phar://C:/Users/Honza/Documents/PocketMine-MP/PocketMine-MP.phar/src/pocketmine/plugin/RegisteredListener.php:96 339.5132 81808992 15. EssentialsPE\EventHandlers\PlayerEvents->onPlayerQuit() phar://C:/Users/Honza/Documents/PocketMine-MP/PocketMine-MP.phar/src/pocketmine/plugin/MethodEventExecutor.php:36 339.5134 81809176 16. EssentialsPE\Loader->removeSession() phar://C:/Users/Honza/Documents/PocketMine-MP/plugins/EssentialsPE.phar/src/EssentialsPE/EventHandlers/PlayerEvents.php:88 339.5135 81809336 17. EssentialsPE\BaseFiles\BaseSession->onClose() phar://C:/Users/Honza/Documents/PocketMine-MP/plugins/EssentialsPE.phar/src/EssentialsPE/Loader.php:862 339.5135 81809400 18. EssentialsPE\BaseFiles\BaseSession->saveSession() phar://C:/Users/Honza/Documents/PocketMine-MP/plugins/EssentialsPE.phar/src/EssentialsPE/BaseFiles/BaseSession.php:94 339.5135 81809768 19. EssentialsPE\BaseFiles\BaseSession->encodeHomes() phar://C:/Users/Honza/Documents/PocketMine-MP/plugins/EssentialsPE.phar/src/EssentialsPE/BaseFiles/BaseSession.php:81 339.5137 81810888 20. pocketmine\level\Level->getName() phar://C:/Users/Honza/Documents/PocketMine-MP/plugins/EssentialsPE.phar/src/EssentialsPE/BaseFiles/BaseSession.php:285 [/PHP]
PHP: loadLevel($name) Needs $name because until you actually load the level you do not have any level object. Once loaded, you should just use the level object.
I also have this problem, getName() on null... Seems that when we unload a level, try to load again, and enter again on this world without stopping this server (in my case), the level becomes null for pocketmine, and the server crashes... It's prety sure a PM bug, because there's absolutelly no problem with my level, it's a PM generated level, and I'm using ManyWorlds as API for unloading/loading worlds due to their stabillity... Well Let's wait to see if this will still happening on PM 1.6, there's anything that we can do :/...
Why? PocketMine itself has API methods on loading levels! Also, do NOT hold the level instance after the level is unloaded.
I know that pocketmine have API methods for that, but when I tryed that: PHP: $level=$this->getServer()->getLevelByName(Main::GAME_LEVEL_1);if(!$this->getServer()->isLevelLoaded($level){ $this->getServer()->loadLevel($level);} and many variants of this code, i got an "getChunk() on null" crash, with ManyWords i won't have this problem, but i get this "getName() on null" instead, but i can't figure out what is the difference between ManyWorlds code and my code, so I use MW as API. Also, i cut off all instances of this level object before unloading the world, and also, This crash won't happens on unloading/loading process, but when player's try to join this world (already loaded) again, so that's not a instance problem...
getLevelByName only works when the level is already loaded. isLevelLoaded and loadLevel both accept strings as parameters.
Well, you're right... Taking a look on my old ugly code I found the problem, the isLoaded check I'm doing on the right way, using the level name directly (trough a constant), but, on the load part, i'm trying to get the name of the level object (that at this point are null), instead of giving a string to the loadLevel.... #facepalm but, looking at the console, everything happens just fine, the unload, and reload part runs without any problem or instant crash, and the console show me "Preparing level Blah" but in theory the world still unloaded due to my mistake, and when a player join the world, the server crashes... PHP: public function loadUnload($name){ if(!$this->getServer()->isLevelLoaded($name)) { $this->getServer()->loadLevel($name); return; }else if($this->getServer()->getLevelByName($name) !== null && $this->getServer()->isLevelLoaded($name)) { $this->getServer()->unloadLevel($this->getServer()->getLevelByName($name)); }} this simply code seems to solve that issue, I haven't tested yet but, calling that using $this->loadUnload("Blah") one time will unload the world called "Blah", and calling again will reload that world...
if getLevelByName doesn't return null, it means that the level is already loaded. Also, it is inefficient to use search functions like getLevelByName multiple times.