Hey everyone, to make arenas for my servers sky wars plugin I create a new world temporarily copied from a default version of that world. However, the copying and the world generation are not working. Any help would be appreciated. World creating code: Code (Text): World world = Bukkit.getServer().createWorld(new WorldCreator("SkyWars" + i)); //i is the number of arenas existing World copying code: Code (Text): public void copyWorld(File source, File target){ try { ArrayList<String> ignore = new ArrayList<String>(Arrays.asList("uid.dat", "session.dat")); if(!ignore.contains(source.getName())) { if(source.isDirectory()) { if(!target.exists()) target.mkdirs(); String files[] = source.list(); for (String file : files) { File srcFile = new File(source, file); File destFile = new File(target, file); copyWorld(srcFile, destFile); } } else { InputStream in = new FileInputStream(source); OutputStream out = new FileOutputStream(target); byte[] buffer = new byte[1024]; int length; while ((length = in.read(buffer)) > 0) out.write(buffer, 0, length); in.close(); out.close(); } } } catch (IOException e) { } }
Are you unloading the world then copying it and loading it back up? Sent from my iPhone using Tapatalk
Since I'm away from my computer I can't be to sure but I think there is a thing for copying worlds. Bukkit.getServer().getWorld(NAME).copy(); EDIT: Nope isn't a method
@ChefJava @xPlumpOrange @dNiym Okay I found this error in the console: Spoiler Couldn't save chunk; already in use by another instance of Minecraft? net.minecraft.server.v1_10_R1.ExceptionWorldConflict: The save for world located at .\SkyWars1 is being accessed from another location, aborting at net.minecraft.server.v1_10_R1.WorldNBTStorage.checkSession(WorldNBTStorage.java:78) ~[spigot-1.10.2.jar:git-Spigot-de459a2-51263e9] at net.minecraft.server.v1_10_R1.World.checkSession(World.java:2828) ~[spigot-1.10.2.jar:git-Spigot-de459a2-51263e9] at net.minecraft.server.v1_10_R1.ChunkRegionLoader.a(ChunkRegionLoader.java:126) ~[spigot-1.10.2.jar:git-Spigot-de459a2-51263e9] at net.minecraft.server.v1_10_R1.ChunkProviderServer.saveChunk(ChunkProviderServer.java:208) [spigot-1.10.2.jar:git-Spigot-de459a2-51263e9] at net.minecraft.server.v1_10_R1.ChunkProviderServer.unloadChunk(ChunkProviderServer.java:300) [spigot-1.10.2.jar:git-Spigot-de459a2-51263e9] at net.minecraft.server.v1_10_R1.ChunkProviderServer.unloadChunks(ChunkProviderServer.java:258) [spigot-1.10.2.jar:git-Spigot-de459a2-51263e9] at net.minecraft.server.v1_10_R1.WorldServer.doTick(WorldServer.java:235) [spigot-1.10.2.jar:git-Spigot-de459a2-51263e9] at net.minecraft.server.v1_10_R1.MinecraftServer.D(MinecraftServer.java:783) [spigot-1.10.2.jar:git-Spigot-de459a2-51263e9] at net.minecraft.server.v1_10_R1.DedicatedServer.D(DedicatedServer.java:400) [spigot-1.10.2.jar:git-Spigot-de459a2-51263e9] at net.minecraft.server.v1_10_R1.MinecraftServer.C(MinecraftServer.java:668) [spigot-1.10.2.jar:git-Spigot-de459a2-51263e9] at net.minecraft.server.v1_10_R1.MinecraftServer.run(MinecraftServer.java:567) [spigot-1.10.2.jar:git-Spigot-de459a2-51263e9] at java.lang.Thread.run(Unknown Source) [?:1.8.0_111]
Exactly^ unload it first. I was getting this issue too when trying to copy world folders using that same code , World#unload first before you copy Sent from my iPhone using Tapatalk
http://stackoverflow.com/questions/1146153/copying-files-from-one-directory-to-another-in-java https://docs.oracle.com/javase/tutorial/essential/io/copy.html The short answer: just recursively visit each directory or file in the target directory (the same loop you use to delete a directory and its contents) and call Files.copy() on each file.
Code (Java): public static boolean copyDir(Path dir, Path dest) { try { Files.copy(dir,dest); } catch(IOException e) { return false; } File d = dir.toFile(); if(d==null) return false; if(d.isDirectory()) { File[] fs = d.listFiles(); if(fs != null) for(File f : fs) if(!copyDir(f.toPath(),dest.resolve(f.getName()))) return false; } return true; }