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

WHY? - Loading Levels:

Comments in 'Plugin Development' started by Samueljh1, Apr 8, 2015.

  1. Samueljh1
    Offline

    Samueljh1 Active Member Plugin Developer

    Joined:
    Jan 9, 2015
    Posts:
    316
    Plugins:
    5
    Minecraft User:
    Samueljh1_
    Hi, i keep getting this error for some reason:

    PHP:
    Fatal errorCall to a member function getChunk() on null in phar:///Users/samuel/PluginDevs/PocketMine-MP.phar/src/pocketmine/level/Level.php on line 2039
    The Question is WHY?

    Here is the whole function:

    PHP:
    public function restartGame(){
          
            
    $this->P1 0;
          
            
    $this->id 1;
          
            
    $this->RJ = [];
          
            
    $this->pid = [];
          
            
    $this->starting 0;
                  
            
    $this->winner "";
          
            
    $this->Sign1 $this->lobby->getTile(new Vector3(-10,6,151));
            
    $this->Sign2 $this->Sign1//$this->lobby->getTile(new Vector3(-11,6,151));
          
            
    $this->Sign1->setText("[Join]","******",$this->mapn,"/4 Players");
            
    $this->Sign2->setText("[Join]","*******",$this->mapn,"/4 Players");
          
            
    $this->players = array();
          
            
    $this->started 0;
          
            
    $this->deleteDir(Server::getInstance()->getDataPath() . "worlds/" $this->tmn);
          
            
    $this->cpr(Server::getInstance()->getDataPath() . "worlds/" $this->omn,Server::getInstance()->getDataPath() . "worlds/" $this->tmn);

            
    $this->map Server::getInstance()->getLevelByName($this->tmn);
          
            
    Server::getInstance()->unloadLevel($this->map);
          
            
    Server::getInstance()->loadLevel($this->tmn);
          
            
    $this->map Server::getInstance()->getLevelByName($this->tmn);
          
        }
    I can get this to work in the onEnable() function:

    PHP:
    public function onEnable(){
          
            
    $this->tmn "**Secret :P**";
            
    $this->omn "**Secret :P**";
          
            
    $this->mapn "Map: **** [1]";
            
    $this->gmid "[1]";
          
            
    $this->leaderboard = new Config($this->getDataFolder() . "/leaderboard.yml"Config::YAML);
          
            
    $this->leaderboard->save();
            
    $this->leaderboard->reload();
          
            
    $this->getServer()->getPluginManager()->registerEvents($this$this);

            
    $this->getLogger()->info("§l§c***** Loaded!");
          
            
    Server::getInstance()->loadLevel("*****Lobby");
            
    Server::getInstance()->loadLevel($this->omn);
            
    Server::getInstance()->loadLevel($this->tmn);
                
            
    $this->lobby Server::getInstance()->getLevelByName("*****Lobby");
            
    $this->mapo Server::getInstance()->getLevelByName($this->omn);
          
            
    $this->rn 0;
          
            
    $this->inv = [];
            
    $this->armor = [];
          
            
    $this->spawns = [];
          
            
    $this->id 1;
          
            
    $this->Spawn1 = new Vector3(610.5,29,-819.5);
            
    $this->Spawn2 = new Vector3(570.5,29,-819.5);
            
    $this->Spawn3 = new Vector3(569.5,29,-858.5);
            
    $this->Spawn4 = new Vector3(610.5,29,-859.5);
          
            
    $this->restartGame();
                  
        }
      
        public function 
    restartGame(){
          
            
    $this->P1 0;
          
            
    $this->id 1;
          
            
    $this->RJ = [];
          
            
    $this->pid = [];
          
            
    $this->starting 0;
                  
            
    $this->winner "";
          
            
    $this->Sign1 $this->lobby->getTile(new Vector3(-10,6,151));
            
    $this->Sign2 $this->Sign1//$this->lobby->getTile(new Vector3(-11,6,151));
          
            
    $this->Sign1->setText("[Join]","SkyWars",$this->mapn,"/4 Players");
            
    $this->Sign2->setText("[Join]","SkyWars",$this->mapn,"/4 Players");
          
            
    $this->players = array();
          
            
    $this->started 0;
          
            
    $this->deleteDir(Server::getInstance()->getDataPath() . "worlds/" $this->tmn);
          
            
    $this->cpr(Server::getInstance()->getDataPath() . "worlds/" $this->omn,Server::getInstance()->getDataPath() . "worlds/" $this->tmn);

            
    $this->map Server::getInstance()->getLevelByName($this->tmn);
          
            
    Server::getInstance()->unloadLevel($this->map);
          
            
    Server::getInstance()->loadLevel($this->tmn);
          
            
    $this->map Server::getInstance()->getLevelByName($this->tmn);
          
        }

    BUT, when i run it in a EntityLevelChangeEvent, i get that error.

    Here is the code for that:

    PHP:
        public function onWorldChange(EntityLevelChangeEvent $elce){
          
            
    //$this->getLogger()->info("§cPlayer Moved World");
          
            
    $wce $elce->getEntity();
          
            if(
    $wce instanceof Player && $this->P1 2){$this->restartGame();}
          
        }
    For some reason, this works in a respawn event! (but i can't use that for my situation)

    Thanks in advance! I hope i can get this fixed! :D (also, is it a pocketmine bug? )
  2. EvolSoft
    Offline

    EvolSoft Notable Member Plugin Developer

    Joined:
    Sep 10, 2014
    Posts:
    821
    Plugins:
    15
    Minecraft User:
    Flavius12
    What is the line 2039 in your code?
  3. Samueljh1
    Offline

    Samueljh1 Active Member Plugin Developer

    Joined:
    Jan 9, 2015
    Posts:
    316
    Plugins:
    5
    Minecraft User:
    Samueljh1_
    Nvm, its fixed. And that is in the pocket mine source code (2039)
  4. EvolSoft
    Offline

    EvolSoft Notable Member Plugin Developer

    Joined:
    Sep 10, 2014
    Posts:
    821
    Plugins:
    15
    Minecraft User:
    Flavius12
    Ah ok
  5. PEMapModder
    Offline

    PEMapModder Notable Member Plugin Developer

    Joined:
    Oct 9, 2013
    Posts:
    7,325
    Plugins:
    11
    Minecraft User:
    PEMapModder
    You should enable debug mode and show us the stack trace.
  6. Samueljh1H8sLag
    Offline

    Samueljh1H8sLag Active Member

    Joined:
    Jun 20, 2015
    Posts:
    168
    Minecraft User:
    Samueljh1_
    its happening again. debug is enabled, where can i get the stack trace???

Share This Page

Advertisement