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

Duplicating worlds

Comments in 'Plugin Development' started by PEMapModder, Feb 8, 2014.

Thread Status:
Not open for further replies.
  1. PEMapModder
    Offline

    PEMapModder Notable Member Plugin Developer

    Joined:
    Oct 9, 2013
    Posts:
    7,294
    Plugins:
    11
    Minecraft User:
    PEMapModder
    What is the fastest way to duplicate a world directory?
  2. PEMapModder
    Offline

    PEMapModder Notable Member Plugin Developer

    Joined:
    Oct 9, 2013
    Posts:
    7,294
    Plugins:
    11
    Minecraft User:
    PEMapModder
    Or can someone just make a plugin or write a code about writing directories to a new directory?
  3. PEMapModder
    Offline

    PEMapModder Notable Member Plugin Developer

    Joined:
    Oct 9, 2013
    Posts:
    7,294
    Plugins:
    11
    Minecraft User:
    PEMapModder
    OK Nvm it is very fast already using this:
    PHP:
    <?php

    /*
    __PocketMine Plugin__
    class=Reproducer
    name=WorldReproducer
    author=PEMapModder
    version=0
    apiversion=11,12
    */

    class PvpMinigame implements Plugin{
        public 
    $s;
        public function 
    __construct(ServerAPI $a,$s=0){
            
    $this->s=ServerAPI::request();
        }
        public function 
    init(){
            
    $s=$this->s;
            
    $s->handle("hub.minigame.register"$this);
            
    $this->reproduceWorld(1);
            
    $this->reproduceWorld(2);
        }
        public function 
    reproduceWorld($id){
            
    console("[DEBUG] Producing PvP temp world $id");
            if(
    $id==and is_dir(PVP_WORLD_TEMP_ONE)){
                return 
    true;
            }
            if(
    $id==and is_dir(PVP_WORLD_TEMP_TWO)){
                return 
    true;
            }
            
    $out=(($id===1)?PVP_WORLD_TEMP_ONE:PVP_WORLD_TEMP_TWO);
            
    mkdir($out);
            
    $in=dir(PVP_ORIGINAL_WORLD);
            
    console("[DEBUG] Copying from ".PVP_ORIGINAL_WORLD." to $out");
            while(
    false!==($file=$in->read())){
                if(
    is_file(PVP_ORIGINAL_WORLD.$file)){
                    
    console("[DEBUG] Copying file from ".PVP_ORIGINAL_WORLD.$file." to $out".$file);
                    
    file_put_contents($out.$filefile_get_contents(PVP_ORIGINAL_WORLD.$file));
                }
            }
            
    $chunksIn=PVP_ORIGINAL_WORLD."chunks/";
            
    $chunksOut=PVP_ORIGINAL_WORLD."chunks/";
            
    $inDir=dir($chunksIn);
            
    mkdir($chunksOut);
            while(
    false!==($chunk=$inDir->read())){
                if(
    is_file($chunksIn.$chunk)){
                    
    console("[DEBUG] Copying chunk from ".$chunksIn.$chunk." to $chunksOut".$chunk);
                    
    file_put_contents($chunksOut.$chunkfile_get_contents($chunksIn.$chunk));
                }
            }
            
    console("[NOTICE] Finished producing temp world $id");
        }
        public function 
    __destruct(){
           
        }
        public function 
    getName(){return "PvP";}
        public function 
    getWorldNames(){return array("pvp_1","pvp_2");}
        public function 
    getMaxPlayers(){return array(100,100);}
        public function 
    getJoinStatus(){
           
        }
        public function 
    getPlayerList(){
           
        }
        public function 
    pmPlayerEvt($evtPlayer $p$data){
           
        }
    }
    And strangely fast (and strangely fast spamming console :p )
  4. Falk
    Offline

    Falk Staff Member Global Moderator

    Joined:
    Sep 2, 2013
    Posts:
    1,706
    Plugins:
    22
    Minecraft User:
    Falkirknh
    Locked. Your issue looks like it has been solved.
    PEMapModder likes this.
Thread Status:
Not open for further replies.

Share This Page

Advertisement