Removing World Directory, Chunk.files are still active

Discussion in 'Plugin Development' started by iZanax, Dec 30, 2013.

Thread Status:
Not open for further replies.
  1. Offline

    iZanax

    I would like to remove the World Directory.

    I succesfully accomplish:
    - Teleport players out of this world ( InGame they are in other location )
    - Unload World (for loop thru Bukkit.getWorlds doesn't show the world I try to delete)
    (I also try to delay unload and delete. same result)

    Error:
    Region directory
    and files in here still excist and are
    not removable even manual (rightclick-delete)

    Bukkit tells me with the for loop thru worlds that the world is not active.
    But for some reason the chunks are still active..

    This problems seems fimiliar to leimekiller
    https://forums.bukkit.org/threads/remove-world-directory.208020/
    But there was no solution posted.

    Could Someone help me out?
    thanks in advance,
    Zanax


    PHP:
            for(Player player Bukkit.getPlayers()) {
                
    player.teleport(Bukkit.getWorlds().get(0).getSpawnLocation());
            }
            
    World world Bukkit.getWorld(worldName);
            
    Bukkit.unloadWorld(worldfalse);
            
    deleteDirectory(world.getWorldFolder());
    PHP:
        public boolean deleteDirectory(File directory) {
            
    System.out.println("Directory: " directory.getName());
            if(
    directory.exists()){
                for(
    File file directory.listFiles()) {
                    if(
    file.isDirectory()) {
                        
    deleteDirectory(file);
                    } else {
                        
    System.out.println("File: " file.getName());
                        
    file.delete();
                    }
                }
            }
            return(
    directory.delete());
        }
     
  2. Offline

    aredherring

    You can't remove the files because they are in use by Bukkit; what exactly are you trying to do here
     
  3. Offline

    iZanax

    aredherring
    Removing a second World Folder.
    When I have unloaded it; which should be possible.
    When I loop thru all worlds, it tells me that that world is not loaded anymore.
    But those chunk files are still active for some reason.
    (region / r.1-0.mc)
     
  4. Offline

    xTrollxDudex

    iZanax
    PHP:
    deleteDirectory(new File(this.getServer().getWorldContainer().getAbsolutePath(), world.getName()));
     
  5. Offline

    iZanax

    xTrollxDudex
    That made no difference,
    Everything beside the Region folder (and files inside) are removed.
    The files inside Region are active and cannot be removed.
    But I don't have this world loaded anymore, so this is really confusing.
     
  6. Offline

    xTrollxDudex

    iZanax
    I'm using this guy as an example a lot today, he strikes again: bergerkiller, creator of MyWorlds. Here's how he does it:
    PHP:
            /**
             * Deletes a file or directory.
             * This method will attempt to delete all files in a directory
             * if a directory is specified.
             * All files it could not delete will be returned.
             * If the returned list is empty then deletion was successful.
             * The returned list is unmodifiable.
             * 
             * @param file to delete
             * @return a list of files it could not delete
             */
            
    public static List<FiledeleteFile(File file) {
                    if (
    file.isDirectory()) {
                            List<
    FilefailFiles = new ArrayList<File>();
                            
    deleteFileList(filefailFiles);
                            return 
    Collections.unmodifiableList(failFiles);
                    } else if (
    file.delete()) {
                            return 
    Collections.emptyList();
                    } else {
                            return 
    Collections.unmodifiableList(Arrays.asList(file));
                    }
            }

            private static 
    boolean deleteFileList(File file, List<FilefailFiles) {
                    if (
    file.isDirectory()) {
                            
    boolean success true;
                            for (
    File subFile listFiles(file)) {
                                    
    success &= deleteFileList(subFilefailFiles);
                            }
                            if (
    success) {
                                    
    file.delete();
                            }
                            return 
    success;
                    } else if (
    file.delete()) {
                            return 
    true;
                    } else {
                            
    failFiles.add(file);
                            return 
    false;
                    }
            }
     
  7. Offline

    iZanax

    xTrollxDudex
    It is not related to the deleteDirectory method.
    Something keeps the chunks still active and loaded in the server.
    Even if unloadWorld was succesfull.
    The chunk files are not removable also not manual while server is running.
     
  8. Offline

    xTrollxDudex

    iZanax
    Why don't you manually unload the chunks in the world then unload the world? Both files relate to chunks.
     
  9. Offline

    iZanax

    PHP:
            for(Chunk chunk world.getLoadedChunks()) {
                if(
    chunk.unload(false)) {
                    
    System.out.println("unloadChunk - " chunk.getX() + " | " chunk.getZ());
                }
            }
            if(
    Bukkit.unloadWorld(worldfalse)) {
                
    System.out.println("unloadWorld - " world.getName());
                
    deleteDirectory(new File(Bukkit.getWorldContainer().getAbsolutePath(), world.getName()));
            }
    Still regionFiles are active : /
    *Im running on latest 1.6.4 recommanded build

    ----------------------------------------------------------------------
    It seems like a Bukkit/MC problem. not plugin related
    So I will post something at leaky.bukkit.org the day after tommorow.
     
  10. Offline

    Minecrell

    I don't think it's easy to get that working, as of it is an issue with Minecraft, and not directly with CraftBukkit. Found this issue in the bug tracker, I don't know if it's still the same problem, but probably nothing has changed there...
    https://bukkit.atlassian.net/browse/BUKKIT-2390
     
  11. Offline

    iZanax

    ferrybig

    r.0.0.mca
    r.0.1.mca
    r.1.0.mca
    r.1.1.mca

    changed to

    r.0.0.mca
    r.0.1.mca
    PHP:
            for(Chunk chunk world.getLoadedChunks()) {
                if(
    chunk.unload(false)) {
                    
    System.out.println("unloadChunk - " chunk.getX() + " | " chunk.getZ());
                }
            }
            if(
    Bukkit.unloadWorld(worldfalse)) {
                
    RegionFileCache.a();
                
    System.out.println("unloadWorld - " world.getName());
                
    deleteDirectory(new File(Bukkit.getWorldContainer().getAbsolutePath(), world.getName()));
            }
    I couldn't delete the remaining two .mca files manually.
    So those are not unloaded yet.
    Any suggestion further?
    Thanks so far
     
  12. iZanax
    can you try waiting 1 sec before calling RegionFileCache.a();, there may be other minecraft threads trying to save delayed save requests to the world
     
  13. Offline

    iZanax

    ferrybig

    Didn't work.
    As well manual after several seconds didnt do anything.
     
  14. Offline

    Minecrell

  15. Offline

    cameron5906

    I know this is a revival of a dead post, however I couldn't find a solution to this problem anywhere so I had to keep trying some new stuff myself and discovered that after calling RegionFileCache.a(); if I called the garbage collector (twice, for some reason?) and then run the deletion function, it works fine. Just thought I'd post this here for anyone else searching google in the future.
    So basically,
    Code:java
    1. RegionFileCache.a();
    2. System.gc();
    3. System.gc();
    4. FileDeleteStrategy.FORCE.deleteQuietly(new File("worldName"));
     
  16. Offline

    fireblast709

    cameron5906
    - No need to necro post nonetheless
    - The second GC call wouldn't do anything (iirc)
     
  17. Offline

    _LB

    It's a common idiom to call it twice, because certain specific implementations might actually decide to possibly actually run the GC perhaps. Maybe, sometimes. It's not guaranteed. Did I mention it's implementation-defined?
     
  18. Offline

    fireblast709

Thread Status:
Not open for further replies.

Share This Page