Add setCuboids method to RegionManager

- Allow FAWE to take charge of big operations like /plot set all
This commit is contained in:
dordsor21 2020-05-20 08:43:58 +01:00
parent 7aba70ea65
commit 0160c2bb55
2 changed files with 32 additions and 52 deletions

View file

@ -36,6 +36,7 @@ import com.plotsquared.core.queue.GlobalBlockQueue;
import com.plotsquared.core.queue.LocalBlockQueue; import com.plotsquared.core.queue.LocalBlockQueue;
import com.plotsquared.core.util.BlockUtil; import com.plotsquared.core.util.BlockUtil;
import com.plotsquared.core.util.MathMan; import com.plotsquared.core.util.MathMan;
import com.plotsquared.core.util.RegionManager;
import com.sk89q.worldedit.function.pattern.Pattern; import com.sk89q.worldedit.function.pattern.Pattern;
import com.sk89q.worldedit.regions.CuboidRegion; import com.sk89q.worldedit.regions.CuboidRegion;
import com.sk89q.worldedit.world.block.BlockTypes; import com.sk89q.worldedit.world.block.BlockTypes;
@ -92,76 +93,39 @@ public class ClassicPlotManager extends SquarePlotManager {
public boolean setFloor(PlotId plotId, Pattern blocks) { public boolean setFloor(PlotId plotId, Pattern blocks) {
Plot plot = classicPlotWorld.getPlotAbs(plotId); Plot plot = classicPlotWorld.getPlotAbs(plotId);
LocalBlockQueue queue = classicPlotWorld.getQueue(false);
if (plot.isBasePlot()) { if (plot.isBasePlot()) {
for (CuboidRegion region : plot.getRegions()) { return RegionManager.manager.setCuboids(classicPlotWorld, plot.getRegions(), blocks,
Location pos1 = classicPlotWorld.PLOT_HEIGHT, classicPlotWorld.PLOT_HEIGHT);
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 false;
return queue.enqueue();
} }
public boolean setAll(PlotId plotId, Pattern blocks) { public boolean setAll(PlotId plotId, Pattern blocks) {
Plot plot = classicPlotWorld.getPlotAbs(plotId); Plot plot = classicPlotWorld.getPlotAbs(plotId);
if (!plot.isBasePlot()) { if (plot.isBasePlot()) {
return RegionManager.manager
.setCuboids(classicPlotWorld, plot.getRegions(), blocks, 1, getWorldHeight());
}
return false; return false;
} }
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();
}
public boolean setAir(PlotId plotId, Pattern blocks) { public boolean setAir(PlotId plotId, Pattern blocks) {
Plot plot = classicPlotWorld.getPlotAbs(plotId); Plot plot = classicPlotWorld.getPlotAbs(plotId);
if (!plot.isBasePlot()) { if (plot.isBasePlot()) {
return RegionManager.manager.setCuboids(classicPlotWorld, plot.getRegions(), blocks,
classicPlotWorld.PLOT_HEIGHT + 1, getWorldHeight());
}
return false; return false;
} }
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();
}
public boolean setMain(PlotId plotId, Pattern blocks) { public boolean setMain(PlotId plotId, Pattern blocks) {
Plot plot = classicPlotWorld.getPlotAbs(plotId); Plot plot = classicPlotWorld.getPlotAbs(plotId);
if (!plot.isBasePlot()) { if (plot.isBasePlot()) {
return RegionManager.manager.setCuboids(classicPlotWorld, plot.getRegions(), blocks, 1,
classicPlotWorld.PLOT_HEIGHT - 1);
}
return false; return false;
} }
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();
}
public boolean setMiddle(PlotId plotId, Pattern blocks) { public boolean setMiddle(PlotId plotId, Pattern blocks) {
Plot plot = classicPlotWorld.getPlotAbs(plotId); Plot plot = classicPlotWorld.getPlotAbs(plotId);

View file

@ -28,8 +28,11 @@ package com.plotsquared.core.util;
import com.plotsquared.core.PlotSquared; import com.plotsquared.core.PlotSquared;
import com.plotsquared.core.location.Location; import com.plotsquared.core.location.Location;
import com.plotsquared.core.plot.Plot; 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.RunnableVal;
import com.plotsquared.core.util.task.TaskManager; import com.plotsquared.core.util.task.TaskManager;
import com.sk89q.worldedit.function.pattern.Pattern;
import com.sk89q.worldedit.math.BlockVector2; import com.sk89q.worldedit.math.BlockVector2;
import com.sk89q.worldedit.regions.CuboidRegion; import com.sk89q.worldedit.regions.CuboidRegion;
import com.sk89q.worldedit.world.biome.BiomeType; import com.sk89q.worldedit.world.biome.BiomeType;
@ -147,6 +150,19 @@ public abstract class RegionManager {
}); });
} }
public boolean setCuboids(final PlotArea area, final Set<CuboidRegion> 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) * Copy a region to a new location (in the same world)
*/ */