Search in sources :

Example 16 with QueueCoordinator

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

the class RegionManager method copyRegion.

/**
 * Copy a region to a new location (in the same world)
 *
 * @param pos1     position 1
 * @param pos2     position 2
 * @param newPos   position to move pos1 to
 * @param actor    the actor associated with the region copy
 * @param whenDone task to run when complete
 * @return success or not
 */
public boolean copyRegion(@NonNull final Location pos1, @NonNull final Location pos2, @NonNull final Location newPos, @Nullable final PlotPlayer<?> actor, @NonNull final Runnable whenDone) {
    final int relX = newPos.getX() - pos1.getX();
    final int relZ = newPos.getZ() - pos1.getZ();
    final com.sk89q.worldedit.world.World oldWorld = worldUtil.getWeWorld(pos1.getWorldName());
    final com.sk89q.worldedit.world.World newWorld = worldUtil.getWeWorld(newPos.getWorldName());
    final QueueCoordinator copyFrom = blockQueue.getNewQueue(oldWorld);
    final BasicQueueCoordinator copyTo = (BasicQueueCoordinator) blockQueue.getNewQueue(newWorld);
    setCopyFromToConsumer(pos1, pos2, relX, relZ, oldWorld, copyFrom, copyTo, false);
    copyFrom.setCompleteTask(copyTo::enqueue);
    if (actor != null && Settings.QUEUE.NOTIFY_PROGRESS) {
        copyFrom.addProgressSubscriber(subscriberFactory.createFull(actor, Settings.QUEUE.NOTIFY_INTERVAL, Settings.QUEUE.NOTIFY_WAIT, TranslatableCaption.of("swap.progress_region_copy")));
    }
    copyFrom.addReadChunks(new CuboidRegion(BlockVector3.at(pos1.getX(), 0, pos1.getZ()), BlockVector3.at(pos2.getX(), 0, pos2.getZ())).getChunks());
    copyTo.setCompleteTask(whenDone);
    if (actor != null && Settings.QUEUE.NOTIFY_PROGRESS) {
        copyTo.addProgressSubscriber(subscriberFactory.createFull(actor, Settings.QUEUE.NOTIFY_INTERVAL, Settings.QUEUE.NOTIFY_WAIT, TranslatableCaption.of("swap.progress_region_paste")));
    }
    return copyFrom.enqueue();
}
Also used : World(com.sk89q.worldedit.world.World) BasicQueueCoordinator(com.plotsquared.core.queue.BasicQueueCoordinator) QueueCoordinator(com.plotsquared.core.queue.QueueCoordinator) BasicQueueCoordinator(com.plotsquared.core.queue.BasicQueueCoordinator) CuboidRegion(com.sk89q.worldedit.regions.CuboidRegion)

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