1. The forums will be archived and moved to a read only mode in about 2 weeks (mid march).

[Solved] Untar and rename map

Discussion in 'Development' started by gistrec, Jan 29, 2017.

  1. gistrec

    gistrec Witch

    Messages:
    68
    GitHub:
    gistrec
    I would like to untar and rename map:
    I have <server>/map/DarkForest.tar (with level.dat and region/)
    I try to untar map to <server>/worlds/HG1 and load it
    My code:
    PHP:
    // I try loadMap("DarkForest", "HG1");
    public function loadMap($standartMapName$customMapName){
            
    // Server path
            
    $path $this->plugin->getServer()->getDataPath();
            
    // Untar map to worlds
            
    exec("tar -xf $path/map/$standartMapName.tar -C $path/worlds");
            
    // Rename to $customName
            
    exec("mv $path/worlds/$standartMapName $path/worlds/$customMapName");
            
    $worldPath "$path/worlds/$customMapName/";
            
    // Cnange LevelName to $customName in level.dat
            
    $data file_get_contents($worldPath."level.dat");
            
    $nbt = new NBT(NBT::BIG_ENDIAN);
            
    $nbt->readCompressed($data);
            
    $nbt->getData()->Data->LevelName = new StringTag("LevelName"$customMapName);
            
    $this->plugin->getServer()->loadLevel($customMapName);
    }
    And it's load map with name "DarkForest", whyy?)
     
    Last edited: Jan 29, 2017
  2. Muqsit

    Muqsit Chicken

    Messages:
    1,548
    GitHub:
    muqsit
    Because the level name in level.dat is "DarkForest".
     
  3. gistrec

    gistrec Witch

    Messages:
    68
    GitHub:
    gistrec
    No
    PHP:
    object(pocketmine\nbt\NBT)#15733 (4) {
        
    ["buffer"]=>
        
    string(0""
        
    ["offset":"pocketmine\nbt\NBT":private]=>
        
    int(1225)
        [
    "endianness"]=>
        
    int(1)
        [
    "data":"pocketmine\nbt\NBT":private]=>
        
    object(pocketmine\nbt\tag\CompoundTag)#15611 (3) {
            
    ["__name":protected]=>
            
    string(0""
            
    ["value":protected]=>
            array(
    0) {
            }
            [
    "Data"]=>
            
    object(pocketmine\nbt\tag\CompoundTag)#15636 (40) {
                
    ["__name":protected]=>
                
    string(4"Data"
                
    ["value":protected]=>
                array(
    0) {
                }
                ***
                [
    "LevelName"]=>
                
    object(pocketmine\nbt\tag\StringTag)#15587 (2) {
                    
    ["__name":protected]=>
                    
    string(9"LevelName"
                    
    ["value":protected]=>
                    
    string(3"HG1"
                
    }
                ***
            }
        }
    }
    Full var_dump($nbt): http://pastebin.com/iQy19yp2
    UPD: Map copy from minecraft pc.
     
    Last edited: Jan 29, 2017
  4. gistrec

    gistrec Witch

    Messages:
    68
    GitHub:
    gistrec
    Ooops, i miss
    PHP:
    $nbt $nbt->writeCompressed();
    file_put_contents($worldPath."level.dat"$nbt);       
    xD
     
  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.