下面列出了org.bukkit.Location#getChunk ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。
private boolean kingdomClaimCheck(Location loc) {
Chunk chunk = loc.getChunk();
if (wild.getConfig().getBoolean("Kingdoms")) {
Kingdoms.getManagers();
if (GameManagement.getLandManager().getOrLoadLand(
new SimpleChunkLocation(chunk)) != null && !checkSurroundingKingdoms(loc))
return true;
else
return false;
}
return false;
}
public void build_farm(Location centerLoc) {
// A new farm, add it to the farm chunk table ...
Chunk chunk = centerLoc.getChunk();
FarmChunk fc = new FarmChunk(chunk, this.getTown(), this);
CivGlobal.addFarmChunk(fc.getCoord(), fc);
this.fc = fc;
}
public static Entity getEntityAtLocation(Location loc) {
Chunk chunk = loc.getChunk();
for (Entity entity : chunk.getEntities()) {
if (entity.getLocation().getBlock().equals(loc.getBlock())) {
return entity;
}
}
return null;
}
public static Chunk getChunkAsync(Location loc) {
if (loc.getWorld().isChunkLoaded(loc.getBlockX() >> 4, loc.getBlockZ() >> 4))
return loc.getChunk();
return null;
}
public static List<Entity> getNearbyEntities(Location location, double radius, EntityType... types) {
List<Entity> entities = new ArrayList<Entity>();
if (location == null) return entities;
if (radius <= 0.0D) return entities;
double radius2 = radius * radius;
int chunkRadius = ((int) (radius / 16)) + 1;
Chunk center = location.getChunk();
int startX = center.getX() - chunkRadius;
int endX = center.getX() + chunkRadius;
int startZ = center.getZ() - chunkRadius;
int endZ = center.getZ() + chunkRadius;
World world = location.getWorld();
for (int chunkX = startX; chunkX <= endX; chunkX++) {
for (int chunkZ = startZ; chunkZ <= endZ; chunkZ++) {
if (!world.isChunkLoaded(chunkX, chunkZ)) continue;
Chunk chunk = world.getChunkAt(chunkX, chunkZ);
for (Entity entity : chunk.getEntities()) {
Location entityLoc = entity.getLocation();
// TODO: this is a workaround: for some yet unknown reason entities sometimes report to be in a
// different world..
if (!entityLoc.getWorld().equals(world)) {
Log.debug("Found an entity which reports to be in a different world than the chunk we got it from:");
Log.debug("Location=" + location + ", Chunk=" + chunk + ", ChunkWorld=" + chunk.getWorld()
+ ", entityType=" + entity.getType() + ", entityLocation=" + entityLoc);
continue; // skip this entity
}
if (entityLoc.distanceSquared(location) <= radius2) {
if (types == null) {
entities.add(entity);
} else {
EntityType type = entity.getType();
for (EntityType t : types) {
if (type.equals(t)) {
entities.add(entity);
break;
}
}
}
}
}
}
}
return entities;
}