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

Clone level

Comments in 'Plugin Development' started by Tarik02, Jul 20, 2015.

  1. Tarik02
    Offline

    Tarik02 New Member

    Joined:
    Jun 24, 2015
    Posts:
    26
    Minecraft User:
    Tarik02
    Hello everyone. How to clone(duplicate) level with changing name of level. Sorry for my bad english...
  2. Primus
    Offline

    Primus Notable Member

    Joined:
    Apr 7, 2015
    Posts:
    1,472
    Minecraft User:
    PrimusLV
    Copy level folder and edit level.dat
  3. Kvetinac97
    Offline

    Kvetinac97 Active Member Plugin Developer

    Joined:
    Nov 17, 2014
    Posts:
    276
    Plugins:
    1
    Minecraft User:
    Kvetinac97
    This is method (not my, but I have permission), I use in my BW plugin:
    PHP:
    public function addWorld($worldname){
      
    $base = ($worldname "_base");
        
    $source Server::getInstance()->getDataPath() . "worlds/" $base "/";
      
    $dest Server::getInstance()->getDataPath() . "worlds/" $worldname "/";
     
    $count 0;
     if (
    $this->xcopy($source,$dest)){
      try {
         
    Server::getInstance()->loadLevel($worldname);
        
    $level Server::getInstance()->getLevelByName($worldname);
     }
    }
    function 
    xcopy($source$dest$permissions 0755) {
      if (
    is_link $source )) {
         return 
    symlink readlink $source ), $dest );
      }

     if (
    is_file $source )) {
      return 
    copy $source$dest );
     }
     if (! 
    is_dir $dest )) {
      
    mkdir $dest$permissions );
     }
      
    $dir dir $source );
         while ( 
    false !== $entry $dir->read () ) {
     if (
    $entry == '.' || $entry == '..') {
    continue;
      }
                
    $this->xcopy "$source/$entry""$dest/$entry"$permissions );
    }
     
    $dir->close ();
     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 )) {
                        
    recurse_copy $src '/' $file$dst '/' $file );
    } else {
                        
    copy $src '/' $file$dst '/' $file );
       }
      }
     }
     
    closedir $dir );
    }
    PS: I rewrite a bit this method, so It can be laggy and bad. PS: This copy the level called $worldname."_base" to level $worldname
  4. Tarik02
    Offline

    Tarik02 New Member

    Joined:
    Jun 24, 2015
    Posts:
    26
    Minecraft User:
    Tarik02
    Copy is no-problem. But how to edit level.dat?
  5. Primus
    Offline

    Primus Notable Member

    Joined:
    Apr 7, 2015
    Posts:
    1,472
    Minecraft User:
    PrimusLV
    use ManyWorlds
  6. Tarik02
    Offline

    Tarik02 New Member

    Joined:
    Jun 24, 2015
    Posts:
    26
    Minecraft User:
    Tarik02
    LoL. This is plugin development. "_"
  7. Tarik02
    Offline

    Tarik02 New Member

    Joined:
    Jun 24, 2015
    Posts:
    26
    Minecraft User:
    Tarik02
    WoW, you have own BedWars plugin. I also. Now l do SW plugin. I copy level folder with other function.
  8. Primus
    Offline

    Primus Notable Member

    Joined:
    Apr 7, 2015
    Posts:
    1,472
    Minecraft User:
    PrimusLV
    Did you know ManyWorlds has Github repository you could go and look how aliyuli did that
  9. Tarik02
    Offline

    Tarik02 New Member

    Joined:
    Jun 24, 2015
    Posts:
    26
    Minecraft User:
    Tarik02
    I think, rename source level to name of dest level, copy it, and rename source level to back name.
  10. Tarik02
    Offline

    Tarik02 New Member

    Joined:
    Jun 24, 2015
    Posts:
    26
    Minecraft User:
    Tarik02
    Yes, i know, but ManyWorlds loads levels for name, not folder name \:
  11. vvzar
    Offline

    vvzar New Member

    Joined:
    Mar 21, 2015
    Posts:
    40
    ManyWorlds has function to change name in level.dat from folder name
    Tarik02 likes this.
  12. Tarik02
    Offline

    Tarik02 New Member

    Joined:
    Jun 24, 2015
    Posts:
    26
    Minecraft User:
    Tarik02
    Thank you!
  13. MCPEPIG
    Offline

    MCPEPIG Notable Member

    Joined:
    Jun 22, 2014
    Posts:
    349
    Minecraft User:
    MCPEPIG
    Server::getInstance() is bad practice, use $this->getServer() instead :p
    PEMapModder likes this.
  14. Tarik02
    Offline

    Tarik02 New Member

    Joined:
    Jun 24, 2015
    Posts:
    26
    Minecraft User:
    Tarik02
    I also use this one! :)
  15. PixelGuy75
    Offline

    PixelGuy75 Notable Member Plugin Developer

    Joined:
    Feb 9, 2014
    Posts:
    316
    Plugins:
    2
    Minecraft User:
    PixelGuy75
    Why are you using both then?
  16. Creeperface
    Offline

    Creeperface Notable Member Plugin Developer

    Joined:
    Nov 8, 2014
    Posts:
    1,346
    Plugins:
    4
    Minecraft User:
    CreeperFace
    :p Screenshot_2015-07-20-11-42-25.png Screenshot_2015-07-19-20-19-46.png
  17. Kvetinac97
    Offline

    Kvetinac97 Active Member Plugin Developer

    Joined:
    Nov 17, 2014
    Posts:
    276
    Plugins:
    1
    Minecraft User:
    Kvetinac97
    Yes, I found out Server::getInstance() is bad. Like loads of starting PocketMine developers, I learned something by minecraftgenius. However, now, I don't use any methods of minecraftgenius. Reason: LAGGGGGGGS
  18. Legoboy0215
    Offline

    Legoboy0215 Notable Member

    Joined:
    Nov 1, 2014
    Posts:
    1,747
    Minecraft User:
    Legoboy0215
    Yes, good for you. he has the best ideas and also the laggy and buggy plugins.
    jojoe77777 likes this.
  19. Legoboy0215
    Offline

    Legoboy0215 Notable Member

    Joined:
    Nov 1, 2014
    Posts:
    1,747
    Minecraft User:
    Legoboy0215
    Wow. JoeJo is back from his ban. yay! [Off topic:This post is off topic.]
    Creeperface likes this.
  20. Tarik02
    Offline

    Tarik02 New Member

    Joined:
    Jun 24, 2015
    Posts:
    26
    Minecraft User:
    Tarik02
    I say, I use "$this->getServer()".

Share This Page

Advertisement