Java Code Examples for org.bukkit.World#getLoadedChunks()
The following examples show how to use
org.bukkit.World#getLoadedChunks() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: Fire.java From GlobalWarming with GNU Lesser General Public License v3.0 | 5 votes |
/** * Set a random set of loaded blocks on fire */ private void setFire(World world, int blocks) { if (world != null) { int count = world.getLoadedChunks().length; for (int i = 0; i < blocks; i++) { int chunkIndex = GlobalWarming.getInstance().getRandom().nextInt(count); Chunk chunk = world.getLoadedChunks()[chunkIndex]; int x = (chunk.getX() * BLOCKS_PER_CHUNK) + GlobalWarming.getInstance().getRandom().nextInt(BLOCKS_PER_CHUNK); int z = (chunk.getZ() * BLOCKS_PER_CHUNK) + GlobalWarming.getInstance().getRandom().nextInt(BLOCKS_PER_CHUNK); Block topBlock = world.getHighestBlockAt(x, z); topBlock.getRelative(BlockFace.UP).setType(Material.FIRE); } } }
Example 2
Source File: WorldData.java From LagMonitor with MIT License | 5 votes |
public static WorldData fromWorld(World world) { String worldName = world.getName(); int tileEntities = 0; for (Chunk loadedChunk : world.getLoadedChunks()) { tileEntities += loadedChunk.getTileEntities().length; } int entities = world.getEntities().size(); int chunks = world.getLoadedChunks().length; return new WorldData(worldName, chunks, tileEntities, entities); }
Example 3
Source File: SystemCommand.java From LagMonitor with MIT License | 5 votes |
private void displayWorldInfo(CommandSender sender) { int entities = 0; int chunks = 0; int livingEntities = 0; int tileEntities = 0; long usedWorldSize = 0; List<World> worlds = Bukkit.getWorlds(); for (World world : worlds) { for (Chunk loadedChunk : world.getLoadedChunks()) { tileEntities += loadedChunk.getTileEntities().length; } livingEntities += world.getLivingEntities().size(); entities += world.getEntities().size(); chunks += world.getLoadedChunks().length; File worldFolder = Bukkit.getWorld(world.getUID()).getWorldFolder(); usedWorldSize += LagUtils.getFolderSize(plugin.getLogger(), worldFolder.toPath()); } sendMessage(sender, "Entities", String.format("%d/%d", livingEntities, entities)); sendMessage(sender, "Tile Entities", String.valueOf(tileEntities)); sendMessage(sender, "Loaded Chunks", String.valueOf(chunks)); sendMessage(sender, "Worlds", String.valueOf(worlds.size())); sendMessage(sender, "World Size", readableBytes(usedWorldSize)); }
Example 4
Source File: WorldData.java From LagMonitor with MIT License | 5 votes |
public static WorldData fromWorld(World world) { String worldName = world.getName(); int tileEntities = 0; for (Chunk loadedChunk : world.getLoadedChunks()) { tileEntities += loadedChunk.getTileEntities().length; } int entities = world.getEntities().size(); int chunks = world.getLoadedChunks().length; return new WorldData(worldName, chunks, tileEntities, entities); }
Example 5
Source File: SystemCommand.java From LagMonitor with MIT License | 5 votes |
private void displayWorldInfo(CommandSender sender) { int entities = 0; int chunks = 0; int livingEntities = 0; int tileEntities = 0; long usedWorldSize = 0; List<World> worlds = Bukkit.getWorlds(); for (World world : worlds) { for (Chunk loadedChunk : world.getLoadedChunks()) { tileEntities += loadedChunk.getTileEntities().length; } livingEntities += world.getLivingEntities().size(); entities += world.getEntities().size(); chunks += world.getLoadedChunks().length; File worldFolder = Bukkit.getWorld(world.getUID()).getWorldFolder(); usedWorldSize += LagUtils.getFolderSize(plugin.getLogger(), worldFolder.toPath()); } sendMessage(sender, "Entities", String.format("%d/%d", livingEntities, entities)); sendMessage(sender, "Tile Entities", String.valueOf(tileEntities)); sendMessage(sender, "Loaded Chunks", String.valueOf(chunks)); sendMessage(sender, "Worlds", String.valueOf(worlds.size())); sendMessage(sender, "World Size", readableBytes(usedWorldSize)); }
Example 6
Source File: BukkitSensor.java From Plan with GNU Lesser General Public License v3.0 | 4 votes |
private int getChunkCountSpigotWay(World world) { return world.getLoadedChunks().length; }
Example 7
Source File: DebugCommand.java From HolographicDisplays with GNU General Public License v3.0 | 4 votes |
@Override public void execute(CommandSender sender, String label, String[] args) throws CommandException { boolean foundAnyHologram = false; for (World world : Bukkit.getWorlds()) { Map<Hologram, HologramDebugInfo> hologramsDebugInfo = new HashMap<>(); for (Chunk chunk : world.getLoadedChunks()) { for (Entity entity : chunk.getEntities()) { NMSEntityBase nmsEntity = HolographicDisplays.getNMSManager().getNMSEntityBase(entity); if (nmsEntity == null) { continue; } Hologram ownerHologram = nmsEntity.getHologramLine().getParent(); HologramDebugInfo hologramDebugInfo = hologramsDebugInfo.computeIfAbsent(ownerHologram, mapKey -> new HologramDebugInfo()); if (nmsEntity.isDeadNMS()) { hologramDebugInfo.deadEntities++; } else { hologramDebugInfo.aliveEntities++; } } } if (!hologramsDebugInfo.isEmpty()) { foundAnyHologram = true; sender.sendMessage(Colors.PRIMARY + "Holograms in world '" + world.getName() + "':"); for (Entry<Hologram, HologramDebugInfo> entry : hologramsDebugInfo.entrySet()) { Hologram hologram = entry.getKey(); String displayName = getHologramDisplayName(hologram); HologramDebugInfo debugInfo = entry.getValue(); sender.sendMessage(Colors.PRIMARY_SHADOW + "- '" + displayName + "': " + hologram.size() + " lines, " + debugInfo.getTotalEntities() + " entities (" + debugInfo.aliveEntities + " alive, " + debugInfo.deadEntities + " dead)"); } } } if (!foundAnyHologram) { sender.sendMessage(Colors.ERROR + "Couldn't find any loaded hologram (holograms may be in unloaded chunks)."); } }