Search in sources :

Example 1 with ScopedQueueCoordinator

use of com.plotsquared.core.queue.ScopedQueueCoordinator in project PlotSquared by IntellectualSites.

the class ChunkManager method setChunkInPlotArea.

public static void setChunkInPlotArea(RunnableVal<ScopedQueueCoordinator> force, RunnableVal<ScopedQueueCoordinator> add, String world, BlockVector2 loc) {
    World weWorld = PlotSquared.platform().worldUtil().getWeWorld(world);
    QueueCoordinator queue = PlotSquared.platform().globalBlockQueue().getNewQueue(weWorld);
    if (PlotSquared.get().getPlotAreaManager().isAugmented(world) && PlotSquared.get().isNonStandardGeneration(world, loc)) {
        int blockX = loc.getX() << 4;
        int blockZ = loc.getZ() << 4;
        ScopedQueueCoordinator scoped = new ScopedQueueCoordinator(queue, Location.at(world, blockX, weWorld.getMinY(), blockZ), Location.at(world, blockX + 15, weWorld.getMaxY(), blockZ + 15));
        if (force != null) {
            force.run(scoped);
        } else {
            scoped.regenChunk(loc.getX(), loc.getZ());
            if (add != null) {
                add.run(scoped);
            }
        }
        queue.enqueue();
    } else {
        if (force != null) {
            forceChunks.put(loc, force);
        }
        addChunks.put(loc, add);
        queue.regenChunk(loc.getX(), loc.getZ());
        forceChunks.remove(loc);
        addChunks.remove(loc);
    }
}
Also used : ScopedQueueCoordinator(com.plotsquared.core.queue.ScopedQueueCoordinator) QueueCoordinator(com.plotsquared.core.queue.QueueCoordinator) ScopedQueueCoordinator(com.plotsquared.core.queue.ScopedQueueCoordinator) World(com.sk89q.worldedit.world.World)

Example 2 with ScopedQueueCoordinator

use of com.plotsquared.core.queue.ScopedQueueCoordinator in project PlotSquared by IntellectualSites.

the class BukkitRegionManager method regenerateRegion.

@Override
public boolean regenerateRegion(@NonNull final Location pos1, @NonNull final Location pos2, final boolean ignoreAugment, @Nullable final Runnable whenDone) {
    final BukkitWorld world = (BukkitWorld) worldUtil.getWeWorld(pos1.getWorldName());
    final int p1x = pos1.getX();
    final int p1z = pos1.getZ();
    final int p2x = pos2.getX();
    final int p2z = pos2.getZ();
    final int bcx = p1x >> 4;
    final int bcz = p1z >> 4;
    final int tcx = p2x >> 4;
    final int tcz = p2z >> 4;
    final QueueCoordinator queue = blockQueue.getNewQueue(world);
    final QueueCoordinator regenQueue = blockQueue.getNewQueue(world);
    queue.addReadChunks(new CuboidRegion(pos1.getBlockVector3(), pos2.getBlockVector3()).getChunks());
    queue.setChunkConsumer(chunk -> {
        int x = chunk.getX();
        int z = chunk.getZ();
        int xxb = x << 4;
        int zzb = z << 4;
        int xxt = xxb + 15;
        int zzt = zzb + 15;
        if (xxb >= p1x && xxt <= p2x && zzb >= p1z && zzt <= p2z) {
            AugmentedUtils.bypass(ignoreAugment, () -> regenQueue.regenChunk(chunk.getX(), chunk.getZ()));
            return;
        }
        boolean checkX1 = false;
        int xxb2;
        if (x == bcx) {
            xxb2 = p1x - 1;
            checkX1 = true;
        } else {
            xxb2 = xxb;
        }
        boolean checkX2 = false;
        int xxt2;
        if (x == tcx) {
            xxt2 = p2x + 1;
            checkX2 = true;
        } else {
            xxt2 = xxt;
        }
        boolean checkZ1 = false;
        int zzb2;
        if (z == bcz) {
            zzb2 = p1z - 1;
            checkZ1 = true;
        } else {
            zzb2 = zzb;
        }
        boolean checkZ2 = false;
        int zzt2;
        if (z == tcz) {
            zzt2 = p2z + 1;
            checkZ2 = true;
        } else {
            zzt2 = zzt;
        }
        final ContentMap map = new ContentMap();
        if (checkX1) {
            // 
            map.saveRegion(world, xxb, xxb2, zzb2, zzt2);
        }
        if (checkX2) {
            // 
            map.saveRegion(world, xxt2, xxt, zzb2, zzt2);
        }
        if (checkZ1) {
            // 
            map.saveRegion(world, xxb2, xxt2, zzb, zzb2);
        }
        if (checkZ2) {
            // 
            map.saveRegion(world, xxb2, xxt2, zzt2, zzt);
        }
        if (checkX1 && checkZ1) {
            // 
            map.saveRegion(world, xxb, xxb2, zzb, zzb2);
        }
        if (checkX2 && checkZ1) {
            // ?
            map.saveRegion(world, xxt2, xxt, zzb, zzb2);
        }
        if (checkX1 && checkZ2) {
            // ?
            map.saveRegion(world, xxb, xxb2, zzt2, zzt);
        }
        if (checkX2 && checkZ2) {
            // 
            map.saveRegion(world, xxt2, xxt, zzt2, zzt);
        }
        CuboidRegion currentPlotClear = new CuboidRegion(pos1.getBlockVector3(), pos2.getBlockVector3());
        map.saveEntitiesOut(Bukkit.getWorld(world.getName()).getChunkAt(x, z), currentPlotClear);
        AugmentedUtils.bypass(ignoreAugment, () -> ChunkManager.setChunkInPlotArea(null, new RunnableVal<ScopedQueueCoordinator>() {

            @Override
            public void run(ScopedQueueCoordinator value) {
                Location min = value.getMin();
                int bx = min.getX();
                int bz = min.getZ();
                for (int x1 = 0; x1 < 16; x1++) {
                    for (int z1 = 0; z1 < 16; z1++) {
                        PlotLoc plotLoc = new PlotLoc(bx + x1, bz + z1);
                        BaseBlock[] ids = map.allBlocks.get(plotLoc);
                        if (ids != null) {
                            int minY = value.getMin().getY();
                            for (int yIndex = 0; yIndex < ids.length; yIndex++) {
                                int y = yIndex + minY;
                                BaseBlock id = ids[yIndex];
                                if (id != null) {
                                    value.setBlock(x1, y, z1, id);
                                } else {
                                    value.setBlock(x1, y, z1, BlockTypes.AIR.getDefaultState());
                                }
                            }
                        }
                    }
                }
            }
        }, world.getName(), chunk));
        // map.restoreBlocks(worldObj, 0, 0);
        map.restoreEntities(Bukkit.getWorld(world.getName()));
    });
    regenQueue.setCompleteTask(whenDone);
    queue.setCompleteTask(regenQueue::enqueue);
    queue.enqueue();
    return true;
}
Also used : BukkitWorld(com.sk89q.worldedit.bukkit.BukkitWorld) ScopedQueueCoordinator(com.plotsquared.core.queue.ScopedQueueCoordinator) CuboidRegion(com.sk89q.worldedit.regions.CuboidRegion) BaseBlock(com.sk89q.worldedit.world.block.BaseBlock) PlotLoc(com.plotsquared.core.location.PlotLoc) RunnableVal(com.plotsquared.core.util.task.RunnableVal) ScopedQueueCoordinator(com.plotsquared.core.queue.ScopedQueueCoordinator) QueueCoordinator(com.plotsquared.core.queue.QueueCoordinator) Location(com.plotsquared.core.location.Location)

Example 3 with ScopedQueueCoordinator

use of com.plotsquared.core.queue.ScopedQueueCoordinator in project PlotSquared by IntellectualSites.

the class BlockStatePopulator method populate.

