Deleting a world while the server is running

Discussion in 'Plugin Development' started by 1994mat, Aug 5, 2014.

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

    1994mat

    So I am trying to delete a world while the server is running, I unload it correctly and do a loop to delete the files but the region folder never gets deleted, deleting it manually gives you a warning that it's being used even though I unloaded the world with this code:
    Code:
    world.setKeepSpawnInMemory(false);
    Bukkit.unloadWorld(world);
    and the world is correctly unloaded because it doesn't show up using this command
    Code:
    if (label.equalsIgnoreCase("worlds")) {
        for (World w : Bukkit.getWorlds()) player.sendMessage(w.getName());
    }
    Any idea why this isn't working? I searched the forum and according to everybody this is supposed to work..
     
  2. Offline

    1994mat

    Bump (No idea if I am allowed to bump since it isn't in the rules)
     
  3. Offline

    xXMaTTHDXx

    1994mat Something like this should do the job
    Code:
            if(new File(Bukkit.getWorldContainer(), "worldName").exists()){
                File file = new File (Bukkit.getWorldContainer(), "worldName");
                file.delete();
            }
        }
     
  4. Offline

    1994mat

    Didn't work, changed the "worldName" to the exact name of the folder but didn't delete anything, the solution I had deletes everything except a few region files.
     
  5. Offline

    Garris0n

    You can't delete directories like that. There are plenty of recursive methods that delete directories, including one in the apache commons FileUtils class.
     
  6. Offline

    Forseth11

    First you need to unload the world (Does not always work) There must be no players in the world to unload it.
    Code:java
    1. public static void unloadMap(String mapname){
    2. if(Bukkit.getServer().unloadWorld(Bukkit.getServer().getWorld(mapname), false)){
    3. plugin.getLogger().info("Successfully unloaded " + mapname);
    4. }else{
    5. plugin.getLogger().severe("COULD NOT UNLOAD " + mapname);
    6. }
    7. }


    Next you will delete the world.
    Code:java
    1. File f = new File(Bukkit.getWorldContainer() + "/" + worldName);
    2. if(f.exists()){
    3. try{
    4. f.delete();
    5. }catch(IOException e){
    6. e.printStackTrace();
    7. }
    8. }
     
  7. Offline

    xXMaTTHDXx

    Garris0n though I could have added a bit to my reply to this post, my delete method was a bit sketchy only cause it was by memory, I know there are other ways of doing it, that was what had came to mind at the current time.
     
Thread Status:
Not open for further replies.

Share This Page