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 fba3c6179..cc4dc4047 100644 --- a/Core/src/main/java/com/plotsquared/core/plot/Plot.java +++ b/Core/src/main/java/com/plotsquared/core/plot/Plot.java @@ -125,9 +125,6 @@ public class Plot { private static final MiniMessage MINI_MESSAGE = MiniMessage.builder().build(); private static final Cleaner CLEANER = Cleaner.create(); - static Set connected_cache; - static Set regions_cache; - static { FLAG_DECIMAL_FORMAT.setMaximumFractionDigits(340); } @@ -210,6 +207,8 @@ public class Plot { */ private Plot origin; + private Set connectedCache; + /** * Constructor for a new plot. * (Only changes after plot.create() will be properly set in the database) @@ -2131,17 +2130,16 @@ public class Plot { this.origin.origin = base; other.origin = base; this.origin = base; - connected_cache = null; + this.connectedCache = null; } } else { if (this.origin != null) { this.origin.origin = null; this.origin = null; } - connected_cache = null; + this.connectedCache = null; } DBFunc.setMerged(this, this.getSettings().getMerged()); - regions_cache = null; } } @@ -2176,8 +2174,7 @@ public class Plot { } public void clearCache() { - connected_cache = null; - regions_cache = null; + this.connectedCache = null; if (this.origin != null) { this.origin.origin = null; this.origin = null; @@ -2327,12 +2324,11 @@ public class Plot { event.commit(); return Collections.singleton(this); } - if (connected_cache != null && connected_cache.contains(this)) { - event.mergedSize = connected_cache.size(); + if (this.connectedCache != null && this.connectedCache.contains(this)) { + event.mergedSize = this.connectedCache.size(); event.commit(); - return connected_cache; + return this.connectedCache; } - regions_cache = null; HashSet tmpSet = new HashSet<>(); tmpSet.add(this); @@ -2437,7 +2433,7 @@ public class Plot { } } } - connected_cache = tmpSet; + this.connectedCache = tmpSet; event.mergedSize = tmpSet.size(); event.cacheMiss = true; event.commit(); @@ -2452,19 +2448,15 @@ public class Plot { * @return all regions within the plot */ public @NonNull Set getRegions() { - if (regions_cache != null && connected_cache != null && connected_cache.contains(this)) { - return regions_cache; - } if (!this.isMerged()) { Location pos1 = this.getBottomAbs().withY(getArea().getMinBuildHeight()); Location pos2 = this.getTopAbs().withY(getArea().getMaxBuildHeight()); - connected_cache = Sets.newHashSet(this); + this.connectedCache = Sets.newHashSet(this); CuboidRegion rg = new CuboidRegion(pos1.getBlockVector3(), pos2.getBlockVector3()); - regions_cache = Collections.singleton(rg); - return regions_cache; + return Collections.singleton(rg); } Set plots = this.getConnectedPlots(); - Set regions = regions_cache = new HashSet<>(); + Set regions = new HashSet<>(); Set visited = new HashSet<>(); for (Plot current : plots) { if (visited.contains(current.getId())) { 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 61658391f..7bbba4e1f 100644 --- a/Core/src/main/java/com/plotsquared/core/plot/PlotModificationManager.java +++ b/Core/src/main/java/com/plotsquared/core/plot/PlotModificationManager.java @@ -327,6 +327,7 @@ public final class PlotModificationManager { ArrayList ids = new ArrayList<>(plots.size()); for (Plot current : plots) { current.setHome(null); + current.clearCache(); ids.add(current.getId()); } this.plot.clearRatings(); @@ -478,8 +479,7 @@ public final class PlotModificationManager { this.plot.updateWorldBorder(); } } - Plot.connected_cache = null; - Plot.regions_cache = null; + this.plot.clearCache(); this.plot.getTrusted().clear(); this.plot.getMembers().clear(); this.plot.getDenied().clear(); @@ -630,6 +630,7 @@ public final class PlotModificationManager { if (queue.size() > 0) { queue.enqueue(); } + visited.forEach(Plot::clearCache); return toReturn; }