下面列出了org.bukkit.World#getLoadedChunks ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。
/**
* 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);
}
}
}
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);
}
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));
}
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);
}
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));
}
private int getChunkCountSpigotWay(World world) {
return world.getLoadedChunks().length;
}
@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).");
}
}