From c25a0c65a2b430a017df81609f8c1cb9e4cbf2b9 Mon Sep 17 00:00:00 2001 From: SirYwell Date: Tue, 7 Sep 2021 09:32:34 +0200 Subject: [PATCH] Don't check same plot over and over again --- .../com/plotsquared/core/services/plots/AutoService.java | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/Core/src/main/java/com/plotsquared/core/services/plots/AutoService.java b/Core/src/main/java/com/plotsquared/core/services/plots/AutoService.java index 85958ebfb..765e3394a 100644 --- a/Core/src/main/java/com/plotsquared/core/services/plots/AutoService.java +++ b/Core/src/main/java/com/plotsquared/core/services/plots/AutoService.java @@ -139,13 +139,18 @@ public interface AutoService extends Service> @Override public List handle(@NonNull AutoQuery autoQuery) { Plot plot; + PlotId nextId = autoQuery.getStartId(); do { synchronized (plotLock) { - plot = autoQuery.getPlotArea().getNextFreePlot(autoQuery.getPlayer(), autoQuery.getStartId()); + plot = autoQuery.getPlotArea().getNextFreePlot(autoQuery.getPlayer(), nextId); if (plot != null && plotCandidateCache.getIfPresent(plot.getId()) == null) { plotCandidateCache.put(plot.getId(), plot); return Collections.singletonList(plot); } + // if the plot is already in the cache, we want to make sure we skip it the next time + if (plot != null) { + nextId = plot.getId(); + } } } while (plot != null); return null;