Advertisement
Guest User

Untitled

a guest
Sep 7th, 2018
119
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.60 KB | None | 0 0
  1. public static void deleteFile(final File file) {
  2. if (file.isDirectory()) {
  3. if (file.listFiles().length == 0) {
  4. file.delete();
  5. }
  6. else {
  7. File[] listFiles;
  8. for (int length = (listFiles = file.listFiles()).length, i = 0; i < length; ++i) {
  9. deleteFile(listFiles[i]);
  10. }
  11. }
  12. }
  13. else {
  14. file.delete();
  15. }
  16. }
  17.  
  18. public static void copyDirectory(final File file, final File file2) {
  19. if (file.isDirectory()) {
  20. if (!file2.exists()) {
  21. file2.mkdir();
  22. }
  23. String[] list;
  24. for (int length = (list = file.list()).length, i = 0; i < length; ++i) {
  25. final String s = list[i];
  26. copyDirectory(new File(file, s), new File(file2, s));
  27. }
  28. }
  29. else {
  30. if (file.getName().equals("uid.dat") || file.getName().equals("session.dat")) {
  31. return;
  32. }
  33. try {
  34. copyFile(new FileInputStream(file), file2);
  35. }
  36. catch (Exception ex) {
  37. ex.printStackTrace();
  38. Logger.warn("Failed to copy file from " + file.getName() + " to " + file2.getName());
  39. }
  40. }
  41. }
  42.  
  43. public static void emptyFolder(File file) {
  44.  
  45. String[]entries = file.list();
  46.  
  47. for(String s : entries){
  48. File currentFile = new File(file.getPath(), s);
  49. currentFile.delete();
  50. }
  51. }
  52.  
  53. public static void applyRules(World world) {
  54. world.setAutoSave(false);
  55. world.setKeepSpawnInMemory(false);
  56. world.setAnimalSpawnLimit(0);
  57. world.setGameRuleValue("doMobSpawning", "false");
  58. world.setGameRuleValue("doDaylightCycle", "false");
  59. world.setGameRuleValue("mobGriefing", "false");
  60. world.setTime(0L);
  61. world.setStorm(false);
  62. world.setThundering(false);
  63. }
  64.  
  65. public static void copyFile(final InputStream inputStream, final File file) throws Exception {
  66. try {
  67. final FileOutputStream fileOutputStream = new FileOutputStream(file);
  68. final byte[] array = new byte[710];
  69. int read;
  70. while ((read = inputStream.read(array)) > 0) {
  71. fileOutputStream.write(array, 0, read);
  72. }
  73. fileOutputStream.close();
  74. inputStream.close();
  75. }
  76. catch (Exception ex) {
  77. throw ex;
  78. }
  79. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement