Regenerating a World

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

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


    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:

    1. public void onEnable()
    2. {
    3. Bukkit.createWorld(new WorldCreator("testWorld").type(WorldType.NORMAL));
    4. }
    6. public void onDisable()
    7. {
    8. for(Player p : Bukkit.getOnlinePlayers())
    9. {
    10. p.kickPlayer("Thanks for playing!");
    11. }
    13. Bukkit.getServer().unloadWorld(Bukkit.getWorld("testWorld"), true);
    14. deleteFolder(new File("testWorld"));
    15. }
    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):

    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!

  2. Offline


    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


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


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


    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.

    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


    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