Unload World, Replace World, Load World

Discussion in 'Plugin Development' started by sionzee, Feb 4, 2013.

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

    sionzee

    Hello, ( TOPIC NAME ).
    Code:java
    1. public void RestoreWorld() throws IOException {
    2. for (Player h : Bukkit.getOnlinePlayers()) {
    3. Bukkit.broadcastMessage("xx");
    4. plugin.unload(h); // TELEPORT TO ANOTHER WORLD
    5. }
    6. Bukkit.unloadWorld("BattleLance", false); // UNLOAD WORLD
    7. restore = true;
    8. final File CopyWorld = new File("BattleLance_COPY");
    9. final File World = new File("BattleLance");
    10. Bukkit.getScheduler().scheduleSyncRepeatingTask(plugin, new Runnable(){
    11. int i = 21;
    12. @Override
    13. public void run(){
    14. i--;
    15. if(i == 20) {
    16. Bukkit.broadcastMessage(ChatColor.RED + "xx");
    17. try {
    18. copyFolder(CopyWorld,World); // COPY WORLD
    19. } catch (IOException e) {
    20. e.printStackTrace();
    21. }
    22. } else if(i == 10) {
    23. Bukkit.broadcastMessage(ChatColor.RED + "xx");
    24. Bukkit.createWorld(new WorldCreator("BattleLance")); // LOADWORLD
    25. } else if(i == 5) {
    26. Bukkit.broadcastMessage(ChatColor.RED + "xx");
    27. } else if(i == 4) {
    28. Bukkit.broadcastMessage(ChatColor.RED + "xx");
    29. } else if(i == 3) {
    30. Bukkit.broadcastMessage(ChatColor.RED + "xx");
    31. } else if(i == 2) {
    32. Bukkit.broadcastMessage(ChatColor.RED + "xx");
    33. } else if(i == 1) {
    34. Bukkit.broadcastMessage(ChatColor.RED + "xx");
    35. } else if(i == 0) {
    36. restore = false;
    37. for (Player h : Bukkit.getOnlinePlayers()) {
    38. Bukkit.broadcastMessage("xx");
    39. plugin.spawn(h); // TELEPORT BACK TO SPAWN
    40. }
    41. }
    42. }
    43. }, 0L, 20L);
    44. }
    45.  
    46. public static void copyFolder(File src, File dest) throws IOException{
    47.  
    48. if(src.isDirectory()){
    49.  
    50. //if directory not exists, create it
    51. if(!dest.exists()){
    52. dest.mkdir();
    53. System.out.println("Kopiruju svet " + src + " do " + dest);
    54. }
    55.  
    56. //list all the directory contents
    57. String files[] = src.list();
    58.  
    59. for (String file : files) {
    60. //construct the src and dest file structure
    61. File srcFile = new File(src, file);
    62. File destFile = new File(dest, file);
    63. //recursive copy
    64. copyFolder(srcFile,destFile);
    65. }
    66.  
    67. }else{
    68. //if file, then copy it
    69. //Use bytes stream to support all file types
    70. OutputStream out = new FileOutputStream(dest);
    71.  
    72. byte[] buffer = new byte[1024];
    73.  
    74. int length;
    75. //copy the file content in bytes
    76. while ((length = in.read(buffer)) > 0){
    77. out.write(buffer, 0, length);
    78. }
    79.  
    80. in.close();
    81. out.close();
    82. System.out.println("Zkopirovano z " + src + " do " + dest);
    83.  
    84. }
    85. }

    I destroy spawn. Use command which call RestoreWorld()
    Teleport me to other world.
    When teleport me back to spawn, all is always destroyed. Why ?
    I Got this error: ( I don't know how this fix )!
    Code:
    2013-02-04 20:45:29 [SEVERE] net.minecraft.server.v1_4_R1.ExceptionWorldConflict: The save is being accessed from another location, aborting
    2013-02-04 20:45:29 [SEVERE]    at net.minecraft.server.v1_4_R1.WorldNBTStorage.checkSession(WorldNBTStorage.java:70)
    2013-02-04 20:45:29 [SEVERE]    at net.minecraft.server.v1_4_R1.World.D(World.java:2585)
    2013-02-04 20:45:29 [SEVERE]    at net.minecraft.server.v1_4_R1.ChunkRegionLoader.a(ChunkRegionLoader.java:115)
    2013-02-04 20:45:29 [SEVERE]    at net.minecraft.server.v1_4_R1.ChunkProviderServer.saveChunk(ChunkProviderServer.java:208)
    2013-02-04 20:45:29 [SEVERE]    at net.minecraft.server.v1_4_R1.ChunkProviderServer.unloadChunks(ChunkProviderServer.java:298)
    2013-02-04 20:45:29 [SEVERE]    at net.minecraft.server.v1_4_R1.WorldServer.doTick(WorldServer.java:161)
    2013-02-04 20:45:29 [SEVERE]    at net.minecraft.server.v1_4_R1.MinecraftServer.r(MinecraftServer.java:572)
    2013-02-04 20:45:29 [SEVERE]    at net.minecraft.server.v1_4_R1.DedicatedServer.r(DedicatedServer.java:224)
    2013-02-04 20:45:29 [SEVERE]    at net.minecraft.server.v1_4_R1.MinecraftServer.q(MinecraftServer.java:494)
    2013-02-04 20:45:29 [SEVERE]    at net.minecraft.server.v1_4_R1.MinecraftServer.run(MinecraftServer.java:427)
    2013-02-04 20:45:29 [SEVERE]    at net.minecraft.server.v1_4_R1.ThreadServerApplication.run(SourceFile:849)
     
  2. Offline

    GeekPlaya

    The final error means you're trying to modify world files of a world that is still loaded (I believe).
     
  3. Offline

    sionzee

    But:
    Code:
    Bukkit.unloadWorld("BattleLance", false); // UNLOAD WORLD
     
  4. Offline

    Johnzeh

    unloadWorld doesn't remove all the world files if the server is still running because the files are still used. You can try unloading all of the chunks first, but I'm not sure. Still trying to figure out a way of my own too.
     
  5. Offline

    Kazzababe

    That little code snippet has actually worked for me before when I was attempting to reset a map.
    I unloaded it then just loaded it again and it seemed to work fine. Could just be circumstantial but I dont know.
     
  6. Offline

    sionzee

    I changed:
    Code:java
    1. World w = Bukkit.getWorld("BattleLance");
    2. for(Chunk c : w.getLoadedChunks())
    3. c.unload(true, false);
    4.  
    5. Bukkit.unloadWorld(w, false);

    But always throws error.
     
  7. Offline

    jayfella

    don't you have to move every player to another world before it will give up the ghost and actually remove all traces of it? Try running it from the console with nobody logged into the game.
     
  8. Offline

    sionzee

    Without login, restore is sucesfull, I login, destroy two block, Logout and Error...
    Code:
    > 16:46:54 [SEVERE] net.minecraft.server.v1_4_R1.ExceptionWorldConflict: The save is being accessed from another location, aborting
    > 16:46:54 [SEVERE] at net.minecraft.server.v1_4_R1.WorldNBTStorage.checkSession(WorldNBTStorage.java:70)
    > 16:46:54 [SEVERE] at net.minecraft.server.v1_4_R1.World.D(World.java:2585)
    > 16:46:54 [SEVERE] at net.minecraft.server.v1_4_R1.ChunkRegionLoader.a(ChunkRegionLoader.java:115)
    > 16:46:54 [SEVERE] at net.minecraft.server.v1_4_R1.ChunkProviderServer.saveChunk(ChunkProviderServer.java:208)
    > 16:46:54 [SEVERE] at net.minecraft.server.v1_4_R1.ChunkProviderServer.unloadChunks(ChunkProviderServer.java:298)
    > 16:46:54 [SEVERE] at net.minecraft.server.v1_4_R1.WorldServer.doTick(WorldServer.java:161)
    > 16:46:54 [SEVERE] at net.minecraft.server.v1_4_R1.MinecraftServer.r(MinecraftServer.java:572)
    > 16:46:54 [SEVERE] at net.minecraft.server.v1_4_R1.DedicatedServer.r(DedicatedServer.java:224)
    > 16:46:54 [SEVERE] at net.minecraft.server.v1_4_R1.MinecraftServer.q(MinecraftServer.java:494)
    > 16:46:54 [SEVERE] at net.minecraft.server.v1_4_R1.MinecraftServer.run(MinecraftServer.java:427)
    > 16:46:54 [SEVERE] at net.minecraft.server.v1_4_R1.ThreadServerApplication.run(SourceFile:849)
     
  9. Offline

    Hoot215

    I've run into this problem on some of my plugins as well. I haven't tested it yet, but this might be relevant.
     
  10. Offline

    sionzee

    infects someone else?
     
  11. Offline

    Splated

    Unload fails if the world has players in it but still returns true.

    heres my Unload or else!
    Code:java
    1.  
    2. public boolean UnLoadWorld(String Name) {
    3. World world = plugin.getServer().getWorld(Name);
    4. List<World> w = Bukkit.getServer().getWorlds();
    5. Location loc = w.get(0).getSpawnLocation();
    6. if (world != null){
    7. plugin.info(plugin.getName(), world.getName() +" was not null");
    8.  
    9.  
    10. for (Player p: world.getPlayers()){
    11. p.teleport(loc);
    12. }
    13.  
    14.  
    15.  
    16.  
    17. if (plugin.getServer().unloadWorld(Name, true));
    18. plugin.info(plugin.getName(),Name +" unloaded via Unload");
    19.  
    20.  
    21. }else plugin.info(plugin.getName(),Name +" not loaded");
    22.  
    23.  
    24.  
    25. world = plugin.getServer().getWorld(Name);
    26.  
    27.  
    28.  
    29.  
    30. if (world != null){
    31.  
    32. plugin.info(plugin.getName(),Name +" Still Loaded, Stage 2 Evac!");
    33.  
    34.  
    35. for (Player p: Bukkit.getServer().getOnlinePlayers()){
    36.  
    37. if (p.getWorld().equals(world)) p.kickPlayer("Dont be dead");
    38.  
    39. }
    40.  
    41. plugin.getServer().unloadWorld(Name, true);
    42. }
    43.  
    44.  
    45. world = plugin.getServer().getWorld(Name);
    46.  
    47.  
    48.  
    49. return world == null;
    50.  
    51.  
    52. }
    53.  
     
Thread Status:
Not open for further replies.

Share This Page