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

Reloading a reseted world

Comments in 'Plugin Development' started by vertx, Jun 27, 2015.

  1. vertx
    Offline

    vertx Active Member

    Joined:
    Dec 4, 2014
    Posts:
    61
    Minecraft User:
    Vertx
    hey guys,

    I'm developing a SkyWars plugin, and i'm facing a issue when I try to reload a world without shutting down the server, well here is my code that when the game stop, it unload the world, fire a Shell script that make a copy of a previous backup of the SkyWars world to the /worlds folder, and finally load the reseted world:
    PHP:
    //a lot of code
    if(count($this->players)==0)
       {
            
    $this->gameStatus=0;
            
    $this->getServer()->unloadLevel()->getLevelByName("nowhere");
            
    exec(dirname(__FILE__).'/../../.././managers/sw/restore1.sh');//Shell script that restore the world :p
            
    $this->getServer()->loadLevel()->getLevelByName("nowhere");
            
    $this->chestReset();
            
    $this->ClearAllInv();
            return;
       }
    It Works, but when a player try to join in this world again, the server give me this lovely crash:
    Code:
    Error: Call to a member function getChunk() on null
    File: /src/pocketmine/level/Level
    Line: 2418
    Type: E_ERROR
    i'm not the only guy that faced this evil getChunk() on null, @Samueljh1 also, he solved their issue but won't said for us how :p so, anyone know a way to solve this? or maybe a better way for reset a game map after a match? thanks
  2. Guillaume351
    Offline

    Guillaume351 Active Member Plugin Developer

    Joined:
    Oct 11, 2013
    Posts:
    150
    Plugins:
    1
    Minecraft User:
    Guillaume351
    Are you sure the world is named nowhere ? Not the folder, but the world itself. I had issues with that. Open level.dat with NBTexplorer software and look at the world name
  3. vertx
    Offline

    vertx Active Member

    Joined:
    Dec 4, 2014
    Posts:
    61
    Minecraft User:
    Vertx
    Yes, the real world name is "skywars1" "skywars2" etc... and I already had problems with folder names not being the same that the level, so, when I port a world for my server I had to remove the original level.dat and let pocketmine regenerate it by itself,
    its more simple and easier way to solve name issues...
  4. Guillaume351
    Offline

    Guillaume351 Active Member Plugin Developer

    Joined:
    Oct 11, 2013
    Posts:
    150
    Plugins:
    1
    Minecraft User:
    Guillaume351
    I use this :
    PHP:
     public function stopGame($gameNumber){
            
    $worldName "game-".$gameNumber;
            
    $level $this->getServer()->getLevelByName($worldName);

            foreach(
    $this->getServer()->getLevelByName("game-".$gameNumber)->getPlayers() as $p){
                if(isset(
    $p)){
               
    $p->teleport($this->getServer()->getDefaultLevel()->getSpawnLocation());
                }
            }
            
    $this->getServer()->unloadLevel($level);
            
    $this->extractWorld($gameNumber);
            return 
    true;

        }

        public function 
    extractWorld($gameNumber){
            
    $worldName "game-".$gameNumber;
            
    $zip = new \ZipArchive;
                
    $zip->open($this->getServer()->getDataPath()."zipworld/game-".$gameNumber.".zip");
                
    $zip->extractTo($this->getServer()->getDataPath()."worlds/".$worldName."/");
                
    $zip->close();
                
    $this->getServer()->loadLevel($worldName);
                
    $this->getServer()->getLevelByName($worldName)->checkTime();
                
    $this->getServer()->getLevelByName($worldName)->setTime(6000);
                
    $this->getServer()->getLevelByName($worldName)->stopTime();
                
    $this->getServer()->getLevelByName($worldName)->checkTime();
                
    $this->game[$gameNumber."-open"] = true;

        }
    Not the most efficient, but work, I will soon use a method than PeMapModder told me long ago, but unzip works well if you can't find a solution.
    I have all my worlds (game-1.zip, game-2.zip...) in a zipworld folder (PocketMine\zipworld)
  5. Guillaume351
    Offline

    Guillaume351 Active Member Plugin Developer

    Joined:
    Oct 11, 2013
    Posts:
    150
    Plugins:
    1
    Minecraft User:
    Guillaume351
    OOOOh you do not unload/load level well !
    use this :
    PHP:
    $this->getServer()->unloadLevel($this->getServer()->getLevelByName("nowhere"));
    // Not this : $this->getServer()->unloadLevel()->getLevelByName("nowhere");
  6. vertx
    Offline

    vertx Active Member

    Joined:
    Dec 4, 2014
    Posts:
    61
    Minecraft User:
    Vertx
    previously I used this:
    PHP:
    Server::getInstance()->unloadLevel(Server::getInstance()->getLevelByName("world"));//bad pratice
    Same issue... but ok, I'll try out your code, maybe the solution is just unload properly the world... thank you
  7. Legoboy0215
    Offline

    Legoboy0215 Notable Member

    Joined:
    Nov 1, 2014
    Posts:
    1,747
    Minecraft User:
    Legoboy0215
    Server::getInstance() is a bad practice. Use $this->getServer().
  8. Valeron
    Offline

    Valeron New Member

    Joined:
    Aug 26, 2015
    Posts:
    111
    Minecraft User:
    DarkSpive
    What will be return $worldName?

Share This Page

Advertisement