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;