use of org.bukkit.Chunk in project BKCommonLib by bergerhealer.
the class RegionHandler_Vanilla_1_15 method getRegions3.
@Override
public Set<IntVector3> getRegions3(World world) {
HashSet<IntVector3> regionIndices = new HashSet<IntVector3>();
// Add all RegionFile instances in the cache
Object regionFileCache = findRegionFileCache.invoke(null, HandleConversion.toWorldHandle(world));
regionIndices.addAll(findCacheRegionFileCoordinates.invoke(null, regionFileCache));
// Figure out the minimum/maximum region y coordinate
// Since Minecraft 1.17 there can be more than one region (32 chunks) vertically
WorldHandle worldHandle = WorldHandle.fromBukkit(world);
int minRegionY = worldHandle.getMinBuildHeight() >> 9;
int maxRegionY = (worldHandle.getMaxBuildHeight() - 1) >> 9;
// Obtain the region coordinates from all files in regions folder
File regionFolder = Common.SERVER.getWorldRegionFolder(world.getName());
if (regionFolder != null) {
String[] regionFileNames = regionFolder.list();
for (String regionFileName : regionFileNames) {
File file = new File(regionFolder, regionFileName);
if (file.isFile() && file.exists() && file.length() >= 4096) {
IntVector2 coords = getRegionFileCoordinates(file);
if (coords != null) {
for (int ry = minRegionY; ry <= maxRegionY; ry++) {
regionIndices.add(coords.toIntVector3(ry));
}
}
}
}
}
// Look at all loaded chunks of the world and add the regions they are inside of
for (Chunk chunk : world.getLoadedChunks()) {
IntVector2 coords = new IntVector2(chunk.getX() >> 5, chunk.getZ() >> 5);
for (int ry = minRegionY; ry <= maxRegionY; ry++) {
regionIndices.add(coords.toIntVector3(ry));
}
}
return regionIndices;
}
use of org.bukkit.Chunk in project BKCommonLib by bergerhealer.
the class RegionHandler_Vanilla_1_8 method getRegions3.
@Override
public Set<IntVector3> getRegions3(World world) {
// Obtain the region file names
Set<File> regionFiles = new HashSet<File>();
File regionFolder = Common.SERVER.getWorldRegionFolder(world.getName());
if (regionFolder != null) {
String[] regionFileNames = regionFolder.list();
for (String regionFileName : regionFileNames) {
File file = new File(regionFolder, regionFileName);
if (file.isFile() && file.exists() && file.length() >= 4096) {
regionFiles.add(file);
}
}
}
// Synchronized, since we are going to iterate the files here...unsafe not to do so!
synchronized (regionFileCacheType) {
for (File regionFile : getCache().keySet()) {
if (regionFile != null && regionFile.getParentFile().equals(regionFolder)) {
regionFiles.add(regionFile);
}
}
}
// Parse all found files into the region x and z coordinates
HashSet<IntVector3> regionIndices = new HashSet<IntVector3>();
for (File file : regionFiles) {
IntVector2 regionFileCoordinates = getRegionFileCoordinates(file);
if (regionFileCoordinates == null) {
continue;
}
IntVector3 coords = regionFileCoordinates.toIntVector3(0);
if (coords != null) {
regionIndices.add(coords);
}
}
// Look at all loaded chunks of the world and add the regions they are inside of
for (Chunk chunk : world.getLoadedChunks()) {
IntVector3 coords = new IntVector3(chunk.getX() >> 5, 0, chunk.getZ() >> 5);
regionIndices.add(coords);
}
return regionIndices;
}
use of org.bukkit.Chunk in project BKCommonLib by bergerhealer.
the class CommonMapController method onChunkEntitiesLoaded.
private void onChunkEntitiesLoaded(Chunk chunk) {
World world = chunk.getWorld();
Set<IntVector2> dependingChunks;
{
Map<IntVector2, Set<IntVector2>> dependencies = this.itemFrameClusterDependencies.get(world);
if (dependencies == null || (dependingChunks = dependencies.remove(new IntVector2(chunk))) == null) {
return;
}
}
boolean wasClustersByWorldCacheEnabled = this.itemFrameClustersByWorldEnabled;
try {
this.itemFrameClustersByWorldEnabled = true;
for (IntVector2 depending : dependingChunks) {
// Check this depending chunk is still loaded with all entities inside
// If not, then when it loads the cluster will be revived then
Chunk dependingChunk = WorldUtil.getChunk(world, depending.x, depending.z);
if (dependingChunk == null || !WorldUtil.isChunkEntitiesLoaded(dependingChunk)) {
continue;
}
// Quicker than iterating all item frames on the world
for (Entity entity : ChunkUtil.getEntities(dependingChunk)) {
if (!(entity instanceof ItemFrame)) {
continue;
}
// Recalculate UUID, this will re-discover the cluster
// May also revive other item frames that were part of the same cluster
// Note that if this chunk being loaded contained item frames part of the cluster,
// the cluster is already revived. Entity add handling occurs prior.
ItemFrameInfo frameInfo = this.itemFrames.get(entity.getEntityId());
if (frameInfo != null) {
frameInfo.onChunkDependencyLoaded();
}
}
}
} finally {
this.itemFrameClustersByWorldEnabled = wasClustersByWorldCacheEnabled;
if (!wasClustersByWorldCacheEnabled) {
itemFrameClustersByWorld.clear();
}
}
}
use of org.bukkit.Chunk in project BKCommonLib by bergerhealer.
the class LightingHandler_1_16_4_StarLightEngine method setSectionBlockLightAsync.
@Override
public CompletableFuture<Void> setSectionBlockLightAsync(World world, int cx, int cy, int cz, byte[] data) {
final CompletableFuture<Void> future = new CompletableFuture<Void>();
final Chunk chunk = WorldUtil.getChunk(world, cx, cz);
scheduleUpdate(world, () -> {
try {
handle.setBlockLightData(HandleConversion.toChunkHandle(chunk), cx, cy, cz, data);
future.complete(null);
} catch (Throwable t) {
future.completeExceptionally(t);
}
});
return future;
}
use of org.bukkit.Chunk in project acidisland by tastybento.
the class GridManager method removeMobs.
/**
* Removes monsters around location l
*
* @param l location
*/
public void removeMobs(final Location l) {
if (!inWorld(l)) {
return;
}
// Don't remove mobs if at spawn
if (this.isAtSpawn(l)) {
// plugin.getLogger().info("DEBUG: at spawn!");
return;
}
final int px = l.getBlockX();
final int py = l.getBlockY();
final int pz = l.getBlockZ();
for (int x = -1; x <= 1; x++) {
for (int z = -1; z <= 1; z++) {
final Chunk c = l.getWorld().getChunkAt(new Location(l.getWorld(), px + x * 16, py, pz + z * 16));
if (c.isLoaded()) {
for (final Entity e : c.getEntities()) {
// Don't remove if the entity is an NPC or has a name tag
if (e.getCustomName() != null || e.hasMetadata("NPC"))
continue;
if (e instanceof Monster && !Settings.mobWhiteList.contains(e.getType())) {
e.remove();
}
}
}
}
}
}
Aggregations