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

Solved Amazing problem with UnLoad

Comments in 'Plugin Development' started by Cristalix, Jul 19, 2016.

  1. Cristalix
    Offline

    Cristalix New Member

    Joined:
    Sep 10, 2015
    Posts:
    38
    Minecraft User:
    Gistrec
    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
    Last edited: Jul 19, 2016
  2. wolfdale
    Offline

    wolfdale Active Member Plugin Developer

    Joined:
    Dec 3, 2014
    Posts:
    276
    Plugins:
    1
    Minecraft User:
    ace
    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)
  3. Cristalix
    Offline

    Cristalix New Member

    Joined:
    Sep 10, 2015
    Posts:
    38
    Minecraft User:
    Gistrec
    YEEEEAAAAA
    YOU ARE THE BEST!!!!!!!!
    ;););););););):rolleyes::rolleyes::rolleyes::rolleyes::rolleyes:
  4. Legoboy0215
    Offline

    Legoboy0215 Notable Member

    Joined:
    Nov 1, 2014
    Posts:
    1,724
    Minecraft User:
    Legoboy0215
    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.
    Cristalix likes this.

Share This Page

Advertisement