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

Solved Help! Undefined property

Discussion in 'Development' started by A354-PH, Feb 13, 2019.

  1. A354-PH

    A354-PH Baby Zombie

    Messages:
    186
    GitHub:
    Kizu
    Code:
    PHP:
    <?php

    namespace bridge\utils;

    use 
    ZipArchive;
    use 
    pocketmine\utils\Config;
    use 
    pocketmine\level\Level;
    use 
    pocketmine\nbt\NBT;
    use 
    pocketmine\nbt\tag\{CompoundTagStringTag};
    use 
    pocketmine\level\generator\Generator;
    use 
    pocketmine\utils\TextFormat;
    use 
    pocketmine\Server;
    use 
    bridge\Main;

    class 
    Utils{
        
        private 
    $plugin;
        
        public function 
    __construct(Main $plugin){
            
    $this->plugin $plugin;
        }
        
        public function 
    getPlugin(){
            return 
    $this->plugin;
        }
        
        public function 
    getServer(){
            return 
    $this->plugin->getServer();
        }
        
        public function 
    backupMap($world$src){
            
    $path $this->getServer()->getDataPath();
            
    $zip = new ZipArchive;
            
    $zip->open($src "mapas/$world.zip"ZipArchive::CREATE);
            
    $files = new \RecursiveIteratorIterator(new \RecursiveDirectoryIterator($path."worlds/$world")); //line 35
            
    foreach($files as $file){
                if(
    is_file($file)){
                    
    $zip->addFile($filestr_replace("\\""/"ltrim(substr($filestrlen($path."worlds/$world")), "/\\")));
                }
            }
            
    $zip->close();
            return 
    true;
        }
        
        public function 
    renameMap($old$new){
            if(!
    is_dir($old_dir $this->getPlugin()->getServer()->getDataPath()."worlds/$old")){
                return 
    false;
            }
            if(
    is_dir($new_dir $this->getPlugin()->getServer()->getDataPath()."worlds/$new")){
                return 
    false;
            }
            if(
    $this->getPlugin()->getServer()->getLevelByName($old) !== null){
                
    $players $this->getPlugin()->getServer()->getLevelByName($old)->getPlayers();
                if(
    $old === $this->getPlugin()->getServer()->getDefaultLevel()->getName() and count($players) > 0){
                    return 
    false;
                }
                foreach(
    $players as $player){
                    
    $player->teleport($this->getPlugin()->getServer()->getDefaultLevel()->getSafeSpawn());
                }
            }
            
    rename($old_dir$new_dir);
            
    $nbt = new NBT(NBT::BIG_ENDIAN);
            
    $nbt->readCompressed(file_get_contents($new_dir."/level.dat"));
            
    $data $nbt->getData();
            
    $leveldata "";
            if(
    $data->Data instanceof CompoundTag){
                
    $leveldata $data->Data;
            }
            
    $leveldata["LevelName"] = $new;
            
    $nbt->setData(new CompoundTag("", ["Data" => $leveldata]));
            
    $buffer $nbt->writeCompressed();
            
    file_put_contents($new_dir."/level.dat"$buffer);
            
    $this->loadMap($new);
            if(
    $old === $this->getPlugin()->getServer()->getDefaultLevel()->getName()){
                
    $this->getPlugin()->getServer()->setDefaultLevel($this->getPlugin()->getServer()->getLevelByName($new));
                
    $config = new Config($this->getPlugin()->getServer()->getDataPath()."server.properties"Config::PROPERTIES);
                
    $config->set("level-name"$new);
                
    $config->save();
            }
            return 
    true;
        }
        
        public function 
    backupExists($world){
            return 
    file_exists($this->getPlugin()->getDataFolder()."mapas/$world.zip");
        }
        
        public function 
    resetMap($world){
            if(!
    is_dir($directory $this->getPlugin()->getServer()->getDataPath()."worlds/$world")){
                @
    mkdir($directory);
            }
            if(
    $this->getPlugin()->getServer()->getLevelByName($world) !== null){
                
    $players $this->getPlugin()->getServer()->getLevelByName($world)->getPlayers();
                if(
    $world !== $this->getPlugin()->getServer()->getDefaultLevel()->getName()){
                    foreach(
    $players as $player){
                        
    $player->teleport($this->getPlugin()->getServer()->getDefaultLevel()->getSafeSpawn());
                    }
                    
    $this->unloadMap($world);
                }
            }
            
    $zip = new ZipArchive;
            if(
    $zip->open($this->getPlugin()->getDataFolder()."mapas/$world.zip") === true){
                
    $zip->extractTo($directory);
            }
            
    $zip->close();
            
    $this->loadMap($world);
            return 
    true;
        }
        
        public function 
    loadMap($world){
            if(!
    $this->getPlugin()->getServer()->isLevelLoaded($world)){
                
    $this->getPlugin()->getServer()->loadLevel($world);
                return 
    true;
            }
            return 
    false;
        }
        
        public function 
    unloadMap($world){
            if(
    $this->getPlugin()->getServer()->isLevelLoaded($world)){
                
    $this->getPlugin()->getServer()->unloadLevel($this->getPlugin()->getServer()->getLevelByName($world));
                return 
    true;
            }
            return 
    false;
        }
    }
    Error:
    Code:
    [00:05:45] [Server thread/CRITICAL]: UnexpectedValueException: "RecursiveDirectoryIterator::__construct(/home/minecraft/worlds/TheBridgeBG): failed to open dir: No such file or directory" (EXCEPTION) in "plugins/TheBridge v1.1.6 PRO.phar/src/bridge/utils/Utils" at line 35
     
  2. A354-PH

    A354-PH Baby Zombie

    Messages:
    186
    GitHub:
    Kizu
    Im just updating it.
     
  3. DiamondGamer30

    DiamondGamer30 Baby Zombie

    Messages:
    175
    GitHub:
    diamondgamermcpe
    The folder does not exist.
     
  4. A354-PH

    A354-PH Baby Zombie

    Messages:
    186
    GitHub:
    Kizu
    The PRO on the versioning at the end was made by my friend
     
  5. A354-PH

    A354-PH Baby Zombie

    Messages:
    186
    GitHub:
    Kizu
    Lemme try to rename the world to TheBridgeBG
     
  6. DiamondGamer30

    DiamondGamer30 Baby Zombie

    Messages:
    175
    GitHub:
    diamondgamermcpe
    You're most likely missing the file.
     
  7. KielKing

    KielKing Zombie

    Messages:
    245
    GitHub:
    kielking
    or, it's not a directory
     
  8. A354-PH

    A354-PH Baby Zombie

    Messages:
    186
    GitHub:
    Kizu
    Its now working! I changed the world to TheBridgeBG and now it works!
     
  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.