Need Help with World Creating and Copying

Discussion in 'Spigot Plugin Development' started by MrGamingLion66, May 2, 2017.

  1. 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) {



            }

        }
     
  2. Are you unloading the world then copying it and loading it back up?


    Sent from my iPhone using Tapatalk
     
  3. 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
     
    #3 xPlumpOrange, May 2, 2017
    Last edited: May 2, 2017
  4. not a method provided.
     
    • Like Like x 2
  5. @ChefJava @xPlumpOrange @dNiym
    Okay I found this error in the console:
    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]
     
  6. This


    Sent from my iPhone using Tapatalk
     
  7. Exactly^ unload it first. I was getting this issue too when trying to copy world folders using that same code :p, World#unload first before you copy


    Sent from my iPhone using Tapatalk
     
  8. 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;
       }