Small Problem With Deleting Worlds

Discussion in 'Plugin Development' started by The Gaming Grunts, Feb 8, 2014.

Thread Status:
Not open for further replies.
  1. Hey everyone! So I have a small problem with deleting worlds. The code that I have below works almost perfectly. It deletes all of the contents of the world folder, but it doesn't delete the main world folder itself (idk if that's clear or not). Any help would be much appreciated :)

    Code:java
    1. public static void deleteWorld(String name){
    2. File world = new File(name);
    3.  
    4. Bukkit.getServer().unloadWorld(name, true);
    5.  
    6. if (world.isDirectory()){
    7. for (File f : world.listFiles()){
    8. f.delete();
    9. }
    10.  
    11. File region = new File(name +"/region");
    12. for (File r : region.listFiles()){
    13. r.delete();
    14. region.delete();
    15. }
    16.  
    17. File data = new File(name +"/data");
    18. for (File d : data.listFiles()){
    19. d.delete();
    20. data.delete();
    21. }
    22.  
    23. world.delete(); //Doesn't delete the actual world file
    24. }
    25.  
    26. removeWorld(name);
    27.  
    28. System.out.println("[WorldManager] Successfully deleted " + name);
    29. }
     
  2. Offline

    ztowne13

    Untested... but try using:
    Code:
    File f = new File(Bukkit.getWorldContainer().getAbsolutePath() + "\\" + worldName);
    f.delete();
    
     
  3. ztowne13
    Thanks that works perfectly :)
     
Thread Status:
Not open for further replies.

Share This Page