1.12.2 Copying the world does not work

Discussion in 'Spigot Plugin Development' started by jarnoboy404, Feb 23, 2020.

  1. Hello i am making a spigot plugin. This plugin needs to copy a world to a new world. When i try to do that i get a normal generated world with a lot of holes in it. Does somebody know how i can copy a world? This is my code so far.

    Code (Java):
        private static void copy(File source, File target) {
            ArrayList<String> ignore = new ArrayList<>(Arrays.asList("uid.dat", "session.lock", "playerdata"));

            try {
                if(!ignore.contains(source.getName())) {
                    if (source.isDirectory()) {
                        if (!target.exists()) if (!target.mkdirs()) throw new IOException("Couldn't create world directory!");
                        String files[] = source.list();
                        for (String file : files) {
                            File srcFile = new File(source, file);
                            File destFile = new File(target, file);
                            copy(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);
            } catch (IOException e) {

        public static void cloneWorld(String sourceName, String destName) {
            File source = new File("./" + sourceName);
            File target = new File("./" + destName);
            File session = new File(target.getPath() + "/session.lock");
            copy(source, target);
            try {
                DataOutputStream dataoutputstream = new DataOutputStream(new FileOutputStream(session));

                try {
                } finally {
            }catch (IOException e) {

            new WorldCreator(destName).createWorld();

    And this is the screenshot of the generated world with the holes:
    • Like Like x 1
  2. You could also use Multiverse’s API for world management

    and I’ve a question why don’t you just copy the whole directory