Advertisement
Guest User

WorldManager Class

a guest
May 28th, 2018
102
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.20 KB | None | 0 0
  1. package me.uba;
  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 WorldManager {
  16.  
  17. private WorldManager() { }
  18.  
  19. static WorldManager instance = new WorldManager();
  20.  
  21. public static WorldManager getInstance() {
  22. return instance;
  23. }
  24.  
  25. @SuppressWarnings("unused")
  26. private World world;
  27.  
  28. public void unloadWorld(World world) {
  29. this.world = Bukkit.getWorld("");
  30. if(!world.equals(null)) {
  31. Bukkit.getServer().unloadWorld(world, true);
  32. }
  33. }
  34. public boolean deleteWorld(File path) {
  35. if(path.exists()) {
  36. File files[] = path.listFiles();
  37. for(int i=0; i<files.length; i++) {
  38. if(files[i].isDirectory()) {
  39. deleteWorld(files[i]);
  40. } else {
  41. files[i].delete();
  42. }
  43. }
  44. }
  45. return(path.delete());
  46. }
  47. public void copyWorld(File source, File target){
  48. try {
  49. ArrayList<String> ignore = new ArrayList<String>(Arrays.asList("uid.dat", "session.dat"));
  50. if(!ignore.contains(source.getName())) {
  51. if(source.isDirectory()) {
  52. if(!target.exists())
  53. target.mkdirs();
  54. String files[] = source.list();
  55. for (String file : files) {
  56. File srcFile = new File(source, file);
  57. File destFile = new File(target, file);
  58. copyWorld(srcFile, destFile);
  59. }
  60. } else {
  61. InputStream in = new FileInputStream(source);
  62. OutputStream out = new FileOutputStream(target);
  63. byte[] buffer = new byte[1024];
  64. int length;
  65. while ((length = in.read(buffer)) > 0)
  66. out.write(buffer, 0, length);
  67. in.close();
  68. out.close();
  69. }
  70. }
  71. } catch (IOException e) {
  72.  
  73. }
  74. }
  75.  
  76. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement