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

restart WORLD

Comments in 'Plugin Development' started by imJayL, Jan 19, 2016.

  1. imJayL
    Offline

    imJayL Active Member

    Joined:
    Aug 5, 2015
    Posts:
    52
    Minecraft User:
    PHC_imJayL
    Can anyone help me? What is the code for this?
  2. Tim // robske Büba
    Offline

    Tim // robske Büba Notable Member

    Joined:
    Feb 26, 2014
    Posts:
    606
    Minecraft User:
    robske_110
    Do you want to RELOAD worlds?
    Simply unload it and then load it again!
  3. imJayL
    Offline

    imJayL Active Member

    Joined:
    Aug 5, 2015
    Posts:
    52
    Minecraft User:
    PHC_imJayL
    No. I need codes -.-
  4. Tim // robske Büba
    Offline

    Tim // robske Büba Notable Member

    Joined:
    Feb 26, 2014
    Posts:
    606
    Minecraft User:
    robske_110
    PHP:
    $this->getLevelByName("lol")->unload();
    $this->getLevelByName("lol")->load();
    Last edited: Jan 19, 2016
  5. PEMapModder
    Offline

    PEMapModder Notable Member Plugin Developer

    Joined:
    Oct 9, 2013
    Posts:
    7,294
    Plugins:
    11
    Minecraft User:
    PEMapModder
    This does not remove the level from the server. This finalizes the level, but only Server::unloadLevel() properly removes the reference from the server to the level.
  6. Tim // robske Büba
    Offline

    Tim // robske Büba Notable Member

    Joined:
    Feb 26, 2014
    Posts:
    606
    Minecraft User:
    robske_110
    But then you can't load it anymore lol
  7. PEMapModder
    Offline

    PEMapModder Notable Member Plugin Developer

    Joined:
    Oct 9, 2013
    Posts:
    7,294
    Plugins:
    11
    Minecraft User:
    PEMapModder
    What?
    One level instance represents once the level gets loaded. If two level references are the same object, the level isn't reloaded.

    Why "can't load it anymore"? If you properly reload something, you are getting it completely fresh, just like it was never loaded before.
    CrazedMiner likes this.
  8. Tim // robske Büba
    Offline

    Tim // robske Büba Notable Member

    Joined:
    Feb 26, 2014
    Posts:
    606
    Minecraft User:
    robske_110
    PHP:
    $this->getLevelByName("lol")->unload();
    $this->getLevelByName("lol")->load();
    That does UNLOAD it and then LOAD it! what's wrong with it?
  9. Tim // robske Büba
    Offline

    Tim // robske Büba Notable Member

    Joined:
    Feb 26, 2014
    Posts:
    606
    Minecraft User:
    robske_110
    LOL Did understand it now
    PHP:
      380  public function unload($force false){
    LevelUnloadEvent($this);
    getName() . "\"");
    getPlayers() as $player){
    Level){
      
    400  $player->teleport($this->server->getDefaultLevel()->getSafeSpawn());
      
    401  }
      
    402  }
      
    403 
      404  
    if($this === $defaultLevel){
      
    405  $this->server->setDefaultLevel(null);
      
    406  }
      
    407 
      408  $this
    ->close();
      
    409 
      410  
    return true;
      
    411  }
    It just kicks the player out of the world!
  10. PEMapModder
    Offline

    PEMapModder Notable Member Plugin Developer

    Joined:
    Oct 9, 2013
    Posts:
    7,294
    Plugins:
    11
    Minecraft User:
    PEMapModder
    They are internal methods used by PocketMine internal implementation to properly free the resources.
    If you unload() then load(), it is indeed a "reload", but that doesn't do the purpose of a reloading, that is to create an entirely new loading of the level.
    Level is not a dummy object used merely for references. It is an actual object that has contents inside it that have to be freed properly.

    Also, unload() calls close(), which frees the level provider, hence the level data. On the other hand, load() tries to load data using the level provider initialized in constructor, but unload() destroyed the level provider.
    unload() and load() are just internal handler-like functions that are called when unloading and loading.
  11. Tim // robske Büba
    Offline

    Tim // robske Büba Notable Member

    Joined:
    Feb 26, 2014
    Posts:
    606
    Minecraft User:
    robske_110
    I still do have to learn much about php and pocketmine
    But how to do it the right way?
  12. wolfdale
    Offline

    wolfdale Active Member Plugin Developer

    Joined:
    Dec 3, 2014
    Posts:
    276
    Plugins:
    1
    Minecraft User:
    ace
    Are you trying to restore a world from a backup or reload(unload and load) a world?
  13. imJayL
    Offline

    imJayL Active Member

    Joined:
    Aug 5, 2015
    Posts:
    52
    Minecraft User:
    PHC_imJayL
    Restore a world .. Like reset floor ..
  14. wolfdale
    Offline

    wolfdale Active Member Plugin Developer

    Joined:
    Dec 3, 2014
    Posts:
    276
    Plugins:
    1
    Minecraft User:
    ace
    PHP:
    public function backupExists($wname){
            return 
    is_file($this->getServer()->getDataPath()."worlds/$wname - Backup/level.dat");
        }

    public function 
    reset($world){
            if(
    $world instanceof Level){
                
    $wname $world->getName();
    if(!
    $this->backupExists($wname)) return false;
                
    $spawn $this->getServer()->getDefaultLevel()->getSafeSpawn();
                foreach(
    $world->getPlayers() as $p){
                    
    $p->teleport($spawn);
                    
    $p->sendMessage(TextFormat::GOLD."- Restoring current world, teleporting you to spawn");
                }
                
    $this->getServer()->unloadLevel($world);
            }
            
    $path $this->getServer()->getDataPath();
            
    $this->recurse_copy($path."worlds/$wname - Backup",$path."worlds/$wname");
    //$this->getServer()->loadLevel($wname); //optionally load level 
            
    return true;
        }


    public function 
    recurse_copy($src,$dst){
            
    $dir opendir($src);
            @
    mkdir($dst);
            while(
    false !== ( $file readdir($dir)) ) {
                if (( 
    $file != '.' ) && ( $file != '..' )) {
                    if ( 
    is_dir($src '/' $file) ) {
                        
    $this->recurse_copy($src '/' $file,$dst '/' $file);
                    }
                    else {
                        
    copy($src '/' $file,$dst '/' $file);
                    }
                }
            }
            
    closedir($dir);
        }
    Last edited: Jan 20, 2016
    Vaivez66 likes this.
  15. imJayL
    Offline

    imJayL Active Member

    Joined:
    Aug 5, 2015
    Posts:
    52
    Minecraft User:
    PHC_imJayL
    Ok thanks.

Share This Page

Advertisement