From 7f404e1cf50f7a675d8334d9efd8630ae8233bda Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Alexander=20Kriv=C3=A1cs=20Schr=C3=B8der?= Date: Sat, 1 Jun 2019 14:43:29 +0200 Subject: [PATCH] Fix plot walls after running regenallroads Also clears whatever was above the plot wall, such as pieces of the road. --- .../plot/generator/ClassicPlotManager.java | 32 +++++++++++++++++++ .../plot/generator/HybridUtils.java | 8 +++++ .../plotsquared/plot/object/PlotManager.java | 2 ++ .../plot/object/worlds/SinglePlotManager.java | 2 ++ .../plot/util/block/LocalBlockQueue.java | 24 ++++++++++---- 5 files changed, 62 insertions(+), 6 deletions(-) diff --git a/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/generator/ClassicPlotManager.java b/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/generator/ClassicPlotManager.java index 6d5e159f8..baa0575e3 100644 --- a/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/generator/ClassicPlotManager.java +++ b/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/generator/ClassicPlotManager.java @@ -250,17 +250,28 @@ public class ClassicPlotManager extends SquarePlotManager { Location top = plot.getExtendedTopAbs().add(1, 0, 1); LocalBlockQueue queue = classicPlotWorld.getQueue(false); int y = classicPlotWorld.WALL_HEIGHT + 1; + StringPlotBlock air = PlotBlock.get("air"); if (!plot.getMerged(Direction.NORTH)) { int z = bot.getZ(); for (int x = bot.getX(); x < top.getX(); x++) { queue.setBlock(x, y, z, blocks.getBlock()); } + // Replace all blocks above the wall with air + queue.setCuboid( + new Location(top.getWorld(), top.getX(), y + 1, bot.getZ()), + new Location(bot.getWorld(), bot.getX(), 255, bot.getZ()), + air); } if (!plot.getMerged(Direction.WEST)) { int x = bot.getX(); for (int z = bot.getZ(); z < top.getZ(); z++) { queue.setBlock(x, y, z, blocks.getBlock()); } + // Replace all blocks above the wall with air + queue.setCuboid( + new Location(top.getWorld(), bot.getX(), y + 1, top.getZ()), + new Location(bot.getWorld(), bot.getX(), 255, bot.getZ()), + air); } if (!plot.getMerged(Direction.SOUTH)) { int z = top.getZ(); @@ -268,6 +279,11 @@ public class ClassicPlotManager extends SquarePlotManager { x < top.getX() + (plot.getMerged(Direction.EAST) ? 0 : 1); x++) { queue.setBlock(x, y, z, blocks.getBlock()); } + // Replace all blocks above the wall with air + queue.setCuboid( + new Location(top.getWorld(), top.getX(), y + 1, top.getZ()), + new Location(bot.getWorld(), bot.getX(), 255, top.getZ()), + air); } if (!plot.getMerged(Direction.EAST)) { int x = top.getX(); @@ -275,6 +291,11 @@ public class ClassicPlotManager extends SquarePlotManager { z < top.getZ() + (plot.getMerged(Direction.SOUTH) ? 0 : 1); z++) { queue.setBlock(x, y, z, blocks.getBlock()); } + // Replace all blocks above the wall with air + queue.setCuboid( + new Location(top.getWorld(), top.getX(), y + 1, top.getZ()), + new Location(bot.getWorld(), top.getX(), 255, bot.getZ()), + air); } queue.enqueue(); return true; @@ -439,6 +460,17 @@ public class ClassicPlotManager extends SquarePlotManager { return true; } + @Override public boolean regenerateAllPlotWalls() { + for (Plot plot : classicPlotWorld.getPlots()) { + if (plot.hasOwner()) { + setWall(plot.getId(), classicPlotWorld.CLAIMED_WALL_BLOCK); + } else { + setWall(plot.getId(), classicPlotWorld.WALL_BLOCK); + } + } + return true; + } + @Override public boolean startPlotMerge(List plotIds) { return true; } diff --git a/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/generator/HybridUtils.java b/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/generator/HybridUtils.java index f98d6ae88..a586af012 100644 --- a/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/generator/HybridUtils.java +++ b/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/generator/HybridUtils.java @@ -153,6 +153,9 @@ public abstract class HybridUtils { PlotSquared.debug("PROGRESS: " + 100 * (2048 - chunks.size()) / 2048 + "%"); } if (regions.isEmpty() && chunks.isEmpty()) { + PlotSquared.debug("&3Regenerating plot walls"); + regeneratePlotWalls(area); + HybridUtils.UPDATE = false; PlotSquared.debug(Captions.PREFIX.s() + "Finished road conversion"); // CANCEL TASK @@ -377,4 +380,9 @@ public abstract class HybridUtils { } return false; } + + public boolean regeneratePlotWalls(final PlotArea area) { + PlotManager plotManager = area.getPlotManager(); + return plotManager.regenerateAllPlotWalls(); + } } diff --git a/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/object/PlotManager.java b/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/object/PlotManager.java index ac2a57058..74f0eddb7 100644 --- a/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/object/PlotManager.java +++ b/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/object/PlotManager.java @@ -85,4 +85,6 @@ public abstract class PlotManager { return 255; } + public abstract boolean regenerateAllPlotWalls(); + } diff --git a/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/object/worlds/SinglePlotManager.java b/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/object/worlds/SinglePlotManager.java index 9998f88f2..0c5a7e866 100644 --- a/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/object/worlds/SinglePlotManager.java +++ b/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/object/worlds/SinglePlotManager.java @@ -107,4 +107,6 @@ public class SinglePlotManager extends PlotManager { @Override public boolean finishPlotUnlink(List plotIds) { return false; } + + @Override public boolean regenerateAllPlotWalls() { return false; } } diff --git a/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/util/block/LocalBlockQueue.java b/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/util/block/LocalBlockQueue.java index 87c0fec56..53196966e 100644 --- a/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/util/block/LocalBlockQueue.java +++ b/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/util/block/LocalBlockQueue.java @@ -97,9 +97,15 @@ public abstract class LocalBlockQueue { } public void setCuboid(Location pos1, Location pos2, PlotBlock block) { - for (int y = pos1.getY(); y <= Math.min(255, pos2.getY()); y++) { - for (int x = pos1.getX(); x <= pos2.getX(); x++) { - for (int z = pos1.getZ(); z <= pos2.getZ(); z++) { + int yMin = Math.min(pos1.getY(), pos2.getY()); + int yMax = Math.min(255, Math.max(pos1.getY(), pos2.getY())); + int xMin = Math.min(pos1.getX(), pos2.getX()); + int xMax = Math.max(pos1.getX(), pos2.getX()); + int zMin = Math.min(pos1.getZ(), pos2.getZ()); + int zMax = Math.max(pos1.getZ(), pos2.getZ()); + for (int y = yMin; y <= yMax; y++) { + for (int x = xMin; x <= xMax; x++) { + for (int z = zMin; z <= zMax; z++) { setBlock(x, y, z, block); } } @@ -107,9 +113,15 @@ public abstract class LocalBlockQueue { } public void setCuboid(Location pos1, Location pos2, BlockBucket blocks) { - for (int y = pos1.getY(); y <= Math.min(255, pos2.getY()); y++) { - for (int x = pos1.getX(); x <= pos2.getX(); x++) { - for (int z = pos1.getZ(); z <= pos2.getZ(); z++) { + int yMin = Math.min(pos1.getY(), pos2.getY()); + int yMax = Math.min(255, Math.max(pos1.getY(), pos2.getY())); + int xMin = Math.min(pos1.getX(), pos2.getX()); + int xMax = Math.max(pos1.getX(), pos2.getX()); + int zMin = Math.min(pos1.getZ(), pos2.getZ()); + int zMax = Math.max(pos1.getZ(), pos2.getZ()); + for (int y = yMin; y <= yMax; y++) { + for (int x = xMin; x <= xMax; x++) { + for (int z = zMin; z <= zMax; z++) { setBlock(x, y, z, blocks.getBlock()); } }