diff --git a/Core/src/main/java/com/plotsquared/core/location/Direction.java b/Core/src/main/java/com/plotsquared/core/location/Direction.java
index eecfb6c37..1f66c4481 100644
--- a/Core/src/main/java/com/plotsquared/core/location/Direction.java
+++ b/Core/src/main/java/com/plotsquared/core/location/Direction.java
@@ -55,6 +55,25 @@ public enum Direction {
return NORTH;
}
+ /**
+ * {@return the opposite direction}
+ * If this is {@link Direction#ALL}, then {@link Direction#ALL} is returned.
+ * @since TODO
+ */
+ public Direction opposite() {
+ return switch (this) {
+ case ALL -> ALL;
+ case NORTH -> SOUTH;
+ case EAST -> WEST;
+ case SOUTH -> NORTH;
+ case WEST -> EAST;
+ case NORTHEAST -> SOUTHWEST;
+ case SOUTHEAST -> NORTHWEST;
+ case SOUTHWEST -> NORTHEAST;
+ case NORTHWEST -> SOUTHEAST;
+ };
+ }
+
public int getIndex() {
return index;
}
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 90e339308..4cd4b18ad 100644
--- a/Core/src/main/java/com/plotsquared/core/plot/Plot.java
+++ b/Core/src/main/java/com/plotsquared/core/plot/Plot.java
@@ -85,6 +85,7 @@ import java.util.ArrayDeque;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
+import java.util.Deque;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
@@ -2283,8 +2284,8 @@ public class Plot {
}
/**
- * Gets a set of plots connected (and including) this plot
- * - This result is cached globally
+ * Gets a set of plots connected (and including) this plot.
+ * The returned set is immutable.
*
* @return a Set of Plots connected to this Plot
*/
@@ -2295,117 +2296,75 @@ public class Plot {
if (!this.isMerged()) {
return Collections.singleton(this);
}
+ Plot basePlot = getBasePlot(false);
+ if (this.connectedCache == null && this != basePlot) {
+ // share cache between connected plots
+ Set connectedPlots = basePlot.getConnectedPlots();
+ this.connectedCache = connectedPlots;
+ return connectedPlots;
+ }
if (this.connectedCache != null && this.connectedCache.contains(this)) {
return this.connectedCache;
}
- HashSet tmpSet = new HashSet<>();
+ Set tmpSet = new HashSet<>();
tmpSet.add(this);
- Plot tmp;
- HashSet