Regenerating a World

Discussion in 'Plugin Development' started by Mattredsox, Jun 22, 2013.

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

    Mattredsox

    Hello! I am currently making a plugin that requires me to delete and regenerate a world every time my plugin is enabled.

    Here is the code I am currently using:

    Code:java
    1. public void onEnable()
    2. {
    3. Bukkit.createWorld(new WorldCreator("testWorld").type(WorldType.NORMAL));
    4. }
    5.  
    6. public void onDisable()
    7. {
    8. for(Player p : Bukkit.getOnlinePlayers())
    9. {
    10. p.kickPlayer("Thanks for playing!");
    11. }
    12.  
    13. Bukkit.getServer().unloadWorld(Bukkit.getWorld("testWorld"), true);
    14. deleteFolder(new File("testWorld"));
    15. }
    16.  
    17. public static void deleteFolder(File folder)
    18. {
    19. File[] files = folder.listFiles();
    20. if (files != null)
    21. {
    22. for (File f : files)
    23. {
    24. if (f.isDirectory())
    25. {
    26. deleteFolder(f);
    27. } else
    28. {
    29. f.delete();
    30. }
    31. }
    32. }
    33. folder.delete();
    34. }


    However, I am getting TONS of errors in console that look like this (session.lock errors): http://pastebin.com/4kKWjacG

    Can someone direct me into fixing this error or give me some alternative code that actually works?

    I would be greatly appreciative!

    Thanks in advanced!

    -Mattredsox
     
  2. Offline

    iKanak

    If I had to guess, you (or any player for that matter) is in the world when it's being unloaded. I'm sure this is something that bukkit prevents (and is the cause of your error).

    Note that the plugin is disabled before the players are kicked. Perhaps try kicking all online players before unloading the world?

    Then again, I know very little about bukkit and this is mainly just speculation. :p
     
  3. Offline

    Mattredsox

    That isn't the problem. I have a for loop at the beginning of onDisable that kicks everyone and it still errors :(
     
  4. Offline

    Ivan

    AFAIK the session lock errors occur when you have too many files open in your OS
     
  5. Offline

    bergerkiller

    The session.lock file is in the world folder, and it is used to check whether a server is currently accessing a specific world in order to avoid world corruption when multiple servers run at once using the same worlds.
    Unloading worlds, sadly, does not clear this lock properly, and as a result you run into these issues.
    I fixed this in MyWorlds (at least I think so) by forcibly closing all file streams part of a certain world when unloading.
    Loading, unloading, loading and unloading in that order works without issues AFAIK.

    https://github.com/bergerkiller/MyW.../bergerkiller/bukkit/mw/WorldManager.java#L42

    Do note that I have some minor doubts about the security of this method...I have a mild suspicion that the world is not entirely saved upon closing the region files, which may lead to issues in the longer term. Saving before stopping is always a good idea for that reason.
     
  6. Offline

    Mattredsox

    Hmm, the error is still happening but it does seem to only happen when I have 3 clients open to test the plugin, a server running and eclipse going, all at the same time.
    This makes me suspect that it is an issue with too many programs open or no memory left for java to run on.
     
Thread Status:
Not open for further replies.

Share This Page