@Override
public void populate(@NonNull final World world, @NonNull final Random random, @NonNull final Chunk source) {
    if (this.queue == null) {
        this.queue = PlotSquared.platform().globalBlockQueue().getNewQueue(new BukkitWorld(world));
    }
    final PlotArea area = this.plotAreaManager.getPlotArea(world.getName(), null);
    if (area == null) {
        return;
    }
    final ChunkWrapper wrap = new ChunkWrapper(area.getWorldName(), source.getX(), source.getZ());
    final ScopedQueueCoordinator chunk = this.queue.getForChunk(wrap.x, wrap.z, com.plotsquared.bukkit.util.BukkitWorld.getMinWorldHeight(world), com.plotsquared.bukkit.util.BukkitWorld.getMaxWorldHeight(world) - 1);
    if (this.plotGenerator.populateChunk(chunk, area)) {
        this.queue.enqueue();
    }
}
Also used : PlotArea(com.plotsquared.core.plot.PlotArea) BukkitWorld(com.sk89q.worldedit.bukkit.BukkitWorld) ChunkWrapper(com.plotsquared.core.location.ChunkWrapper) ScopedQueueCoordinator(com.plotsquared.core.queue.ScopedQueueCoordinator)

Example 4 with ScopedQueueCoordinator

use of com.plotsquared.core.queue.ScopedQueueCoordinator in project PlotSquared by IntellectualSites.

the class AugmentedUtils method generate.

