Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class WorldManager extends Manager
- {
- public WorldManager(** p)
- {
- super(p);
- }
- public void configureWorlds()
- {
- for(Player p : Bukkit.getOnlinePlayers())
- p.kickPlayer(ChatUtils.NAME+"\n§e§m----------------\n§cLe serveur redémarre !");
- while(Bukkit.getOnlinePlayers().size()!=0);
- /*
- * Generate Lobbby if world doesn't exists
- */
- // if(Bukkit.getWorld("TGLobby") == null) // TODO != -> ==
- resetTGLobby();
- if(true){
- new WorldCreator("TGLobby").generator(new ChunkGenerator()
- {
- @Override
- public List<BlockPopulator> getDefaultPopulators(World world)
- {
- return new ArrayList<BlockPopulator>(); // Empty list
- }
- @Override
- public boolean canSpawn(World world, int x, int z)
- {
- return false;
- }
- @Override
- public byte[][] generateBlockSections(World world, Random random, int chunkx, int chunkz, ChunkGenerator.BiomeGrid biomes)
- {
- return new byte[world.getMaxHeight() / 16][];
- }
- }).createWorld();
- plugin.setCurrentWorld("TGLobby");
- new Cuboid(Utils.getSpawn().clone().add(15, -3, 15), Utils.getSpawn().clone().add(-15, -3, -15), Material.STAINED_GLASS, true);
- new Cuboid(Utils.getSpawn().clone().add(15, 0, 15), Utils.getSpawn().clone().add(-15, -2, -15), Material.STAINED_GLASS_PANE, true);
- new Cuboid(Utils.getSpawn().clone().add(14, 0, 14), Utils.getSpawn().clone().add(-14, -2, -14), Material.AIR, (byte) -1);
- }
- resetTGWorld();
- Bukkit.createWorld(new WorldCreator("TGWorld"));
- /*
- * LOAD
- */
- for(World w : Bukkit.getWorlds())
- {
- w.setWeatherDuration(86400);
- w.setTime(6000);
- w.setPVP(true);
- WorldBorder border = w.getWorldBorder();
- border.setCenter(0, 0);
- border.setSize(1000);
- border.setDamageAmount(3);
- border.setDamageBuffer(6);
- border.setWarningDistance(60);
- plugin.getGamerulesManager().setGamerule(w, "doDaylightCycle", false);
- plugin.getGamerulesManager().setGamerule(w, "doMobLoot", false);
- plugin.getGamerulesManager().setGamerule(w, "doMobSpawning", false);
- plugin.getGamerulesManager().setGamerule(w, "mobGriefing", false);
- plugin.getGamerulesManager().setGamerule(w, "naturalRegeneration", false);
- plugin.getGamerulesManager().setGamerule(w, "logAdminCommands", false);
- plugin.getGamerulesManager().setGamerule(w, "reducedDebugInfo", false);
- for(Entity e : w.getEntities())
- if(e.getType() != EntityType.PLAYER)
- e.remove();
- }
- World world = Bukkit.getWorld("TGWorld");
- int radius = 1200;
- final long start = Calendar.getInstance().getTimeInMillis();
- for(int i = 0; i < Bukkit.getMaxPlayers(); i++)
- {
- plugin.getLogger().info("Generating spawn area " + (i + 1) + " / " + Bukkit.getMaxPlayers());
- Location center = new Location(world, radius * Math.cos(i * 360 / Bukkit.getMaxPlayers()), 100, radius * Math.sin(i * 360 / Bukkit.getMaxPlayers()));
- Chunk c = world.getChunkAt(center);
- for(int x = c.getX() - 11; x < c.getX() + 11; x++)
- for(int z = c.getZ() - 11; z < c.getZ() + 11; z++)
- if(world.getChunkAt(x, z).getBlock(8, 100, 8).getLocation().distance(center) < 280.0d)
- if(!world.getChunkAt(x, z).isLoaded())
- world.getChunkAt(x, z).load(true);
- }
- final long end = Calendar.getInstance().getTimeInMillis();
- 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");
- world.getWorldBorder().setCenter(new Location(world, 0, 0, 0));
- world.getWorldBorder().setSize(1250 * 2);
- world.getWorldBorder().setWarningDistance(5);
- }
- public void resetTGWorld()
- {
- if(Bukkit.getWorld("TGWorld") != null)
- Bukkit.unloadWorld("TGWorld", false);
- plugin.getLogger().info("Deleting TaupeGunWorld...");
- deleteWorld(new File(plugin.getDataFolder().getParentFile().getParentFile(), "TGWorld"));
- plugin.getLogger().info("Done");
- }
- public void resetTGLobby()
- {
- if(Bukkit.getWorld("TGLobby") != null)
- Bukkit.unloadWorld("TGLobby", false);
- plugin.getLogger().info("Deleting TaupeGunLobby...");
- deleteWorld(new File(plugin.getDataFolder().getParentFile().getParentFile(), "TGLobby"));
- plugin.getLogger().info("Done");
- }
- private void 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 if(!files[i].delete())
- **.getInstance().getLogger().warning(files[i].getPath() + " Has not been deleted !");
- }
- }
- return;
- }
- 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)
- {
- e.printStackTrace();
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement