Solved Remove world directory

Discussion in 'Plugin Development' started by leimekiller, Dec 19, 2013.

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

    leimekiller

    Hello,

    I am trying to remove a full world (The folder too) but it only doesn't remove the "region" folder. Does anyone know how to fix this?
     
  2. Offline

    Minecrell

    Have you unloaded the world first?
     
  3. Offline

    Alshain01

    Your going to have to unload the world from the server class first to make sure Bukkit isn't trying to use it. This can be done with Server.unloadWorld()

    http://jd.bukkit.org/rb/apidocs/org/bukkit/Server.html

    Once you have it unloaded you probably have to resort to Java File IO. There won't be anything in Bukkit to delete it outright.
     
  4. Offline

    leimekiller

    Minecrell Yes, I did.

    Alshain01 I already did that.

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Jun 5, 2016
  5. Offline

    Alshain01

    leimekiller For anything more we would need to see the code your using.
     
  6. Offline

    leimekiller

    Alshain01

    Code:java
    1. @Override
    2. public void onDisable()
    3. {
    4. System.out.println("[SuperWalls] Disabled!");
    5.  
    6. this.getServer().unloadWorld(Bukkit.getWorld(s.getString("currentmap")), false);
    7.  
    8. final File remove = new File(this.getServer().getWorldContainer().getAbsolutePath() + "/" + s.getString("currentmap"));
    9.  
    10. deleteDirectory(remove);
    11. }


    Delete directory method:
    Code:java
    1. static public boolean deleteDirectory(File path)
    2. {
    3. if(path.exists())
    4. {
    5. File[] files = path.listFiles();
    6. for(int i = 0; i < files.length; i++)
    7. {
    8. if(files[i].isDirectory())
    9. {
    10. deleteDirectory(files[i]);
    11. }
    12. else
    13. {
    14. files[i].delete();
    15. }
    16. }
    17. }
    18. return (path.delete());
    19. }[/i][/i][/i]
     
  7. Offline

    Alshain01

    Wrong slash character. and it must be escaped. May not be the only problem but that one jumped out at me.

    Code:java
    1. final File remove = new File(this.getServer().getWorldContainer().getAbsolutePath() + "\\" + s.getString("currentmap"))
     
  8. Offline

    Shevchik

    Nope. At least his separator will not fail on *nix, but your will.
     
  9. Offline

    Alshain01

    Never has for me. As you can see I have more Linux users than Windows and it uses "\\" on every yml file I have. Judging by the fact that he marked it as solved, I'm guessing that was the issue.

    Of course if you really want to avoid literals (other than the last one) all together you could do this:

    Code:java
    1. final File remove = new File(this.getServer().getWorldContainer().getAbsolutePath(), s.getString("currentmap"));
     
  10. Offline

    Shevchik

    The \\ will only work based on distro, on fresh ubuntu 12.04 it doesn't work.
    The only one correct separator is File.separator.
     
Thread Status:
Not open for further replies.

Share This Page