Guest User

Untitled

a guest
Jun 26th, 2019
146
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.55 KB | None | 0 0
  1.    private static void copyFileStructure(File source, File target){
  2.         try {
  3.             ArrayList<String> ignore = new ArrayList<>(Arrays.asList("uid.dat", "session.lock"));
  4.             if(!ignore.contains(source.getName())) {
  5.                 if(source.isDirectory()) {
  6.                     if(!target.exists())
  7.                         if (!target.mkdirs())
  8.                             throw new IOException("Couldn't create world directory!");
  9.                     String files[] = source.list();
  10.                     for (String file : files) {
  11.                         File srcFile = new File(source, file);
  12.                         File destFile = new File(target, file);
  13.                         copyFileStructure(srcFile, destFile);
  14.                     }
  15.                 } else {
  16.                     InputStream in = new FileInputStream(source);
  17.                     OutputStream out = new FileOutputStream(target);
  18.                     byte[] buffer = new byte[1024];
  19.                     int length;
  20.                     while ((length = in.read(buffer)) > 0)
  21.                         out.write(buffer, 0, length);
  22.                     in.close();
  23.                     out.close();
  24.                 }
  25.             }
  26.         } catch (IOException e) {
  27.             throw new RuntimeException(e);
  28.         }
  29.     }
  30.  
  31.     public static void copyWorld(World originalWorld, String newWorldName) {
  32.         copyFileStructure(originalWorld.getWorldFolder(), new File(Bukkit.getWorldContainer(), newWorldName));
  33.         new WorldCreator(newWorldName).createWorld();
  34.     }
Advertisement
Add Comment
Please, Sign In to add comment