Advertisement
  1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

unloading level

Comments in 'Plugin Development' started by Creeperface, Aug 16, 2015.

  1. Creeperface
    Offline

    Creeperface Notable Member Plugin Developer

    Joined:
    Nov 8, 2014
    Posts:
    1,346
    Plugins:
    4
    Minecraft User:
    CreeperFace
    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
    
    
  2. Creeperface
    Offline

    Creeperface Notable Member Plugin Developer

    Joined:
    Nov 8, 2014
    Posts:
    1,346
    Plugins:
    4
    Minecraft User:
    CreeperFace
    my code is $level->unload();
  3. Creeperface
    Offline

    Creeperface Notable Member Plugin Developer

    Joined:
    Nov 8, 2014
    Posts:
    1,346
    Plugins:
    4
    Minecraft User:
    CreeperFace
    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]
  4. PEMapModder
    Offline

    PEMapModder Notable Member Plugin Developer

    Joined:
    Oct 9, 2013
    Posts:
    7,294
    Plugins:
    11
    Minecraft User:
    PEMapModder
    Use $server->unloadLevel().
  5. Creeperface
    Offline

    Creeperface Notable Member Plugin Developer

    Joined:
    Nov 8, 2014
    Posts:
    1,346
    Plugins:
    4
    Minecraft User:
    CreeperFace
    I tried too i get error file_put_contents
  6. Legoboy0215
    Offline

    Legoboy0215 Notable Member

    Joined:
    Nov 1, 2014
    Posts:
    1,724
    Minecraft User:
    Legoboy0215
    PHP:
    if($level instanceof Level){
    $this->getServer()->unloadLevel($level->getName());
    }
  7. aliuly
    Offline

    aliuly Notable Member Plugin Developer

    Joined:
    Feb 8, 2014
    Posts:
    1,086
    Plugins:
    17
    You should pass $level not $level->getName()
    Taha_The_Hacker and iksaku like this.
  8. Legoboy0215
    Offline

    Legoboy0215 Notable Member

    Joined:
    Nov 1, 2014
    Posts:
    1,724
    Minecraft User:
    Legoboy0215
    Ok. But I thought loadLeve($name) $name is a string?
  9. aliuly
    Offline

    aliuly Notable Member Plugin Developer

    Joined:
    Feb 8, 2014
    Posts:
    1,086
    Plugins:
    17
    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.
  10. PEMapModder
    Offline

    PEMapModder Notable Member Plugin Developer

    Joined:
    Oct 9, 2013
    Posts:
    7,294
    Plugins:
    11
    Minecraft User:
    PEMapModder
    Check the method declaration. It is unloadLevel($level).
    Legoboy0215 likes this.
  11. Legoboy0215
    Offline

    Legoboy0215 Notable Member

    Joined:
    Nov 1, 2014
    Posts:
    1,724
    Minecraft User:
    Legoboy0215
    Neat!
  12. PEMapModder
    Offline

    PEMapModder Notable Member Plugin Developer

    Joined:
    Oct 9, 2013
    Posts:
    7,294
    Plugins:
    11
    Minecraft User:
    PEMapModder
    Mind using the edit button.
    iksaku likes this.
  13. Legoboy0215
    Offline

    Legoboy0215 Notable Member

    Joined:
    Nov 1, 2014
    Posts:
    1,724
    Minecraft User:
    Legoboy0215
    Sorry. It was my internet lagging...
  14. vertx
    Offline

    vertx Active Member

    Joined:
    Dec 4, 2014
    Posts:
    61
    Minecraft User:
    Vertx
    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 :/...
    Creeperface likes this.
  15. PEMapModder
    Offline

    PEMapModder Notable Member Plugin Developer

    Joined:
    Oct 9, 2013
    Posts:
    7,294
    Plugins:
    11
    Minecraft User:
    PEMapModder
    Why? PocketMine itself has API methods on loading levels!
    Also, do NOT hold the level instance after the level is unloaded.
  16. vertx
    Offline

    vertx Active Member

    Joined:
    Dec 4, 2014
    Posts:
    61
    Minecraft User:
    Vertx
    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...
    Last edited: Aug 18, 2015
  17. PEMapModder
    Offline

    PEMapModder Notable Member Plugin Developer

    Joined:
    Oct 9, 2013
    Posts:
    7,294
    Plugins:
    11
    Minecraft User:
    PEMapModder
    getLevelByName only works when the level is already loaded.
    isLevelLoaded and loadLevel both accept strings as parameters.
  18. vertx
    Offline

    vertx Active Member

    Joined:
    Dec 4, 2014
    Posts:
    61
    Minecraft User:
    Vertx
    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...
    Last edited: Aug 18, 2015
    Kvetinac97 likes this.
  19. PEMapModder
    Offline

    PEMapModder Notable Member Plugin Developer

    Joined:
    Oct 9, 2013
    Posts:
    7,294
    Plugins:
    11
    Minecraft User:
    PEMapModder
    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.

Share This Page

Advertisement