Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package net.PlayIL.bw.utils;
- import java.io.File;
- import java.io.FileInputStream;
- import java.io.FileOutputStream;
- import java.io.IOException;
- import java.io.InputStream;
- import java.io.OutputStream;
- import java.util.ArrayList;
- import java.util.Arrays;
- import org.bukkit.Bukkit;
- import org.bukkit.World;
- public class Worlds {
- public static void setup(World main, File template) {
- File target = main.getWorldFolder();
- unloadWorld(main);
- copyWorld(template, target);
- }
- public static void unloadWorld(World world) {
- if (!world.equals(null)) {
- Bukkit.getServer().unloadWorld(world, true);
- }
- }
- public static 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) {
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement