From 8d55304242eb6be2b91c51e1817605bb0ead1fd7 Mon Sep 17 00:00:00 2001
From: TheMeinerLP
Date: Wed, 3 May 2023 22:28:35 +0200
Subject: [PATCH] Add a meta to hold current process of plot merge
---
.../bukkit/listener/BlockEventListener.java | 2 +-
.../java/com/plotsquared/core/plot/Plot.java | 26 +++++++++++++++++++
.../core/plot/PlotModificationManager.java | 16 ++++++++++++
3 files changed, 43 insertions(+), 1 deletion(-)
diff --git a/Bukkit/src/main/java/com/plotsquared/bukkit/listener/BlockEventListener.java b/Bukkit/src/main/java/com/plotsquared/bukkit/listener/BlockEventListener.java
index 8ae570bd15..78bb2e82da 100644
--- a/Bukkit/src/main/java/com/plotsquared/bukkit/listener/BlockEventListener.java
+++ b/Bukkit/src/main/java/com/plotsquared/bukkit/listener/BlockEventListener.java
@@ -341,7 +341,7 @@ public void blockDestroy(BlockBreakEvent event) {
return;
}
Plot plot = area.getPlot(location);
- if (plot != null) {
+ if (plot != null && !plot.isMerging()) {
BukkitPlayer plotPlayer = BukkitUtil.adapt(player);
// == rather than <= as we only care about the "ground level" not being destroyed
if (event.getBlock().getY() == area.getMinGenHeight()) {
diff --git a/Core/src/main/java/com/plotsquared/core/plot/Plot.java b/Core/src/main/java/com/plotsquared/core/plot/Plot.java
index b1c7c1f6a3..6d53167186 100644
--- a/Core/src/main/java/com/plotsquared/core/plot/Plot.java
+++ b/Core/src/main/java/com/plotsquared/core/plot/Plot.java
@@ -1244,6 +1244,32 @@ public int addRunning() {
return value;
}
+ /**
+ * Sets the plot into merging process
+ */
+ public void setMerging() {
+ for (Plot plot : this.getConnectedPlots()) {
+ plot.setMeta("merging", true);
+ }
+ }
+
+ /**
+ * @return the current state of merging process
+ */
+ public Boolean isMerging() {
+ Boolean value = (Boolean) this.getMeta("merging");
+ return value != null && value;
+ }
+
+ /**
+ * Removes the merging process
+ */
+ public void removeMerging() {
+ for (Plot plot : this.getConnectedPlots()) {
+ plot.deleteMeta("merging");
+ }
+ }
+
/**
* Decrement the number of tracked tasks this plot is running
* - Used to track/limit the number of things a player can do on the plot at once
diff --git a/Core/src/main/java/com/plotsquared/core/plot/PlotModificationManager.java b/Core/src/main/java/com/plotsquared/core/plot/PlotModificationManager.java
index 81a2f740b4..843fb506a2 100644
--- a/Core/src/main/java/com/plotsquared/core/plot/PlotModificationManager.java
+++ b/Core/src/main/java/com/plotsquared/core/plot/PlotModificationManager.java
@@ -582,6 +582,8 @@ public boolean autoMerge(
Plot other = current.getRelative(Direction.NORTH);
if (other != null && other.isOwner(uuid) && (other.getBasePlot(false).equals(current.getBasePlot(false))
|| (plots = other.getConnectedPlots()).size() <= max && frontier.addAll(plots) && (max -= plots.size()) != -1)) {
+ current.setMerging();
+ other.setMerging();
current.mergePlot(other, removeRoads, queue);
merged.add(current.getId());
merged.add(other.getId());
@@ -593,12 +595,16 @@ public boolean autoMerge(
ids.add(other.getId());
this.plot.getManager().finishPlotMerge(ids, queue);
}
+ current.removeMerging();
+ other.removeMerging();
}
}
if (max >= 0 && (dir == Direction.ALL || dir == Direction.EAST) && !current.isMerged(Direction.EAST)) {
Plot other = current.getRelative(Direction.EAST);
if (other != null && other.isOwner(uuid) && (other.getBasePlot(false).equals(current.getBasePlot(false))
|| (plots = other.getConnectedPlots()).size() <= max && frontier.addAll(plots) && (max -= plots.size()) != -1)) {
+ current.setMerging();
+ other.setMerging();
current.mergePlot(other, removeRoads, queue);
merged.add(current.getId());
merged.add(other.getId());
@@ -610,12 +616,16 @@ public boolean autoMerge(
ids.add(other.getId());
this.plot.getManager().finishPlotMerge(ids, queue);
}
+ current.removeMerging();
+ other.removeMerging();
}
}
if (max >= 0 && (dir == Direction.ALL || dir == Direction.SOUTH) && !current.isMerged(Direction.SOUTH)) {
Plot other = current.getRelative(Direction.SOUTH);
if (other != null && other.isOwner(uuid) && (other.getBasePlot(false).equals(current.getBasePlot(false))
|| (plots = other.getConnectedPlots()).size() <= max && frontier.addAll(plots) && (max -= plots.size()) != -1)) {
+ current.setMerging();
+ other.setMerging();
current.mergePlot(other, removeRoads, queue);
merged.add(current.getId());
merged.add(other.getId());
@@ -627,12 +637,16 @@ public boolean autoMerge(
ids.add(other.getId());
this.plot.getManager().finishPlotMerge(ids, queue);
}
+ current.removeMerging();
+ other.removeMerging();
}
}
if (max >= 0 && (dir == Direction.ALL || dir == Direction.WEST) && !current.isMerged(Direction.WEST)) {
Plot other = current.getRelative(Direction.WEST);
if (other != null && other.isOwner(uuid) && (other.getBasePlot(false).equals(current.getBasePlot(false))
|| (plots = other.getConnectedPlots()).size() <= max && frontier.addAll(plots) && (max -= plots.size()) != -1)) {
+ current.setMerging();
+ other.setMerging();
current.mergePlot(other, removeRoads, queue);
merged.add(current.getId());
merged.add(other.getId());
@@ -644,6 +658,8 @@ public boolean autoMerge(
ids.add(other.getId());
this.plot.getManager().finishPlotMerge(ids, queue);
}
+ current.removeMerging();
+ other.removeMerging();
}
}
}