Search in sources :

Example 1 with PlotLoc

use of com.plotsquared.core.location.PlotLoc 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 2 with PlotLoc

use of com.plotsquared.core.location.PlotLoc in project PlotSquared by IntellectualSites.

the class ContentMap method saveBlocks.

private void saveBlocks(BukkitWorld world, int x, int z) {
    BaseBlock[] ids = new BaseBlock[world.getMaxY() - world.getMinY() + 1];
    for (short yIndex = 0; yIndex <= world.getMaxY() - world.getMinY(); yIndex++) {
        BaseBlock block = world.getFullBlock(BlockVector3.at(x, yIndex + world.getMinY(), z));
        ids[yIndex] = block;
    }
    PlotLoc loc = new PlotLoc(x, z);
    this.allBlocks.put(loc, ids);
}
Also used : PlotLoc(com.plotsquared.core.location.PlotLoc) BaseBlock(com.sk89q.worldedit.world.block.BaseBlock)

Aggregations

PlotLoc (com.plotsquared.core.location.PlotLoc)2 BaseBlock (com.sk89q.worldedit.world.block.BaseBlock)2 Location (com.plotsquared.core.location.Location)1 QueueCoordinator (com.plotsquared.core.queue.QueueCoordinator)1 ScopedQueueCoordinator (com.plotsquared.core.queue.ScopedQueueCoordinator)1 RunnableVal (com.plotsquared.core.util.task.RunnableVal)1 BukkitWorld (com.sk89q.worldedit.bukkit.BukkitWorld)1 CuboidRegion (com.sk89q.worldedit.regions.CuboidRegion)1