Hi! Sorry for my english, but I'm from Poland (I use google translator) I want to do, so that when you type the command /restart, resets my map called "castle". This is my code: Code: final World w = ca.getSpawn1().getWorld(); final String name = w.getName(); if (Bukkit.getServer().unloadWorld(w, false)){ System.out.print("<--------------- UNLOADED"); } else { System.out.print("<--------------- ERROR"); } Bukkit.getScheduler().runTask(Main.getPlugin(), new Runnable(){ @Override public void run() { WorldCreator wr = new WorldCreator(name); wr.copy(w); wr.createWorld(); // TODO Auto-generated method stub }}); Everything is working, but when I do this the second/third etc time I get info "<------- ERROR"/ I must to do restart/reload server. Why? Sorry for my english :/
You should keep a reference/copy of the world outside of the folder of worlds, then when you unload you just delete / load a copy of the "base" instance.
My code: Code: if (Bukkit.getServer().unloadWorld(w, false)){ System.out.print("<--------------- UNLOADED"); } else { System.out.print("<--------------- ERROR"); } WorldCreator wr = new WorldCreator(name); wr.copy(w); wr.environment(Environment.NORMAL); File folder = w.getWorldFolder(); if(!folder.isDirectory()) return; for(File file : folder.listFiles()) { file.delete(); } folder.delete(); wr.createWorld(); Firt time: All OK Second/Third etc time: "<--------------- ERROR" Code: 17:29:16 [SEVERE] net.minecraft.server.v1_6_R3.ExceptionWorldConflict: Failed to check session lock, aborting 17:29:16 [SEVERE] at net.minecraft.server.v1_6_R3.WorldNBTStorage.checkSession(WorldNBTStorage.java:74) 17:29:16 [SEVERE] at net.minecraft.server.v1_6_R3.World.G(World.java:2758) 17:29:16 [SEVERE] at net.minecraft.server.v1_6_R3.ChunkRegionLoader.a(ChunkRegionLoader.java:124) 17:29:16 [SEVERE] at net.minecraft.server.v1_6_R3.ChunkProviderServer.saveChunk(ChunkProviderServer.java:209) 17:29:16 [SEVERE] at net.minecraft.server.v1_6_R3.ChunkProviderServer.unloadChunks(ChunkProviderServer.java:297) 17:29:16 [SEVERE] at net.minecraft.server.v1_6_R3.WorldServer.doTick(WorldServer.java:192) 17:29:16 [SEVERE] at net.minecraft.server.v1_6_R3.MinecraftServer.t(MinecraftServer.java:565) 17:29:16 [SEVERE] at net.minecraft.server.v1_6_R3.DedicatedServer.t(DedicatedServer.java:240) 17:29:16 [SEVERE] at net.minecraft.server.v1_6_R3.MinecraftServer.s(MinecraftServer.java:483) 17:29:16 [SEVERE] at net.minecraft.server.v1_6_R3.MinecraftServer.run(MinecraftServer.java:415) 17:29:16 [SEVERE] at net.minecraft.server.v1_6_R3.ThreadServerApplication.run(SourceFile:583) Please, help me :/
Here is a small example, how to delete and copy a WorldBackup. Code: public void resetMap(World resetWorld) { //teleport all players in the world for(Player p : resetWorld.getPlayers()) { p.teleport(Bukkit.getServer().getWorlds().get(0).getSpawnLocation()); } //unload the map Bukkit.getServer().unloadWorld(Bukkit.getServer().getWorld(resetWorld.getName()), false); //copy the map try { File normal = new File(resetWorld.getName()); File backup = new File("plugins" + File.separator + "backup" + File.separator + resetMap); if(normal.exists() && backup.exists()) { FileUtils.forceDelete(normal); FileUtils.copyDirectory(backup, new File(resetWorld.getName())); } } catch (Exception e) { e.printStackTrace(); } //load the map Bukkit.getServer().createWorld(new WorldCreator(resetWorld.getName())); }
mitroh: Import: Code: import org.apache.commons.io.FileUtils; PS: I use Java 7 edit: The resetMap-Method is my own, you can rename the method if you want