Advertisement
Guest User

Untitled

a guest
Nov 20th, 2017
57
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.47 KB | None | 0 0
  1. package net.PlayIL.bw.utils;
  2.  
  3. import java.io.File;
  4. import java.io.FileInputStream;
  5. import java.io.FileOutputStream;
  6. import java.io.IOException;
  7. import java.io.InputStream;
  8. import java.io.OutputStream;
  9. import java.util.ArrayList;
  10. import java.util.Arrays;
  11.  
  12. import org.bukkit.Bukkit;
  13. import org.bukkit.World;
  14.  
  15. public class Worlds {
  16.  
  17. public static void setup(World main, File template) {
  18. File target = main.getWorldFolder();
  19. unloadWorld(main);
  20. copyWorld(template, target);
  21. }
  22.  
  23. public static void unloadWorld(World world) {
  24. if (!world.equals(null)) {
  25. Bukkit.getServer().unloadWorld(world, true);
  26. }
  27. }
  28.  
  29. public static void copyWorld(File source, File target) {
  30. try {
  31. ArrayList<String> ignore = new ArrayList<String>(Arrays.asList("uid.dat", "session.dat"));
  32. if (!ignore.contains(source.getName())) {
  33. if (source.isDirectory()) {
  34. if (!target.exists())
  35. target.mkdirs();
  36. String files[] = source.list();
  37. for (String file : files) {
  38. File srcFile = new File(source, file);
  39. File destFile = new File(target, file);
  40. copyWorld(srcFile, destFile);
  41. }
  42. } else {
  43. InputStream in = new FileInputStream(source);
  44. OutputStream out = new FileOutputStream(target);
  45. byte[] buffer = new byte[1024];
  46. int length;
  47. while ((length = in.read(buffer)) > 0)
  48. out.write(buffer, 0, length);
  49. in.close();
  50. out.close();
  51. }
  52. }
  53. } catch (IOException e) {
  54.  
  55.  
  56.  
  57. }
  58. }
  59. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement