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

Noob Question #2653: Reloading Worlds

Comments in 'Plugin Development' started by Samueljh1, May 21, 2015.

  1. Samueljh1
    Offline

    Samueljh1 Active Member Plugin Developer

    Joined:
    Jan 9, 2015
    Posts:
    316
    Plugins:
    5
    Minecraft User:
    Samueljh1_
    Hi Guys :)

    Title says all!

    But because i feel like it, let me give you a story!

    I got a skywars server, and i need to reload worlds. It keeps crashing with the infamous getChunk() on null error and the isChunkLoaded() on null error.

    I had to modify the pocketmine source to fix this.

    Anyway to reload in pocket mine properly? Also, the function is called in a EntityDamageEvent.

    here is the whole reload function:

    PHP:

    public function restartGame(){

            
    $this->restarting 1;
           
            
    $this->P1 0;

            
    $this->id 1;

            
    $this->RJ = [];

            
    $this->pid = [];

            
    $this->starting 0;

            
    $this->taken = [];

            
    $this->winner "";

            
    $this->Sign1 $this->lobby->getTile(new Vector3(-1329,66,-140));
            
    $this->Sign2 $this->lobby->getTile(new Vector3(-1340,66,-135));

            
    $this->Sign1->setText("§a[Join]","§eSkyWars",$this->mapn,"§e0" "/" $this->maxp " Players");
            
    $this->Sign2->setText("§a[Join]","§eSkyWars",$this->mapn,"§e0" "/" $this->maxp " 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);  Crashes sometimes lolz

            
    foreach(Server::getInstance()->getLevels() as $gl){

                if(
    $gl->getFolderName() == $this->tmn){

                    
    $this->map $gl;

                }

            }
           
            
    $this->restarting 0;
           
            
    $this->reloadSigns();

           
        }


  2. PEMapModder
    Offline

    PEMapModder Notable Member Plugin Developer

    Joined:
    Oct 9, 2013
    Posts:
    7,294
    Plugins:
    11
    Minecraft User:
    PEMapModder
    Avoid using Server::getInstance().
  3. Samueljh1
    Offline

    Samueljh1 Active Member Plugin Developer

    Joined:
    Jan 9, 2015
    Posts:
    316
    Plugins:
    5
    Minecraft User:
    Samueljh1_
    $this->getServer() ?

    And do you think that's the cause?

Share This Page

Advertisement