public static boolean generate(@Nullable Object chunkObject, @NonNull final String world, final int chunkX, final int chunkZ, QueueCoordinator queue) {
    if (!enabled) {
        return false;
    }
    // The coordinates of the block on the
    // least positive corner of the chunk
    final int blockX = chunkX << 4;
    final int blockZ = chunkZ << 4;
    // Create a region that contains the
    // entire chunk
    CuboidRegion region = RegionUtil.createRegion(blockX, blockX + 15, 0, 0, blockZ, blockZ + 15);
    // Query for plot areas in the chunk
    final Set<PlotArea> areas = PlotSquared.get().getPlotAreaManager().getPlotAreasSet(world, region);
    if (areas.isEmpty()) {
        return false;
    }
    boolean enqueue = false;
    boolean generationResult = false;
    for (final PlotArea area : areas) {
        // and so there's no reason to continue searching
        if (area.getType() == PlotAreaType.NORMAL) {
            return false;
        }
        // so we do not interfere
        if (area.getTerrain() == PlotAreaTerrainType.ALL || !area.contains(blockX, blockZ)) {
            continue;
        }
        IndependentPlotGenerator generator = area.getGenerator();
        // Mask
        if (queue == null) {
            enqueue = true;
            queue = PlotSquared.platform().globalBlockQueue().getNewQueue(PlotSquared.platform().worldUtil().getWeWorld(world));
            if (chunkObject != null) {
                queue.setChunkObject(chunkObject);
            }
        }
        QueueCoordinator primaryMask;
        // coordinates
        int relativeBottomX;
        int relativeBottomZ;
        int relativeTopX;
        int relativeTopZ;
        // Generation
        if (area.getType() == PlotAreaType.PARTIAL) {
            relativeBottomX = Math.max(0, area.getRegion().getMinimumPoint().getX() - blockX);
            relativeBottomZ = Math.max(0, area.getRegion().getMinimumPoint().getZ() - blockZ);
            relativeTopX = Math.min(15, area.getRegion().getMaximumPoint().getX() - blockX);
            relativeTopZ = Math.min(15, area.getRegion().getMaximumPoint().getZ() - blockZ);
            primaryMask = new AreaBoundDelegateQueueCoordinator(area, queue);
        } else {
            relativeBottomX = relativeBottomZ = 0;
            relativeTopX = relativeTopZ = 15;
            primaryMask = queue;
        }
        QueueCoordinator secondaryMask;
        BlockState air = BlockTypes.AIR.getDefaultState();
        int startYOffset = !(area instanceof ClassicPlotWorld) || ((ClassicPlotWorld) area).PLOT_BEDROCK ? 1 : 0;
        if (area.getTerrain() == PlotAreaTerrainType.ROAD) {
            PlotManager manager = area.getPlotManager();
            final boolean[][] canPlace = new boolean[16][16];
            boolean has = false;
            for (int x = relativeBottomX; x <= relativeTopX; x++) {
                for (int z = relativeBottomZ; z <= relativeTopZ; z++) {
                    int worldX = x + blockX;
                    int worldZ = z + blockZ;
                    boolean can = manager.getPlotId(worldX, 0, worldZ) == null;
                    if (can) {
                        for (int y = area.getMinGenHeight() + startYOffset; y <= area.getMaxGenHeight(); y++) {
                            queue.setBlock(worldX, y, worldZ, air);
                        }
                        canPlace[x][z] = true;
                        has = true;
                    }
                }
            }
            if (!has) {
                continue;
            }
            generationResult = true;
            secondaryMask = new LocationOffsetDelegateQueueCoordinator(canPlace, blockX, blockZ, primaryMask);
        } else {
            secondaryMask = primaryMask;
            for (int x = relativeBottomX; x <= relativeTopX; x++) {
                for (int z = relativeBottomZ; z <= relativeTopZ; z++) {
                    for (int y = area.getMinGenHeight() + startYOffset; y <= area.getMaxGenHeight(); y++) {
                        queue.setBlock(blockX + x, y, blockZ + z, air);
                    }
                }
            }
            generationResult = true;
        }
        if (chunkObject != null) {
            primaryMask.setChunkObject(chunkObject);
        }
        if (chunkObject != null) {
            secondaryMask.setChunkObject(chunkObject);
        }
        ScopedQueueCoordinator scoped = new ScopedQueueCoordinator(secondaryMask, Location.at(world, blockX, area.getMinGenHeight(), blockZ), Location.at(world, blockX + 15, area.getMaxGenHeight(), blockZ + 15));
        generator.generateChunk(scoped, area);
        generator.populateChunk(scoped, area);
        scoped.setForceSync(true);
        scoped.enqueue();
    }
    if (enqueue) {
        queue.enqueue();
    }
    return generationResult;
}
Also used : PlotArea(com.plotsquared.core.plot.PlotArea) PlotManager(com.plotsquared.core.plot.PlotManager) AreaBoundDelegateQueueCoordinator(com.plotsquared.core.queue.AreaBoundDelegateQueueCoordinator) ScopedQueueCoordinator(com.plotsquared.core.queue.ScopedQueueCoordinator) CuboidRegion(com.sk89q.worldedit.regions.CuboidRegion) BlockState(com.sk89q.worldedit.world.block.BlockState) ScopedQueueCoordinator(com.plotsquared.core.queue.ScopedQueueCoordinator) QueueCoordinator(com.plotsquared.core.queue.QueueCoordinator) LocationOffsetDelegateQueueCoordinator(com.plotsquared.core.queue.LocationOffsetDelegateQueueCoordinator) AreaBoundDelegateQueueCoordinator(com.plotsquared.core.queue.AreaBoundDelegateQueueCoordinator) LocationOffsetDelegateQueueCoordinator(com.plotsquared.core.queue.LocationOffsetDelegateQueueCoordinator)

Aggregations

ScopedQueueCoordinator (com.plotsquared.core.queue.ScopedQueueCoordinator)4 QueueCoordinator (com.plotsquared.core.queue.QueueCoordinator)3 PlotArea (com.plotsquared.core.plot.PlotArea)2 BukkitWorld (com.sk89q.worldedit.bukkit.BukkitWorld)2 CuboidRegion (com.sk89q.worldedit.regions.CuboidRegion)2 ChunkWrapper (com.plotsquared.core.location.ChunkWrapper)1 Location (com.plotsquared.core.location.Location)1 PlotLoc (com.plotsquared.core.location.PlotLoc)1 PlotManager (com.plotsquared.core.plot.PlotManager)1 AreaBoundDelegateQueueCoordinator (com.plotsquared.core.queue.AreaBoundDelegateQueueCoordinator)1 LocationOffsetDelegateQueueCoordinator (com.plotsquared.core.queue.LocationOffsetDelegateQueueCoordinator)1 RunnableVal (com.plotsquared.core.util.task.RunnableVal)1 World (com.sk89q.worldedit.world.World)1 BaseBlock (com.sk89q.worldedit.world.block.BaseBlock)1 BlockState (com.sk89q.worldedit.world.block.BlockState)1