Search in sources :

Example 1 with QueueCoordinator

use of com.plotsquared.core.queue.QueueCoordinator 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 QueueCoordinator

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

the class RegionManager method setBiome.

/**
 * Set a region to a biome type.
 *
 * @param region      region to set
 * @param extendBiome how far outside the region to extent setting the biome too account for 3D biomes being 4x4
 * @param biome       biome to set
 * @param area        {@link PlotArea} in which the biome is being set
 * @param whenDone    task to run when complete
 * @since 6.6.0
 */
public void setBiome(final CuboidRegion region, final int extendBiome, final BiomeType biome, final PlotArea area, final Runnable whenDone) {
    final QueueCoordinator queue = blockQueue.getNewQueue(worldUtil.getWeWorld(area.getWorldName()));
    queue.addReadChunks(region.getChunks());
    final BlockVector3 regionMin = region.getMinimumPoint();
    final BlockVector3 regionMax = region.getMaximumPoint();
    queue.setChunkConsumer(chunkPos -> {
        BlockVector3 chunkMin = BlockVector3.at(Math.max(chunkPos.getX() << 4, regionMin.getBlockX()), regionMin.getBlockY(), Math.max(chunkPos.getZ() << 4, regionMin.getBlockZ()));
        BlockVector3 chunkMax = BlockVector3.at(Math.min((chunkPos.getX() << 4) + 15, regionMax.getBlockX()), regionMax.getBlockY(), Math.min((chunkPos.getZ() << 4) + 15, regionMax.getBlockZ()));
        CuboidRegion chunkRegion = new CuboidRegion(region.getWorld(), chunkMin, chunkMax);
        WorldUtil.setBiome(area.getWorldName(), chunkRegion, biome);
        worldUtil.refreshChunk(chunkPos.getBlockX(), chunkPos.getBlockZ(), area.getWorldName());
    });
    queue.setCompleteTask(whenDone);
    queue.enqueue();
}
Also used : BasicQueueCoordinator(com.plotsquared.core.queue.BasicQueueCoordinator) QueueCoordinator(com.plotsquared.core.queue.QueueCoordinator) CuboidRegion(com.sk89q.worldedit.regions.CuboidRegion) BlockVector3(com.sk89q.worldedit.math.BlockVector3)

Example 3 with QueueCoordinator

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

the class RegionManager method swap.

/**
 * Swap two regions within the same world
 *
 * @param pos1     position 1
 * @param pos2     position 2
 * @param swapPos  position to swap with
 * @param actor    the actor associated with the region copy
 * @param whenDone task to run when complete
 */
