Java Code Examples for org.bukkit.World#isChunkLoaded()

The following examples show how to use org.bukkit.World#isChunkLoaded() . 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: BukkitBlockConnectionProvider.java    From ViaVersion with MIT License 6 votes vote down vote up
@Override
public int getWorldBlockData(UserConnection user, int bx, int by, int bz) {
    UUID uuid = user.getProtocolInfo().getUuid();
    Player player = Bukkit.getPlayer(uuid);
    if (player != null) {
        World world = player.getWorld();
        int x = bx >> 4;
        int z = bz >> 4;
        if (world.isChunkLoaded(x, z)) {
            Chunk c = getChunk(world, x, z);
            Block b = c.getBlock(bx, by, bz);
            return b.getTypeId() << 4 | b.getData();
        }
    }
    return 0;
}
 
Example 2
Source File: BukkitQueue_All.java    From FastAsyncWorldedit with GNU General Public License v3.0 6 votes vote down vote up
@Override
public ChunkSnapshot getCachedChunk(World world, int cx, int cz) {
    long pair = MathMan.pairInt(cx, cz);
    ChunkSnapshot cached = chunkCache.get(pair);
    if (cached != null) return cached;
    if (world.isChunkLoaded(cx, cz)) {
        Long originalKeep = keepLoaded.get(pair);
        keepLoaded.put(pair, Long.MAX_VALUE);
        if (world.isChunkLoaded(cx, cz)) {
            Chunk chunk = world.getChunkAt(cx, cz);
            ChunkSnapshot snapshot = getAndCacheChunk(chunk);
            if (originalKeep != null) {
                keepLoaded.put(pair, originalKeep);
            } else {
                keepLoaded.remove(pair);
            }
            return snapshot;
        } else {
            keepLoaded.remove(pair);
            return null;
        }
    } else {
        return null;
    }
}
 
Example 3
Source File: SignUtil.java    From GriefDefender with MIT License 5 votes vote down vote up
public static Sign getSign(World world, Vector3i pos) {
    if (pos == null) {
        return null;
    }

    // Don't load chunks to update signs
    if (!world.isChunkLoaded(pos.getX() >> 4, pos.getZ() >> 4)) {
        return null;
    }

    return getSign(VecHelper.toLocation(world, pos));
}
 
Example 4
Source File: ChunkData.java    From Shopkeepers with GNU General Public License v3.0 5 votes vote down vote up
public boolean isChunkLoaded() {
	World world = Bukkit.getServer().getWorld(worldName);
	if (world != null) {
		return world.isChunkLoaded(chunkX, chunkZ);
	}
	return false;
}
 
Example 5
Source File: BlockUtil.java    From GriefDefender with MIT License 4 votes vote down vote up
public Set<Claim> getNearbyClaims(Location location, int blockDistance, boolean includeChildren) {
    Set<Claim> claims = new HashSet<>();
    GDClaimManager claimWorldManager = GriefDefenderPlugin.getInstance().dataStore.getClaimWorldManager(location.getWorld().getUID());
    if (claimWorldManager == null) {
        return claims;
    }

    final World world = location.getWorld();
    org.bukkit.Chunk lesserChunk = location.getWorld().getChunkAt((location.getBlockX() - blockDistance) >> 4, (location.getBlockZ() - blockDistance) >> 4);
    org.bukkit.Chunk greaterChunk = location.getWorld().getChunkAt((location.getBlockX() + blockDistance) >> 4, (location.getBlockZ() + blockDistance) >> 4);

    if (lesserChunk != null && greaterChunk != null) {
        for (int chunkX = lesserChunk.getX(); chunkX <= greaterChunk.getX(); chunkX++) {
            for (int chunkZ = lesserChunk.getZ(); chunkZ <= greaterChunk.getZ(); chunkZ++) {
                if (!world.isChunkLoaded(chunkX, chunkZ)) {
                    continue;
                }
                org.bukkit.Chunk chunk = location.getWorld().getChunkAt(chunkX, chunkZ);
                if (chunk != null) {
                    Set<Claim> claimsInChunk = claimWorldManager.getInternalChunksToClaimsMap().get(NMSUtil.getInstance().getChunkCoordIntPair(chunkX, chunkZ));
                    if (claimsInChunk != null) {
                        for (Claim claim : claimsInChunk) {
                            final GDClaim gdClaim = (GDClaim) claim;
                            if (!includeChildren) {
                                if (gdClaim.parent == null && !claims.contains(claim)) {
                                    claims.add(claim);
                                }
                            } else if (!claims.contains(claim)){
                                claims.add(claim);
                                for (Claim child : gdClaim.getChildren(true)) {
                                    claims.add(child);
                                }
                            }
                        }
                    }
                }
            }
        }
    }

    return claims;
}
 
Example 6
Source File: BlockUtil.java    From GriefDefender with MIT License 4 votes vote down vote up
public boolean isChunkLoaded(World world, int cx, int cz) {
    return world.isChunkLoaded(cx, cz);
}
 
Example 7
Source File: BlockUtil.java    From GriefDefender with MIT License 4 votes vote down vote up
public boolean isChunkLoadedAtBlock(World world, int x, int z) {
    return world.isChunkLoaded(x >> 4, z >> 4);
}
 
Example 8
Source File: ChunkPacketProcessor.java    From PacketWrapper with GNU Lesser General Public License v3.0 4 votes vote down vote up
private boolean isChunkLoaded(World world, int x, int z) {
    return world.isChunkLoaded(x, z);
}
 
Example 9
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;
}
 
Example 10
Source File: ChunkUtils.java    From AACAdditionPro with GNU General Public License v3.0 2 votes vote down vote up
/**
 * Checks if the chunk of certain coordinates are loaded.
 *
 * @param world  the {@link World} to check for the chunk
 * @param blockX the x - coordinate of a {@link org.bukkit.block.Block} in that {@link World}
 * @param blockZ the z - coordinate of a {@link org.bukkit.block.Block} in that {@link World}
 *
 * @return True if the chunk is loaded, else false.
 */
public static boolean isChunkLoaded(final World world, final int blockX, final int blockZ)
{
    return world.isChunkLoaded(blockX >> 4, blockZ >> 4);
}