SPIGOT COPY WORLD code example

Example 1: spigot world copy

// The world to copyWorld source = Bukkit.getWorld("world");File sourceFolder = source.getWorldFolder(); // The world to overwrite when copyingWorld target = Bukkit.getWorld("NewWorld");File targetFolder = target.getWorldFolder();

Example 2: spigot world copy

copyWorld(sourceFolder, targetFolder);

Example 3: spigot world copy

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) {     }}

Tags:

Java Example