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

Deleting and Duplicating Worlds

Comments in 'Plugin Development' started by Calrizer, Jul 16, 2015.

  1. Calrizer
    Offline

    Calrizer Active Member

    Joined:
    Jan 17, 2015
    Posts:
    102
    Minecraft User:
    callumdrain
    That is just a function to extract a world from a ZIP archive and put it in your worlds folder. It could be used as a way of taking the clean worlds out as duplicating is my problem. I'll test it out ASAP, I'm out of town at the moment.
    Legoboy0215 likes this.
  2. PEMapModder
    Offline

    PEMapModder Notable Member Plugin Developer

    Joined:
    Oct 9, 2013
    Posts:
    7,294
    Plugins:
    11
    Minecraft User:
    PEMapModder
    Yes. Though, it is better to use exec
  3. Legoboy0215
    Offline

    Legoboy0215 Notable Member

    Joined:
    Nov 1, 2014
    Posts:
    1,724
    Minecraft User:
    Legoboy0215
    Can I use the extract zip function and put the world zip in my data folder? Then use your function to unload and delete the world. Is it possible?
  4. PEMapModder
    Offline

    PEMapModder Notable Member Plugin Developer

    Joined:
    Oct 9, 2013
    Posts:
    7,294
    Plugins:
    11
    Minecraft User:
    PEMapModder
    Delete before copying :p
  5. Legoboy0215
    Offline

    Legoboy0215 Notable Member

    Joined:
    Nov 1, 2014
    Posts:
    1,724
    Minecraft User:
    Legoboy0215
    K.
  6. Creeperface
    Offline

    Creeperface Notable Member Plugin Developer

    Joined:
    Nov 8, 2014
    Posts:
    1,346
    Plugins:
    4
    Minecraft User:
    CreeperFace
    maybe simpler way is use this code (by mcg76) it copy/delete full folder with all files and subfolders
    PHP:
    public function addWorld($worldname) {
            
    $base $worldname;
            
    $source Server::getInstance ()->getDataPath () . "worlds/bedwars/" $base "/";
            
    $dest Server::getInstance ()->getDataPath () . "worlds/" $worldname."/";       
           
            
    $count 0;
           
            if (
    $this->xcopy $source$dest )) {
                try {
                    
    Server::getInstance ()->loadLevel $worldname );
                } catch ( \
    Exception $e ) {
                }
                
    Server::getInstance ()->loadLevel $worldname );
                
    $level Server::getInstance ()->getLevelByName $worldname );
            }
        }

            public function 
    deleteWorld($worldname) {
            
    $levelpath Server::getInstance ()->getDataPath () . "worlds/" $worldname ."/";
            
    $this->unlinkRecursive $levelpathtrue );
        }
           
            function 
    xcopy($source$dest$permissions 0755) {
            
    // Check for symlinks
            
    if (is_link $source )) {
                return 
    symlink readlink $source ), $dest );
            }
           
            
    // Simple copy for a file
            
    if (is_file $source )) {
                return 
    copy $source$dest );
            }
           
            
    // Make destination directory
            
    if (! is_dir $dest )) {
                
    mkdir $dest$permissions );
            }
           
            
    // Loop through the folder
            
    $dir dir $source );
            while ( 
    false !== $entry $dir->read () ) {
                
    // Skip pointers
                
    if ($entry == '.' || $entry == '..') {
                    continue;
                }
               
                
    // Deep copy directories
                
    $this->xcopy "$source/$entry""$dest/$entry"$permissions );
            }
           
            
    // Clean up
            
    $dir->close ();
            return 
    true;
        }
       
        
    /**
        * Recursively delete a directory
        *
        * @param string $dir
        *           Directory name
        * @param boolean $deleteRootToo
        *           Delete specified top-level directory as well
        */
        
    public function unlinkRecursive($dir$deleteRootToo) {
            if (! 
    $dh = @opendir $dir )) {
                return;
            }
            while ( 
    false !== ($obj readdir $dh )) ) {
                if (
    $obj == '.' || $obj == '..') {
                    continue;
                }
               
                if (! @
    unlink $dir '/' $obj )) {
                    
    $this->unlinkRecursive $dir '/' $objtrue );
                }
            }
           
            
    closedir $dh );
           
            if (
    $deleteRootToo) {
                @
    rmdir $dir );
            }
           
            return;
        }
    Legoboy0215 likes this.

Share This Page

Advertisement