From 30867354cc5c45b7af3bb97e8c22b88dcdca465a Mon Sep 17 00:00:00 2001 From: Pierre Maurice Schwang Date: Sat, 22 Feb 2025 21:45:09 +0100 Subject: [PATCH] chore/fix: update iterator --- .../plotsquared/core/util/query/PlotProvider.java | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/Core/src/main/java/com/plotsquared/core/util/query/PlotProvider.java b/Core/src/main/java/com/plotsquared/core/util/query/PlotProvider.java index 110ed2d27..eee73b4c8 100644 --- a/Core/src/main/java/com/plotsquared/core/util/query/PlotProvider.java +++ b/Core/src/main/java/com/plotsquared/core/util/query/PlotProvider.java @@ -35,16 +35,19 @@ interface PlotProvider { Stream streamPlots(); default Stream streamPlotsInPlotAreas(PlotArea[] areas) { + if (areas == null || areas.length == 0) { + return Stream.of(); + } return StreamSupport.stream(Spliterators.spliteratorUnknownSize(new Iterator<>() { private int areaIndex = -1; private Iterator currentAreaPlots; @Override public boolean hasNext() { - if (currentAreaPlots == null) { - return areas.length > 0; - } - if (!currentAreaPlots.hasNext()) { - return ++areaIndex < areas.length - 1; + if (currentAreaPlots == null || !currentAreaPlots.hasNext()) { + if (areaIndex >= areas.length) { + return false; + } + currentAreaPlots = areas[++areaIndex].getPlots().iterator(); } return true; }