From 0160c2bb551d9cbab5659f4c2f2bb57a99b6b2d2 Mon Sep 17 00:00:00 2001 From: dordsor21 Date: Wed, 20 May 2020 08:43:58 +0100 Subject: [PATCH] Add setCuboids method to RegionManager - Allow FAWE to take charge of big operations like /plot set all --- .../core/generator/ClassicPlotManager.java | 68 +++++-------------- .../plotsquared/core/util/RegionManager.java | 16 +++++ 2 files changed, 32 insertions(+), 52 deletions(-) diff --git a/Core/src/main/java/com/plotsquared/core/generator/ClassicPlotManager.java b/Core/src/main/java/com/plotsquared/core/generator/ClassicPlotManager.java index 022f7037d..52557144e 100644 --- a/Core/src/main/java/com/plotsquared/core/generator/ClassicPlotManager.java +++ b/Core/src/main/java/com/plotsquared/core/generator/ClassicPlotManager.java @@ -36,6 +36,7 @@ import com.plotsquared.core.queue.GlobalBlockQueue; import com.plotsquared.core.queue.LocalBlockQueue; import com.plotsquared.core.util.BlockUtil; import com.plotsquared.core.util.MathMan; +import com.plotsquared.core.util.RegionManager; import com.sk89q.worldedit.function.pattern.Pattern; import com.sk89q.worldedit.regions.CuboidRegion; import com.sk89q.worldedit.world.block.BlockTypes; @@ -92,75 +93,38 @@ public class ClassicPlotManager extends SquarePlotManager { public boolean setFloor(PlotId plotId, Pattern blocks) { Plot plot = classicPlotWorld.getPlotAbs(plotId); - LocalBlockQueue queue = classicPlotWorld.getQueue(false); if (plot.isBasePlot()) { - for (CuboidRegion region : plot.getRegions()) { - Location pos1 = - new Location(classicPlotWorld.getWorldName(), region.getMinimumPoint().getX(), - classicPlotWorld.PLOT_HEIGHT, region.getMinimumPoint().getZ()); - Location pos2 = - new Location(classicPlotWorld.getWorldName(), region.getMaximumPoint().getX(), - classicPlotWorld.PLOT_HEIGHT, region.getMaximumPoint().getZ()); - queue.setCuboid(pos1, pos2, blocks); - } + return RegionManager.manager.setCuboids(classicPlotWorld, plot.getRegions(), blocks, + classicPlotWorld.PLOT_HEIGHT, classicPlotWorld.PLOT_HEIGHT); } - return queue.enqueue(); + return false; } public boolean setAll(PlotId plotId, Pattern blocks) { Plot plot = classicPlotWorld.getPlotAbs(plotId); - if (!plot.isBasePlot()) { - return false; + if (plot.isBasePlot()) { + return RegionManager.manager + .setCuboids(classicPlotWorld, plot.getRegions(), blocks, 1, getWorldHeight()); } - LocalBlockQueue queue = classicPlotWorld.getQueue(false); - int maxY = getWorldHeight(); - for (CuboidRegion region : plot.getRegions()) { - Location pos1 = - new Location(classicPlotWorld.getWorldName(), region.getMinimumPoint().getX(), 1, - region.getMinimumPoint().getZ()); - Location pos2 = - new Location(classicPlotWorld.getWorldName(), region.getMaximumPoint().getX(), maxY, - region.getMaximumPoint().getZ()); - queue.setCuboid(pos1, pos2, blocks); - } - return queue.enqueue(); + return false; } public boolean setAir(PlotId plotId, Pattern blocks) { Plot plot = classicPlotWorld.getPlotAbs(plotId); - if (!plot.isBasePlot()) { - return false; + if (plot.isBasePlot()) { + return RegionManager.manager.setCuboids(classicPlotWorld, plot.getRegions(), blocks, + classicPlotWorld.PLOT_HEIGHT + 1, getWorldHeight()); } - LocalBlockQueue queue = classicPlotWorld.getQueue(false); - int maxY = getWorldHeight(); - for (CuboidRegion region : plot.getRegions()) { - Location pos1 = - new Location(classicPlotWorld.getWorldName(), region.getMinimumPoint().getX(), - classicPlotWorld.PLOT_HEIGHT + 1, region.getMinimumPoint().getZ()); - Location pos2 = - new Location(classicPlotWorld.getWorldName(), region.getMaximumPoint().getX(), maxY, - region.getMaximumPoint().getZ()); - queue.setCuboid(pos1, pos2, blocks); - } - return queue.enqueue(); + return false; } public boolean setMain(PlotId plotId, Pattern blocks) { Plot plot = classicPlotWorld.getPlotAbs(plotId); - if (!plot.isBasePlot()) { - return false; + if (plot.isBasePlot()) { + return RegionManager.manager.setCuboids(classicPlotWorld, plot.getRegions(), blocks, 1, + classicPlotWorld.PLOT_HEIGHT - 1); } - LocalBlockQueue queue = classicPlotWorld.getQueue(false); - for (CuboidRegion region : plot.getRegions()) { - Location pos1 = - new Location(classicPlotWorld.getWorldName(), region.getMinimumPoint().getX(), 1, - region.getMinimumPoint().getZ()); - Location pos2 = - new Location(classicPlotWorld.getWorldName(), region.getMaximumPoint().getX(), - classicPlotWorld.PLOT_HEIGHT - 1, region.getMaximumPoint().getZ()); - queue.setCuboid(pos1, pos2, blocks); - } - return queue.enqueue(); + return false; } public boolean setMiddle(PlotId plotId, Pattern blocks) { diff --git a/Core/src/main/java/com/plotsquared/core/util/RegionManager.java b/Core/src/main/java/com/plotsquared/core/util/RegionManager.java index 5ab1a8350..ab3333a19 100644 --- a/Core/src/main/java/com/plotsquared/core/util/RegionManager.java +++ b/Core/src/main/java/com/plotsquared/core/util/RegionManager.java @@ -28,8 +28,11 @@ package com.plotsquared.core.util; import com.plotsquared.core.PlotSquared; import com.plotsquared.core.location.Location; import com.plotsquared.core.plot.Plot; +import com.plotsquared.core.plot.PlotArea; +import com.plotsquared.core.queue.LocalBlockQueue; import com.plotsquared.core.util.task.RunnableVal; import com.plotsquared.core.util.task.TaskManager; +import com.sk89q.worldedit.function.pattern.Pattern; import com.sk89q.worldedit.math.BlockVector2; import com.sk89q.worldedit.regions.CuboidRegion; import com.sk89q.worldedit.world.biome.BiomeType; @@ -147,6 +150,19 @@ public abstract class RegionManager { }); } + public boolean setCuboids(final PlotArea area, final Set regions, + final Pattern blocks, int minY, int maxY) { + LocalBlockQueue queue = area.getQueue(false); + for (CuboidRegion region : regions) { + Location pos1 = new Location(area.getWorldName(), region.getMinimumPoint().getX(), minY, + region.getMinimumPoint().getZ()); + Location pos2 = new Location(area.getWorldName(), region.getMaximumPoint().getX(), maxY, + region.getMaximumPoint().getZ()); + queue.setCuboid(pos1, pos2, blocks); + } + return queue.enqueue(); + } + /** * Copy a region to a new location (in the same world) */