Search in sources :

Example 1 with BasicQueueCoordinator

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

BasicQueueCoordinator (com.plotsquared.core.queue.BasicQueueCoordinator)1 QueueCoordinator (com.plotsquared.core.queue.QueueCoordinator)1 CuboidRegion (com.sk89q.worldedit.regions.CuboidRegion)1 World (com.sk89q.worldedit.world.World)1