Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public static World getPlayWorld() {
- return Bukkit.getWorld("playworld");
- }
- public static World getOriginalWorld() {
- return Bukkit.getWorld("original");
- }
- public static void regeneratedWorld() {
- if (getPlayWorld() != null) {
- Bukkit.getLogger().warning("world is delete");
- Bukkit.unloadWorld("playworld", false);
- deleteWorld(new File("playworld"));
- }
- if (getPlayWorld() == null) {
- copyWorld(getOriginalWorld(), "playworld");
- }
- }
- public static void copyWorld(World originalWorld, String newWorldName) {
- copyFileStructure(originalWorld.getWorldFolder(), new File(Bukkit.getWorldContainer(), newWorldName));
- new WorldCreator(newWorldName).createWorld();
- }
- private static void copyFileStructure(File source, File target){
- try {
- ArrayList<String> ignore = new ArrayList<>(Arrays.asList("uid.dat", "session.lock"));
- 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);
- copyFileStructure(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) {
- throw new RuntimeException(e);
- }
- }
- public static boolean deleteWorld(File path) {
- if(path.exists()) {
- File files[] = path.listFiles();
- for(int i=0; i<files.length; i++) {
- if(files[i].isDirectory()) {
- deleteWorld(files[i]);
- } else {
- files[i].delete();
- }
- }
- }
- return(path.delete());
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement