Java Code Examples for org.bukkit.Location#getChunk()

The following examples show how to use org.bukkit.Location#getChunk() . 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: ClaimChecks.java    From WildernessTp with MIT License 5 votes vote down vote up
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;
}
 
Example 2
Source File: Farm.java    From civcraft with GNU General Public License v2.0 5 votes vote down vote up
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;
}
 
Example 3
Source File: CivGlobal.java    From civcraft with GNU General Public License v2.0 5 votes vote down vote up
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;
}
 
Example 4
Source File: ServerUtils.java    From Hawk with GNU General Public License v3.0 4 votes vote down vote up
public static Chunk getChunkAsync(Location loc) {
    if (loc.getWorld().isChunkLoaded(loc.getBlockX() >> 4, loc.getBlockZ() >> 4))
        return loc.getChunk();
    return null;
}
 
Example 5
Source File: Utils.java    From Shopkeepers with GNU General Public License v3.0 4 votes vote down vote up
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;
}