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

Unload Level Crash

Comments in 'Plugin Development' started by Samueljh1H8sLag, Jan 13, 2016.

  1. Samueljh1H8sLag
    Offline

    Samueljh1H8sLag Active Member

    Joined:
    Jun 20, 2015
    Posts:
    168
    Minecraft User:
    Samueljh1_
    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($levelfalse)) {
      
    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! :)
  2. Creeperface
    Offline

    Creeperface Notable Member Plugin Developer

    Joined:
    Nov 8, 2014
    Posts:
    1,346
    Plugins:
    4
    Minecraft User:
    CreeperFace
    i think this happens if someplayer has spawnpoint in this level and when he disconnects after level unload
  3. wolfdale
    Offline

    wolfdale Active Member Plugin Developer

    Joined:
    Dec 3, 2014
    Posts:
    276
    Plugins:
    1
    Minecraft User:
    ace
    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
    Samueljh1H8sLag likes this.
  4. PEMapModder
    Offline

    PEMapModder Notable Member Plugin Developer

    Joined:
    Oct 9, 2013
    Posts:
    7,294
    Plugins:
    11
    Minecraft User:
    PEMapModder
    Any stack trace?
  5. Creeperface
    Offline

    Creeperface Notable Member Plugin Developer

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

    Legoboy0215 Notable Member

    Joined:
    Nov 1, 2014
    Posts:
    1,724
    Minecraft User:
    Legoboy0215
    I got this too. I took a day to fix it. Use a delayed task and wait a bit before unloading it.
  7. Creeperface
    Offline

    Creeperface Notable Member Plugin Developer

    Joined:
    Nov 8, 2014
    Posts:
    1,346
    Plugins:
    4
    Minecraft User:
    CreeperFace
    You dont have to use delayed task
  8. Samueljh1H8sLag
    Offline

    Samueljh1H8sLag Active Member

    Joined:
    Jun 20, 2015
    Posts:
    168
    Minecraft User:
    Samueljh1_
    nop. didn't show anything.
  9. Samueljh1H8sLag
    Offline

    Samueljh1H8sLag Active Member

    Joined:
    Jun 20, 2015
    Posts:
    168
    Minecraft User:
    Samueljh1_
    good point! :)
  10. Samueljh1H8sLag
    Offline

    Samueljh1H8sLag Active Member

    Joined:
    Jun 20, 2015
    Posts:
    168
    Minecraft User:
    Samueljh1_
    still having issues, tried re-setting the level object and using a delay task. :/
  11. Creeperface
    Offline

    Creeperface Notable Member Plugin Developer

    Joined:
    Nov 8, 2014
    Posts:
    1,346
    Plugins:
    4
    Minecraft User:
    CreeperFace
    Enable debug
  12. AndrewBit
    Offline

    AndrewBit Notable Member

    Joined:
    Jun 18, 2015
    Posts:
    435
    Minecraft User:
    AndrewBit4
    Is winner a instance of Player?

Share This Page

Advertisement