public void swap(Location pos1, Location pos2, Location swapPos, @Nullable final PlotPlayer<?> actor, final Runnable whenDone) {
    int relX = swapPos.getX() - pos1.getX();
    int relZ = swapPos.getZ() - pos1.getZ();
    World world1 = worldUtil.getWeWorld(pos1.getWorldName());
    World world2 = worldUtil.getWeWorld(swapPos.getWorldName());
    QueueCoordinator fromQueue1 = blockQueue.getNewQueue(world1);
    QueueCoordinator fromQueue2 = blockQueue.getNewQueue(world2);
    fromQueue1.setUnloadAfter(false);
    fromQueue2.setUnloadAfter(false);
    fromQueue1.addReadChunks(new CuboidRegion(pos1.getBlockVector3(), pos2.getBlockVector3()).getChunks());
    fromQueue2.addReadChunks(new CuboidRegion(swapPos.getBlockVector3(), BlockVector3.at(swapPos.getX() + pos2.getX() - pos1.getX(), pos1.getY(), swapPos.getZ() + pos2.getZ() - pos1.getZ())).getChunks());
    QueueCoordinator toQueue1 = blockQueue.getNewQueue(world1);
    QueueCoordinator toQueue2 = blockQueue.getNewQueue(world2);
    setCopyFromToConsumer(pos1, pos2, relX, relZ, world1, fromQueue1, toQueue2, true);
    setCopyFromToConsumer(pos1.add(relX, 0, relZ), pos2.add(relX, 0, relZ), -relX, -relZ, world1, fromQueue2, toQueue1, true);
    toQueue2.setCompleteTask(whenDone);
    if (actor != null && Settings.QUEUE.NOTIFY_PROGRESS) {
        toQueue2.addProgressSubscriber(subscriberFactory.createFull(actor, Settings.QUEUE.NOTIFY_INTERVAL, Settings.QUEUE.NOTIFY_WAIT, TranslatableCaption.of("swap.progress_region2_paste")));
    }
    toQueue1.setCompleteTask(toQueue2::enqueue);
    if (actor != null && Settings.QUEUE.NOTIFY_PROGRESS) {
        toQueue1.addProgressSubscriber(subscriberFactory.createFull(actor, Settings.QUEUE.NOTIFY_INTERVAL, Settings.QUEUE.NOTIFY_WAIT, TranslatableCaption.of("swap.progress_region1_paste")));
    }
    fromQueue2.setCompleteTask(toQueue1::enqueue);
    if (actor != null && Settings.QUEUE.NOTIFY_PROGRESS) {
        fromQueue2.addProgressSubscriber(subscriberFactory.createFull(actor, Settings.QUEUE.NOTIFY_INTERVAL, Settings.QUEUE.NOTIFY_WAIT, TranslatableCaption.of("swap.progress_region2_copy")));
    }
    fromQueue1.setCompleteTask(fromQueue2::enqueue);
    if (actor != null && Settings.QUEUE.NOTIFY_PROGRESS) {
        fromQueue1.addProgressSubscriber(subscriberFactory.createFull(actor, Settings.QUEUE.NOTIFY_INTERVAL, Settings.QUEUE.NOTIFY_WAIT, TranslatableCaption.of("swap.progress_region1_copy")));
    }
    fromQueue1.enqueue();
}
Also used : BasicQueueCoordinator(com.plotsquared.core.queue.BasicQueueCoordinator) QueueCoordinator(com.plotsquared.core.queue.QueueCoordinator) CuboidRegion(com.sk89q.worldedit.regions.CuboidRegion) World(com.sk89q.worldedit.world.World)

Example 4 with QueueCoordinator

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

the class Trim method onCommand.

