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

Solved delete directory error?

Discussion in 'Development' started by KHAV, Jun 12, 2018.

  1. KHAV

    KHAV Baby Zombie

    Messages:
    152
    GitHub:
    xkhhv
    Why when my minigame plugin end the game and want to copy the map from my plugin and send it to worlds file tell me this error:
    Code:
    [22:36:07] [Server thread/CRITICAL]: Could not pass event 'pocketmine\event\player\PlayerQuitEvent' to 'ReachGame v1.0.0': unlink(C:\Users\khale\Desktop\PocketMine-MP\/worlds/ReachWorld-1\region\r.0.0.mca): Resource temporarily unavailable on ReachGame\Main
    [22:36:07] [Server thread/CRITICAL]: ErrorException: "unlink(C:\Users\khale\Desktop\PocketMine-MP\/worlds/ReachWorld-1\region\r.0.0.mca): Resource temporarily unavailable" (EXCEPTION) in "ReachGame/src/ReachGame/Main" at line 1162
    [22:36:07] [Server thread/DEBUG]: #0 (): pocketmine\error_handler(integer 2, string unlink(C:\Users\khale\Desktop\PocketMine-MP\/worlds/ReachWorld-1\region\r.0.0.mca): Resource temporarily unavailable, string C:\Users\khale\Desktop\PocketMine-MP\plugins\ReachGame\src\ReachGame\Main.php, integer 1162, array Array())
    [22:36:07] [Server thread/DEBUG]: #1 ReachGame/src/ReachGame/Main(1162): unlink(string C:\Users\khale\Desktop\PocketMine-MP\/worlds/ReachWorld-1\region\r.0.0.mca)
    [22:36:07] [Server thread/DEBUG]: #2 ReachGame/src/ReachGame/Main(1160): ReachGame\Main->deleteDirectory(string C:\Users\khale\Desktop\PocketMine-MP\/worlds/ReachWorld-1\region)
    [22:36:07] [Server thread/DEBUG]: #3 ReachGame/src/ReachGame/Main(343): ReachGame\Main->deleteDirectory(string C:\Users\khale\Desktop\PocketMine-MP\/worlds/ReachWorld-1)
    [22:36:07] [Server thread/DEBUG]: #4 ReachGame/src/ReachGame/Main(184): ReachGame\Main->LeaveCheck(string Game1, string Blue)
    [22:36:07] [Server thread/DEBUG]: #5 src/pocketmine/plugin/MethodEventExecutor(38): ReachGame\Main->onQuit(pocketmine\event\player\PlayerQuitEvent object)
    [22:36:07] [Server thread/DEBUG]: #6 src/pocketmine/plugin/RegisteredListener(98): pocketmine\plugin\MethodEventExecutor->execute(ReachGame\Main object, pocketmine\event\player\PlayerQuitEvent object)
    [22:36:07] [Server thread/DEBUG]: #7 src/pocketmine/plugin/PluginManager(699): pocketmine\plugin\RegisteredListener->callEvent(pocketmine\event\player\PlayerQuitEvent object)
    [22:36:07] [Server thread/DEBUG]: #8 src/pocketmine/Player(3364): pocketmine\plugin\PluginManager->callEvent(pocketmine\event\player\PlayerQuitEvent object)
    [22:36:07] [Server thread/DEBUG]: #9 src/pocketmine/network/mcpe/RakLibInterface(113): pocketmine\Player->close(pocketmine\lang\TranslationContainer object, string client disconnect)
    [22:36:07] [Server thread/DEBUG]: #10 vendor/pocketmine/raklib/server/ServerHandler(130): pocketmine\network\mcpe\RakLibInterface->closeSession(string 192.168.100.5 53186, string client disconnect)
    [22:36:07] [Server thread/DEBUG]: #11 src/pocketmine/network/mcpe/RakLibInterface(94): raklib\server\ServerHandler->handlePacket()
    [22:36:07] [Server thread/DEBUG]: #12 src/pocketmine/network/Network(89): pocketmine\network\mcpe\RakLibInterface->process()
    [22:36:07] [Server thread/DEBUG]: #13 src/pocketmine/Server(2495): pocketmine\network\Network->processInterfaces()
    [22:36:07] [Server thread/DEBUG]: #14 src/pocketmine/Server(2243): pocketmine\Server->tick()
    [22:36:07] [Server thread/DEBUG]: #15 src/pocketmine/Server(2119): pocketmine\Server->tickProcessor()
    [22:36:07] [Server thread/DEBUG]: #16 src/pocketmine/Server(1701): pocketmine\Server->start()
    [22:36:07] [Server thread/DEBUG]: #17 src/pocketmine/PocketMine(305): pocketmine\Server->__construct(BaseClassLoader object, pocketmine\utils\MainLogger object, string C:\Users\khale\Desktop\PocketMine-MP\, string C:\Users\khale\Desktop\PocketMine-MP\plugins\)
    [22:36:07] [Server thread/DEBUG]: #18 C:/Users/khale/Desktop/PocketMine-MP/PocketMine-MP.phar(1): require(string phar://C:/Users/khale/Desktop/PocketMine-MP/PocketMine-MP.phar/src/pocketmine/PocketMine.php)
    
    Note: copy map code work but the delete directory doesn't.

    I use this code for delete directory:
    PHP:
    public function deleteDirectory($dirPath) {
        if (
    is_dir($dirPath)) {
            
    $objects scandir($dirPath);
            foreach (
    $objects as $object) {
                if (
    $object != "." && $object != "..") {
                    if (
    filetype($dirPath DIRECTORY_SEPARATOR $object) == "dir") {
                        
    $this->deleteDirectory($dirPath DIRECTORY_SEPARATOR $object);
                    } else {
                        
    unlink($dirPath DIRECTORY_SEPARATOR $object); //This is 1162 line
                    
    }
                }
            }
            
    reset($objects);
            
    rmdir($dirPath);
        }
    }
    How i can fix it please?
     
  2. dktapps

    dktapps Administrator Staff Member PMMP Team

    Messages:
    774
    GitHub:
    dktapps
    you need to unload the world before trying to delete it.
     
    EdwardHamHam likes this.
  3. KHAV

    KHAV Baby Zombie

    Messages:
    152
    GitHub:
    xkhhv
    Sorry for my late reply, so i made like what you said bu what is this now?:
    Code:
    [03:29:07] [Server thread/INFO]: Unloading level "space"
    [03:29:07] [Server thread/CRITICAL]: Level "space" was unloaded during a tick
    [03:29:07] [Server thread/CRITICAL]: Error: "Call to a member function getChunk() on null" (EXCEPTION) in "src/pocketmine/entity/Entity" at line 1799
    [03:29:07] [Server thread/DEBUG]: #0 src/pocketmine/entity/projectile/Projectile(244): pocketmine\entity\Entity->checkChunks()
    [03:29:07] [Server thread/DEBUG]: #1 src/pocketmine/entity/Entity(1361): pocketmine\entity\projectile\Projectile->move(double -2.0828838912333, double -1.0559897279676, double -2.9038311956559)
    [03:29:07] [Server thread/DEBUG]: #2 src/pocketmine/level/Level(761): pocketmine\entity\Entity->onUpdate(integer 9808)
    [03:29:07] [Server thread/DEBUG]: #3 src/pocketmine/Server(2349): pocketmine\level\Level->doTick(integer 9808)
    [03:29:07] [Server thread/DEBUG]: #4 src/pocketmine/Server(2507): pocketmine\Server->checkTickUpdates(integer 9808, double 1529022546.9762)
    [03:29:07] [Server thread/DEBUG]: #5 src/pocketmine/Server(2243): pocketmine\Server->tick()
    [03:29:07] [Server thread/DEBUG]: #6 src/pocketmine/Server(2119): pocketmine\Server->tickProcessor()
    [03:29:07] [Server thread/DEBUG]: #7 src/pocketmine/Server(1701): pocketmine\Server->start()
    [03:29:07] [Server thread/DEBUG]: #8 src/pocketmine/PocketMine(305): pocketmine\Server->__construct(BaseClassLoader object, pocketmine\utils\MainLogger object, string C:\Users\khale\Desktop\PocketMine-MP\, string C:\Users\khale\Desktop\PocketMine-MP\plugins\)
    [03:29:07] [Server thread/DEBUG]: #9 C:/Users/khale/Desktop/PocketMine-MP/PocketMine-MP.phar(1): require(string phar://C:/Users/khale/Desktop/PocketMine-MP/PocketMine-MP.phar/src/pocketmine/PocketMine.php)
    
     
  4. dktapps

    dktapps Administrator Staff Member PMMP Team

    Messages:
    774
    GitHub:
    dktapps
    Use a scheduled task, avoid unloading during an event. See this issue.

    (yes, this is hacky but right now there's no better alternative.)
     
    KHAV likes this.
  5. KHAV

    KHAV Baby Zombie

    Messages:
    152
    GitHub:
    xkhhv
    Ok thank you!:)
     
  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.