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

Solved How to delete world from the worlds folder

Discussion in 'Development' started by SkyZone, Jun 24, 2018.

  1. SkyZone

    SkyZone Slime

    Messages:
    95
    Hi guys, I'm trying to delete a world inside to worlds folder, but it doesn't work, there isn't even a error message.

    PHP:
    $lvl $player->getLevel();
                        
    $folder $lvl->getProvider()->getPath();
                        
    $this->plugin->getServer()->unloadLevel($lvl);
                        
    $server $this->plugin->getServer()->getDataPath();

                        echo 
    $folder;

                        
    $player->teleport($this->plugin->getServer()->getDefaultLevel()->getSafeSpawn());
                        
    $this->plugin->getServer()->getScheduler()->scheduleDelayedTask(new DelayedDeleteDir($this->plugin$folder), 40);
    PHP:
    <?php

    namespace CWTraining\tasks;

    use 
    CWTraining\CWTraining;
    use 
    pocketmine\scheduler\Task;

    class 
    DelayedDeleteDir extends Task{
        public 
    $plugin;
        public 
    $dir;

        public function 
    __construct(CWTraining $pluginstring $dir) {
            
    $this->plugin $plugin;
        }

        public function 
    onRun(int $currentTick) {
            
    $this->plugin->delete_files($this->dir);
        }
    }
    PHP:
    public function delete_files($target) {
            if(
    is_dir($target)){
                
    $files glob$target '*'GLOB_MARK ); //GLOB_MARK adds a slash to directories returned

                
    foreach( $files as $file )
                {
                    
    $this->delete_files$file );
                }

                
    rmdir$target );
            } elseif(
    is_file($target)) {
                
    unlink$target );
            }
        }
    Please help, idk what I do wrong...
     
  2. SalmonDE

    SalmonDE Zombie Pigman

    Messages:
    739
    GitHub:
    SalmonDE
    Solved with SkyZoneMC in a private discord chat.
    He was missing $this->dir = $dir; in his task constructor.

    PHP:
    public function __construct(CWTraining $pluginstring $dir) {
        
    $this->plugin $plugin;
    }
     
    SkyZone 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.