Advertisement
Guest User

Untitled

a guest
Jan 17th, 2018
79
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 6.97 KB | None | 0 0
  1. public class WorldManager extends Manager
  2. {
  3. public WorldManager(** p)
  4. {
  5. super(p);
  6. }
  7.  
  8. public void configureWorlds()
  9. {
  10. for(Player p : Bukkit.getOnlinePlayers())
  11. p.kickPlayer(ChatUtils.NAME+"\n§e§m----------------\n§cLe serveur redémarre !");
  12.  
  13. while(Bukkit.getOnlinePlayers().size()!=0);
  14. /*
  15. * Generate Lobbby if world doesn't exists
  16. */
  17.  
  18. // if(Bukkit.getWorld("TGLobby") == null) // TODO != -> ==
  19. resetTGLobby();
  20. if(true){
  21.  
  22. new WorldCreator("TGLobby").generator(new ChunkGenerator()
  23. {
  24. @Override
  25. public List<BlockPopulator> getDefaultPopulators(World world)
  26. {
  27. return new ArrayList<BlockPopulator>(); // Empty list
  28. }
  29.  
  30. @Override
  31. public boolean canSpawn(World world, int x, int z)
  32. {
  33. return false;
  34. }
  35.  
  36. @Override
  37. public byte[][] generateBlockSections(World world, Random random, int chunkx, int chunkz, ChunkGenerator.BiomeGrid biomes)
  38. {
  39. return new byte[world.getMaxHeight() / 16][];
  40. }
  41.  
  42. }).createWorld();
  43.  
  44. plugin.setCurrentWorld("TGLobby");
  45.  
  46. new Cuboid(Utils.getSpawn().clone().add(15, -3, 15), Utils.getSpawn().clone().add(-15, -3, -15), Material.STAINED_GLASS, true);
  47. new Cuboid(Utils.getSpawn().clone().add(15, 0, 15), Utils.getSpawn().clone().add(-15, -2, -15), Material.STAINED_GLASS_PANE, true);
  48. new Cuboid(Utils.getSpawn().clone().add(14, 0, 14), Utils.getSpawn().clone().add(-14, -2, -14), Material.AIR, (byte) -1);
  49. }
  50. resetTGWorld();
  51. Bukkit.createWorld(new WorldCreator("TGWorld"));
  52.  
  53. /*
  54. * LOAD
  55. */
  56.  
  57. for(World w : Bukkit.getWorlds())
  58. {
  59. w.setWeatherDuration(86400);
  60. w.setTime(6000);
  61. w.setPVP(true);
  62.  
  63. WorldBorder border = w.getWorldBorder();
  64. border.setCenter(0, 0);
  65. border.setSize(1000);
  66. border.setDamageAmount(3);
  67. border.setDamageBuffer(6);
  68. border.setWarningDistance(60);
  69.  
  70. plugin.getGamerulesManager().setGamerule(w, "doDaylightCycle", false);
  71. plugin.getGamerulesManager().setGamerule(w, "doMobLoot", false);
  72. plugin.getGamerulesManager().setGamerule(w, "doMobSpawning", false);
  73. plugin.getGamerulesManager().setGamerule(w, "mobGriefing", false);
  74. plugin.getGamerulesManager().setGamerule(w, "naturalRegeneration", false);
  75. plugin.getGamerulesManager().setGamerule(w, "logAdminCommands", false);
  76. plugin.getGamerulesManager().setGamerule(w, "reducedDebugInfo", false);
  77.  
  78. for(Entity e : w.getEntities())
  79. if(e.getType() != EntityType.PLAYER)
  80. e.remove();
  81. }
  82.  
  83. World world = Bukkit.getWorld("TGWorld");
  84.  
  85. int radius = 1200;
  86.  
  87. final long start = Calendar.getInstance().getTimeInMillis();
  88.  
  89. for(int i = 0; i < Bukkit.getMaxPlayers(); i++)
  90. {
  91. plugin.getLogger().info("Generating spawn area " + (i + 1) + " / " + Bukkit.getMaxPlayers());
  92.  
  93. Location center = new Location(world, radius * Math.cos(i * 360 / Bukkit.getMaxPlayers()), 100, radius * Math.sin(i * 360 / Bukkit.getMaxPlayers()));
  94. Chunk c = world.getChunkAt(center);
  95.  
  96. for(int x = c.getX() - 11; x < c.getX() + 11; x++)
  97. for(int z = c.getZ() - 11; z < c.getZ() + 11; z++)
  98. if(world.getChunkAt(x, z).getBlock(8, 100, 8).getLocation().distance(center) < 280.0d)
  99. if(!world.getChunkAt(x, z).isLoaded())
  100. world.getChunkAt(x, z).load(true);
  101. }
  102.  
  103. final long end = Calendar.getInstance().getTimeInMillis();
  104.  
  105. plugin.getLogger().info(world.getLoadedChunks().length + " chunks loaded in " + new SimpleDateFormat("mm").format(new Date(end - start)) + "m " + new SimpleDateFormat("ss").format(new Date(end - start)) + "s");
  106.  
  107. world.getWorldBorder().setCenter(new Location(world, 0, 0, 0));
  108. world.getWorldBorder().setSize(1250 * 2);
  109. world.getWorldBorder().setWarningDistance(5);
  110. }
  111.  
  112. public void resetTGWorld()
  113. {
  114. if(Bukkit.getWorld("TGWorld") != null)
  115. Bukkit.unloadWorld("TGWorld", false);
  116.  
  117. plugin.getLogger().info("Deleting TaupeGunWorld...");
  118. deleteWorld(new File(plugin.getDataFolder().getParentFile().getParentFile(), "TGWorld"));
  119. plugin.getLogger().info("Done");
  120. }
  121.  
  122. public void resetTGLobby()
  123. {
  124. if(Bukkit.getWorld("TGLobby") != null)
  125. Bukkit.unloadWorld("TGLobby", false);
  126.  
  127. plugin.getLogger().info("Deleting TaupeGunLobby...");
  128. deleteWorld(new File(plugin.getDataFolder().getParentFile().getParentFile(), "TGLobby"));
  129. plugin.getLogger().info("Done");
  130. }
  131.  
  132. private void deleteWorld(File path)
  133. {
  134. if(path.exists())
  135. {
  136. File files[] = path.listFiles();
  137. for(int i = 0; i < files.length; i++)
  138. {
  139. if(files[i].isDirectory())
  140. deleteWorld(files[i]);
  141.  
  142. else if(!files[i].delete())
  143. **.getInstance().getLogger().warning(files[i].getPath() + " Has not been deleted !");
  144. }
  145. }
  146.  
  147. return;
  148. }
  149.  
  150. public void copyWorld(File source, File target)
  151. {
  152. try
  153. {
  154. ArrayList<String> ignore = new ArrayList<String>(Arrays.asList("uid.dat", "session.dat"));
  155. if(!ignore.contains(source.getName()))
  156. {
  157. if(source.isDirectory())
  158. {
  159. if(!target.exists())
  160. target.mkdirs();
  161. String files[] = source.list();
  162. for(String file : files)
  163. {
  164. File srcFile = new File(source, file);
  165. File destFile = new File(target, file);
  166. copyWorld(srcFile, destFile);
  167. }
  168. }
  169. else
  170. {
  171. InputStream in = new FileInputStream(source);
  172. OutputStream out = new FileOutputStream(target);
  173. byte[] buffer = new byte[1024];
  174. int length;
  175. while((length = in.read(buffer)) > 0)
  176. out.write(buffer, 0, length);
  177. in.close();
  178. out.close();
  179. }
  180. }
  181. }catch(IOException e)
  182. {
  183. e.printStackTrace();
  184. }
  185. }
  186.  
  187. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement