Java Code Examples for org.bukkit.Chunk#getZ()

The following examples show how to use org.bukkit.Chunk#getZ() . 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: Util.java    From SkyWarsReloaded with GNU General Public License v3.0 6 votes vote down vote up
public List<Chunk> getChunks(World mapWorld) {
int size = 400;
int maxX = size/2;
int minX = -size/2;
int maxZ = size/2;
int minZ = -size/2;
int minY = 0;
int maxY = 0;
Block min = mapWorld.getBlockAt(minX, minY, minZ);
Block max = mapWorld.getBlockAt(maxX, maxY, maxZ);
Chunk cMin = min.getChunk();
Chunk cMax = max.getChunk();
List<Chunk> chunks = new ArrayList<>();

for(int cx = cMin.getX(); cx < cMax.getX(); cx++) {
	for(int cz = cMin.getZ(); cz < cMax.getZ(); cz++) {
           Chunk currentChunk = mapWorld.getChunkAt(cx, cz);
           chunks.add(currentChunk);
	}
}
return chunks;
  }
 
Example 2
Source File: HologramListener.java    From Holograms with MIT License 6 votes vote down vote up
@EventHandler
public void onChunkUnload(ChunkUnloadEvent event) {
    Chunk chunk = event.getChunk();
    for (Entity entity : chunk.getEntities()) {
        HologramEntity hologramEntity = plugin.getEntityController().getHologramEntity(entity);
        if (hologramEntity != null) {
            hologramEntity.remove();
        }
    }
    Collection<Hologram> holograms = plugin.getHologramManager().getActiveHolograms().values();
    for (Hologram holo : holograms) {
        Location loc = holo.getLocation();
        int chunkX = (int) Math.floor(loc.getBlockX() / 16.0D);
        int chunkZ = (int) Math.floor(loc.getBlockZ() / 16.0D);
        if (chunkX == chunk.getX() && chunkZ == chunk.getZ()) {
            holo.despawn();
        }
    }
}
 
Example 3
Source File: EventForwarder.java    From BlueMap with MIT License 5 votes vote down vote up
@EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true)
public synchronized void onChunkFinishedGeneration(ChunkPopulateEvent evt) {
	Chunk chunk = evt.getChunk();
	UUID world = chunk.getWorld().getUID();
	Vector2i chunkPos = new Vector2i(chunk.getX(), chunk.getZ());
	listeners.forEach(l -> l.onChunkFinishedGeneration(world, chunkPos));
}
 
Example 4
Source File: CondIsSlimeChunk.java    From Skript with GNU General Public License v3.0 5 votes vote down vote up
@Override
public boolean check(Chunk chunk) {
	Random random = new Random(chunk.getWorld().getSeed() +
			(long) (chunk.getX() * chunk.getX() * 0x4c1906) +
			(long) (chunk.getX() * 0x5ac0db) +
			(long) (chunk.getZ() * chunk.getZ()) * 0x4307a7L +
			(long) (chunk.getZ() * 0x5f24f) ^ 0x3ad8025f);
	return random.nextInt(10) == 0;
}
 
Example 5
Source File: ChunkWrapper.java    From ObsidianDestroyer with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Wraps a chunk with a ChunkWrapper
 *
 * @param chunk           the chunk to wrap
 * @param durabilitiesDir the directory to store this wrapper in
 */
ChunkWrapper(Chunk chunk, File durabilitiesDir) {
    this.chunkX = chunk.getX();
    this.chunkZ = chunk.getZ();
    this.world = chunk.getWorld().getName();
    this.durabilitiesDir = durabilitiesDir;
}
 
Example 6
Source File: ChunkEventHelper.java    From ClaimChunk with MIT License 5 votes vote down vote up
private static boolean getChunksEqual(Chunk a, Chunk b) {
    if (Objects.equals(a, b)) return true;
    if (a == null || b == null) return false;

    return (Objects.equals(a.getWorld(), b.getWorld())
            && a.getX() == b.getX()
            && a.getZ() == b.getZ());
}
 
Example 7
Source File: UnloadedInventoryHandler.java    From Civs with GNU General Public License v3.0 5 votes vote down vote up
public void syncAllInventoriesInChunk(Chunk chunk) {
    String chunkString = "c:" + chunk.getX() + ":" + chunk.getZ();
    if (!unloadedChestInventories.containsKey(chunkString)) {
        return;
    }
    for (String locationString : unloadedChestInventories.get(chunkString).keySet()) {
        syncInventory(locationString);
    }
}
 
Example 8
Source File: GameCreator.java    From BedWars with GNU Lesser General Public License v3.0 5 votes vote down vote up
public static boolean isChunkInArea(Chunk l, Location p1, Location p2) {
	if (!p1.getWorld().equals(l.getWorld())) {
		return false;
	}
	
    Chunk min = new Location(p1.getWorld(), Math.min(p1.getX(), p2.getX()), Math.min(p1.getY(), p2.getY()),
            Math.min(p1.getZ(), p2.getZ())).getChunk();
    Chunk max = new Location(p1.getWorld(), Math.max(p1.getX(), p2.getX()), Math.max(p1.getY(), p2.getY()),
            Math.max(p1.getZ(), p2.getZ())).getChunk();
    return (min.getX() <= l.getX() && min.getZ() <= l.getZ() && max.getX() >= l.getX() && max.getZ() >= l.getZ());
}
 
Example 9
Source File: StoneVariantPopulator.java    From Carbon with GNU Lesser General Public License v3.0 5 votes vote down vote up
@Override
public void populate(World world, Random random, Chunk chunk) {
    int x, y, z, i;
    int worldChunkX = chunk.getX() * 16;
    int worldChunkZ = chunk.getZ() * 16;
    for (i = 0; i < pockets; i++) {
        x = worldChunkX + random.nextInt(16);
        z = worldChunkZ + random.nextInt(16);
        y = random.nextInt(257);
        this.createVein(world, max, x, y, z);
    }
}
 
Example 10
Source File: GameCreator.java    From BedWars with GNU Lesser General Public License v3.0 5 votes vote down vote up
public static boolean isChunkInArea(Chunk l, Location p1, Location p2) {
	if (!p1.getWorld().equals(l.getWorld())) {
		return false;
	}
	
    Chunk min = new Location(p1.getWorld(), Math.min(p1.getX(), p2.getX()), Math.min(p1.getY(), p2.getY()),
            Math.min(p1.getZ(), p2.getZ())).getChunk();
    Chunk max = new Location(p1.getWorld(), Math.max(p1.getX(), p2.getX()), Math.max(p1.getY(), p2.getY()),
            Math.max(p1.getZ(), p2.getZ())).getChunk();
    return (min.getX() <= l.getX() && min.getZ() <= l.getZ() && max.getX() >= l.getX() && max.getZ() >= l.getZ());
}
 
Example 11
Source File: GChunk.java    From GlobalWarming with GNU Lesser General Public License v3.0 4 votes vote down vote up
public GChunk(Chunk chunk) {
    this.world = chunk.getWorld().getName();
    this.x = chunk.getX();
    this.z = chunk.getZ();
}
 
Example 12
Source File: Regions.java    From ProjectAres with GNU Affero General Public License v3.0 4 votes vote down vote up
public static Region forChunk(Chunk chunk) {
    Vector min = new Vector(chunk.getX() * 16, 0, chunk.getZ() * 16);
    return new CuboidRegion(min, new Vector(min.getX() + 16, 256, min.getZ() + 16));
}
 
Example 13
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 14
Source File: ChunkData.java    From Shopkeepers with GNU General Public License v3.0 4 votes vote down vote up
public ChunkData(Chunk chunk) {
	Validate.notNull(chunk);
	this.worldName = chunk.getWorld().getName();
	this.chunkX = chunk.getX();
	this.chunkZ = chunk.getZ();
}
 
Example 15
Source File: Regions.java    From PGM with GNU Affero General Public License v3.0 4 votes vote down vote up
public static Region forChunk(Chunk chunk) {
  Vector min = new Vector(chunk.getX() * 16, 0, chunk.getZ() * 16);
  return new CuboidRegion(min, new Vector(min.getX() + 16, 256, min.getZ() + 16));
}
 
Example 16
Source File: TickerTask.java    From Slimefun4 with GNU General Public License v3.0 4 votes vote down vote up
public long getTimings(Chunk c) {
    String id = c.getWorld().getName() + ';' + c.getX() + ';' + c.getZ();
    return chunkTimings.getOrDefault(id, 0L);
}
 
Example 17
Source File: ChunkVector.java    From PGM with GNU Affero General Public License v3.0 4 votes vote down vote up
public static ChunkVector of(Chunk chunk) {
  return new ChunkVector(chunk.getX(), chunk.getZ());
}
 
Example 18
Source File: PlayerMovementHandler.java    From ClaimChunk with MIT License 4 votes vote down vote up
@SuppressWarnings("unused")
@EventHandler
public void onPlayerMove(PlayerMoveEvent e) {
    if (e != null && !e.isCancelled() && e.getTo() != null) {
        // Get the previous and current chunks
        Chunk prev = e.getFrom().getChunk();
        Chunk to = e.getTo().getChunk();

        // Make sure the player moved into a new chunk
        if (prev.getX() != to.getX() || prev.getZ() != to.getZ()) {
            // If the claim is currently autoclaiming, try to claim this chunk
            if (AutoClaimHandler.inList(e.getPlayer())) {
                claimChunk.getCommandHandler().mainHandler.claimChunk(e.getPlayer(), to);
                return;
            }

            ChunkHandler ch = claimChunk.getChunkHandler();

            // Check if the previous chunk was already claimed
            boolean lastClaimed = ch.isClaimed(prev.getWorld(), prev.getX(), prev.getZ());

            // Check if the new chunk is already claimed
            if (ch.isClaimed(to.getWorld(), to.getX(), to.getZ())) {
                // If the new chunk and the previous chunk were claimed, check if the owners differ
                if (lastClaimed) {
                    UUID prevOwner = ch.getOwner(prev.getWorld(), prev.getX(), prev.getZ());
                    UUID newOwner = ch.getOwner(to.getWorld(), to.getX(), to.getZ());

                    // Only display the new chunk's owner if they differ from the previous chunk's owner
                    if ((prevOwner == null && newOwner == null) || (prevOwner != null && !prevOwner.equals(newOwner))) {
                        showTitle(e.getPlayer(), to);
                    }
                } else {
                    // Show the player the chunk's owner
                    showTitle(e.getPlayer(), to);
                }
            } else {
                // The player entered an unclaimed chunk from a claimed chunk
                if (lastClaimed) {
                    UUID lastOwner = ch.getOwner(prev.getWorld(), prev.getX(), prev.getZ());
                    String name = claimChunk.getPlayerHandler().getChunkName(lastOwner);
                    String msg = (e.getPlayer().getUniqueId().equals(lastOwner) ? claimChunk.getMessages().chunkLeaveSelf : claimChunk.getMessages().chunkLeave)
                            .replace("%%PLAYER%%",
                                    ((name == null) ? claimChunk.getMessages().chunkLeaveUnknown : name));
                    Utils.toPlayer(e.getPlayer(), msg);
                }
            }
        }
    }
}
 
Example 19
Source File: SignsFeature.java    From AreaShop with GNU General Public License v3.0 2 votes vote down vote up
/**
 * Convert a chunk to a string to use as map key.
 * Use a Location argument to prevent chunk loading!
 * @param chunk The location to get the key for
 * @return A string to use in a map for a chunk
 */
public static String chunkToString(Chunk chunk) {
	return chunk.getWorld().getName() + ";" + chunk.getX() + ";" + chunk.getZ();
}
 
Example 20
Source File: ChunkPos.java    From ClaimChunk with MIT License 2 votes vote down vote up
/**
 * Create an instance of a chunk position from Spigot's chunk position
 * representation.
 *
 * @param chunk The Spigot chunk representation.
 */
public ChunkPos(Chunk chunk) {
    this(chunk.getWorld().getName(), chunk.getX(), chunk.getZ());
}