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

[Solved] Reload map for minigame

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

  1. gistrec

    gistrec Witch

    Messages:
    68
    GitHub:
    gistrec
    I have *.tar archive in map/
    I would like to create function, witch will untar map, change level name and load map
    But LevelProviderManager::getProvider don't work :c
    My code:
    PHP:
        // I have map/*.tar where '*' - standart name 
        // And I need to get load map with custom name
        
    public function loadMap($standartMapName$customMapName){
            
    $path $this->getServer()->getDataPath();
            
    exec("tar -xf $path/map/$standartMapName.tar -C $path/worlds");
            
    exec("mv $path/worlds/$standartMapName $path/worlds/$customMapName");
            
    exec("chmod -R 777 $path/worlds/$customMapName/*");
            
    $worldPath "$path/worlds/$customMapName/";
            
    $provider LevelProviderManager::getProvider($worldPath);
            
    $provider->getLevelData()->LevelName = new StringTag("LevelName"$customMapName);
            
    $this->getServer()->loadLevel($customMapName);
            return 
    true;
        }
    Error: Call to a member function getLevelData() on null
     
  2. Thunder33345

    Thunder33345 Moderator Staff Member

    Messages:
    2,137
    GitHub:
    Thunder33345
    make sure provider is not null
     
    gistrec likes this.
  3. gistrec

    gistrec Witch

    Messages:
    68
    GitHub:
    gistrec
    Solve, I change name of world dir and world name in level.dat
    PHP:
        public function loadMap($standartMapName$customMapName){
            
    $path $this->plugin->getServer()->getDataPath();
            
    exec("tar -xf $path/map/$standartMapName.tar -C $path/worlds");
            
    exec("mv $path/worlds/$standartMapName $path/worlds/$customMapName");
            
    exec("chmod -R 777 $path/worlds/$customMapName/*");
            
    $worldPath "$path/worlds/$customMapName/";
            
    $data file_get_contents($worldPath."level.dat");
            
    $nbt = new NBT(NBT::BIG_ENDIAN);
            
    $nbt->readCompressed($data);
            
    $nbt->getData()->Data->LevelName = new StringTag("__name"$customMapName);
            
    $this->plugin->getServer()->loadLevel($customMapName);
        }
     
  4. Bluplayz

    Bluplayz Spider Jockey

    Messages:
    43
    GitHub:
    bluplayz
    I prefer to move the map using only php not linux commands ^^
     
    gistrec likes this.
  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.