@Override
public boolean onCommand(final PlotPlayer<?> player, String[] args) {
    if (args.length == 0) {
        sendUsage(player);
        return false;
    }
    final String world = args[0];
    if (!this.worldUtil.isWorld(world) || !this.plotAreaManager.hasPlotArea(world)) {
        player.sendMessage(TranslatableCaption.of("errors.not_valid_world"));
        return false;
    }
    if (Trim.TASK) {
        player.sendMessage(TranslatableCaption.of("trim.trim_in_progress"));
        return false;
    }
    Trim.TASK = true;
    final boolean regen = args.length == 2 && Boolean.parseBoolean(args[1]);
    getTrimRegions(world, new RunnableVal2<>() {

        @Override
        public void run(Set<BlockVector2> viable, final Set<BlockVector2> nonViable) {
            Runnable regenTask;
            if (regen) {
                LOGGER.info("Starting regen task");
                LOGGER.info(" - This is a VERY slow command");
                LOGGER.info(" - It will say 'Trim done!' when complete");
                regenTask = new Runnable() {

                    @Override
                    public void run() {
                        if (nonViable.isEmpty()) {
                            Trim.TASK = false;
                            player.sendMessage(TranslatableCaption.of("trim.trim_done"));
                            LOGGER.info("Trim done!");
                            return;
                        }
                        Iterator<BlockVector2> iterator = nonViable.iterator();
                        BlockVector2 mcr = iterator.next();
                        iterator.remove();
                        int cbx = mcr.getX() << 5;
                        int cbz = mcr.getZ() << 5;
                        // get all 1024 chunks
                        HashSet<BlockVector2> chunks = new HashSet<>();
                        for (int x = cbx; x < cbx + 32; x++) {
                            for (int z = cbz; z < cbz + 32; z++) {
                                BlockVector2 loc = BlockVector2.at(x, z);
                                chunks.add(loc);
                            }
                        }
                        int bx = cbx << 4;
                        int bz = cbz << 4;
                        CuboidRegion region = RegionUtil.createRegion(bx, bx + 511, 0, 0, bz, bz + 511);
                        for (Plot plot : PlotQuery.newQuery().inWorld(world)) {
                            Location bot = plot.getBottomAbs();
                            Location top = plot.getExtendedTopAbs();
                            CuboidRegion plotReg = RegionUtil.createRegion(bot.getX(), top.getX(), 0, 0, bot.getZ(), top.getZ());
                            if (!RegionUtil.intersects(region, plotReg)) {
                                continue;
                            }
                            for (int x = plotReg.getMinimumPoint().getX() >> 4; x <= plotReg.getMaximumPoint().getX() >> 4; x++) {
                                for (int z = plotReg.getMinimumPoint().getZ() >> 4; z <= plotReg.getMaximumPoint().getZ() >> 4; z++) {
                                    BlockVector2 loc = BlockVector2.at(x, z);
                                    chunks.remove(loc);
                                }
                            }
                        }
                        final QueueCoordinator queue = blockQueue.getNewQueue(worldUtil.getWeWorld(world));
                        TaskManager.getPlatformImplementation().objectTask(chunks, new RunnableVal<>() {

                            @Override
                            public void run(BlockVector2 value) {
                                queue.regenChunk(value.getX(), value.getZ());
                            }
                        }).thenAccept(ignore -> TaskManager.getPlatformImplementation().taskLater(this, TaskTime.ticks(1L)));
                    }
                };
            } else {
                regenTask = () -> {
                    Trim.TASK = false;
                    player.sendMessage(TranslatableCaption.of("trim.trim_done"));
                    LOGGER.info("Trim done!");
                };
            }
            regionManager.deleteRegionFiles(world, viable, regenTask);
        }
    });
    return true;
}
Also used : Plot(com.plotsquared.core.plot.Plot) CuboidRegion(com.sk89q.worldedit.regions.CuboidRegion) BlockVector2(com.sk89q.worldedit.math.BlockVector2) RunnableVal(com.plotsquared.core.util.task.RunnableVal) QueueCoordinator(com.plotsquared.core.queue.QueueCoordinator) HashSet(java.util.HashSet) Location(com.plotsquared.core.location.Location)

Example 5 with QueueCoordinator

use of com.plotsquared.core.queue.QueueCoordinator 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)

Aggregations

QueueCoordinator (com.plotsquared.core.queue.QueueCoordinator)16 CuboidRegion (com.sk89q.worldedit.regions.CuboidRegion)10 Location (com.plotsquared.core.location.Location)7 ArrayDeque (java.util.ArrayDeque)4 ArrayList (java.util.ArrayList)4 Plot (com.plotsquared.core.plot.Plot)3 PlotArea (com.plotsquared.core.plot.PlotArea)3 BasicQueueCoordinator (com.plotsquared.core.queue.BasicQueueCoordinator)3 ScopedQueueCoordinator (com.plotsquared.core.queue.ScopedQueueCoordinator)3 HashSet (java.util.HashSet)3 PlotUnlinkEvent (com.plotsquared.core.events.PlotUnlinkEvent)2 PlotManager (com.plotsquared.core.plot.PlotManager)2 PlotFlag (com.plotsquared.core.plot.flag.PlotFlag)2 RunnableVal (com.plotsquared.core.util.task.RunnableVal)2 Pattern (com.sk89q.worldedit.function.pattern.Pattern)2 World (com.sk89q.worldedit.world.World)2 BiomeType (com.sk89q.worldedit.world.biome.BiomeType)2 Nullable (org.checkerframework.checker.nullness.qual.Nullable)2 JsonParseException (com.google.gson.JsonParseException)1 Inject (com.google.inject.Inject)1