org.bukkit.World#getLoadedChunks ( )源码实例Demo

下面列出了org.bukkit.World#getLoadedChunks ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。

源代码1 项目: GlobalWarming   文件: Fire.java
/**
 * 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);
        }
    }
}
 
源代码2 项目: LagMonitor   文件: WorldData.java
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);
}
 
源代码3 项目: LagMonitor   文件: SystemCommand.java
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));
}
 
源代码4 项目: LagMonitor   文件: WorldData.java
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);
}
 
源代码5 项目: LagMonitor   文件: SystemCommand.java
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));
}
 
源代码6 项目: Plan   文件: BukkitSensor.java
private int getChunkCountSpigotWay(World world) {
    return world.getLoadedChunks().length;
}
 
源代码7 项目: HolographicDisplays   文件: DebugCommand.java
@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).");
	}
	
}