Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package me.uba;
- 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 WorldManager {
- private WorldManager() { }
- static WorldManager instance = new WorldManager();
- public static WorldManager getInstance() {
- return instance;
- }
- @SuppressWarnings("unused")
- private World world;
- public void unloadWorld(World world) {
- this.world = Bukkit.getWorld("");
- if(!world.equals(null)) {
- Bukkit.getServer().unloadWorld(world, true);
- }
- }
- public 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());
- }
- public 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