Search in sources :

Example 21 with Chunk

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;
}
Also used : WorldHandle(com.bergerkiller.generated.net.minecraft.world.level.WorldHandle) IntVector2(com.bergerkiller.bukkit.common.bases.IntVector2) Chunk(org.bukkit.Chunk) IntVector3(com.bergerkiller.bukkit.common.bases.IntVector3) File(java.io.File) HashSet(java.util.HashSet)

Example 22 with Chunk

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;
}
Also used : IntVector2(com.bergerkiller.bukkit.common.bases.IntVector2) Chunk(org.bukkit.Chunk) File(java.io.File) IntVector3(com.bergerkiller.bukkit.common.bases.IntVector3) HashSet(java.util.HashSet)

Example 23 with Chunk

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();
        }
    }
}
Also used : Entity(org.bukkit.entity.Entity) ItemFrame(org.bukkit.entity.ItemFrame) World(org.bukkit.World) OfflineWorld(com.bergerkiller.bukkit.common.offline.OfflineWorld) IntVector2(com.bergerkiller.bukkit.common.bases.IntVector2) Chunk(org.bukkit.Chunk) Map(java.util.Map) IdentityHashMap(java.util.IdentityHashMap) IntHashMap(com.bergerkiller.bukkit.common.wrappers.IntHashMap) HashMap(java.util.HashMap) OutputTypeMap(com.bergerkiller.mountiplex.reflection.util.OutputTypeMap) ItemFrameInfo(com.bergerkiller.bukkit.common.map.binding.ItemFrameInfo)

Example 24 with Chunk

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;
}
Also used : CompletableFuture(java.util.concurrent.CompletableFuture) Chunk(org.bukkit.Chunk)

Example 25 with Chunk

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();
                    }
                }
            }
        }
    }
}
Also used : Entity(org.bukkit.entity.Entity) Monster(org.bukkit.entity.Monster) Chunk(org.bukkit.Chunk) Location(org.bukkit.Location)

Aggregations

Chunk (org.bukkit.Chunk)52 Location (org.bukkit.Location)16 World (org.bukkit.World)10 OwnedLand (biz.princeps.landlord.util.OwnedLand)9 Entity (org.bukkit.entity.Entity)9 ArrayList (java.util.ArrayList)6 IntVector2 (com.bergerkiller.bukkit.common.bases.IntVector2)5 IntVector3 (com.bergerkiller.bukkit.common.bases.IntVector3)5 Block (org.bukkit.block.Block)5 BlockState (org.bukkit.block.BlockState)5 Player (org.bukkit.entity.Player)5 Offers (biz.princeps.landlord.persistent.Offers)4 HashSet (java.util.HashSet)4 EventHandler (org.bukkit.event.EventHandler)3 Plugin (org.bukkit.plugin.Plugin)3 LPlayer (biz.princeps.landlord.persistent.LPlayer)2 DurationTag (com.denizenscript.denizencore.objects.core.DurationTag)2 ElementTag (com.denizenscript.denizencore.objects.core.ElementTag)2 ListTag (com.denizenscript.denizencore.objects.core.ListTag)2 Mob (com.earth2me.essentials.Mob)2