SHARE
TWEET

Untitled

a guest Jun 27th, 2019 69 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1.     public static World getPlayWorld() {
  2.         return Bukkit.getWorld("playworld");
  3.     }
  4.  
  5.     public static World getOriginalWorld() {
  6.         return Bukkit.getWorld("original");
  7.     }
  8.  
  9.     public static void regeneratedWorld() {
  10.         if (getPlayWorld() != null) {
  11.             Bukkit.getLogger().warning("world is delete");
  12.             Bukkit.unloadWorld("playworld", false);
  13.             deleteWorld(new File("playworld"));
  14.         }
  15.         if (getPlayWorld() == null) {
  16.             copyWorld(getOriginalWorld(), "playworld");
  17.         }
  18.     }
  19.  
  20.     public static void copyWorld(World originalWorld, String newWorldName) {
  21.         copyFileStructure(originalWorld.getWorldFolder(), new File(Bukkit.getWorldContainer(), newWorldName));
  22.         new WorldCreator(newWorldName).createWorld();
  23.     }
  24.  
  25.     private static void copyFileStructure(File source, File target){
  26.         try {
  27.             ArrayList<String> ignore = new ArrayList<>(Arrays.asList("uid.dat", "session.lock"));
  28.             if(!ignore.contains(source.getName())) {
  29.                 if(source.isDirectory()) {
  30.                     if(!target.exists())
  31.                         if (!target.mkdirs())
  32.                             throw new IOException("Couldn't create world directory!");
  33.                     String files[] = source.list();
  34.                     for (String file : files) {
  35.                         File srcFile = new File(source, file);
  36.                         File destFile = new File(target, file);
  37.                         copyFileStructure(srcFile, destFile);
  38.                     }
  39.                 } else {
  40.                     InputStream in = new FileInputStream(source);
  41.                     OutputStream out = new FileOutputStream(target);
  42.                     byte[] buffer = new byte[1024];
  43.                     int length;
  44.                     while ((length = in.read(buffer)) > 0)
  45.                         out.write(buffer, 0, length);
  46.                     in.close();
  47.                     out.close();
  48.                 }
  49.             }
  50.         } catch (IOException e) {
  51.             throw new RuntimeException(e);
  52.         }
  53.     }
  54.    
  55.     public static boolean deleteWorld(File path) {
  56.         if(path.exists()) {
  57.             File files[] = path.listFiles();
  58.             for(int i=0; i<files.length; i++) {
  59.                 if(files[i].isDirectory()) {
  60.                     deleteWorld(files[i]);
  61.                 } else {
  62.                     files[i].delete();
  63.                 }
  64.             }
  65.         }
  66.         return(path.delete());
  67.     }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top