Skip to content

Commit

Permalink
Changes
Browse files Browse the repository at this point in the history
  • Loading branch information
TheAbsolutionism committed Nov 25, 2024
1 parent 93cf518 commit 3abfa08
Showing 1 changed file with 14 additions and 9 deletions.
23 changes: 14 additions & 9 deletions src/main/java/ch/njol/skript/sections/SecLoop.java
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@ public class SecLoop extends LoopSection {

private @Nullable TriggerItem actualNext;
private boolean guaranteedToLoop;
private Object nextValue = null;

@Override
@SuppressWarnings("unchecked")
Expand Down Expand Up @@ -125,21 +126,22 @@ protected TriggerItem walk(Event event) {
iter = expr instanceof Variable<?> variable ? variable.variablesIterator(event) : expr.iterator(event);
if (iter != null && iter.hasNext()) {
currentIter.put(event, iter);
next.put(event, iter.next());
} else {
iter = null;
}
}

if (iter == null || next.get(event) == null) {
if (iter == null || (!iter.hasNext() && nextValue == null)) {
exit(event);
debug(event, false);
return actualNext;
} else {
previous.put(event, current.get(event));
current.put(event, next.get(event));
if (iter.hasNext()) {
next.put(event, iter.next());
} else {
next.put(event, null);
if (nextValue != null) {
current.put(event, nextValue);
nextValue = null;
} else if (iter.hasNext()) {
current.put(event, iter.next());
}
currentLoopCounter.put(event, (currentLoopCounter.getOrDefault(event, 0L)) + 1);
return walk(event, true);
Expand All @@ -161,7 +163,11 @@ public String toString(@Nullable Event event, boolean debug) {
}

public @Nullable Object getNext(Event event) {
return next.get(event);
Iterator<?> iter = currentIter.get(event);
if (iter == null || !iter.hasNext())
return null;
nextValue = iter.next();
return nextValue;
}

public @Nullable Object getPrevious(Event event) {
Expand Down Expand Up @@ -189,7 +195,6 @@ public void exit(Event event) {
current.remove(event);
currentIter.remove(event);
previous.remove(event);
next.remove(event);
super.exit(event);
}

Expand Down

0 comments on commit 3abfa08

Please sign in to comment.