Skip to content

Commit

Permalink
Add comments to SecLoop#guaranteedToLoop
Browse files Browse the repository at this point in the history
  • Loading branch information
UnderscoreTud committed Sep 4, 2024
1 parent ce79b11 commit 501253d
Showing 1 changed file with 7 additions and 0 deletions.
7 changes: 7 additions & 0 deletions src/main/java/ch/njol/skript/sections/SecLoop.java
Original file line number Diff line number Diff line change
Expand Up @@ -188,11 +188,15 @@ public void exit(Event event) {
}

private static boolean guaranteedToLoop(Expression<?> expression) {
// If the expression is a literal, it's guaranteed to loop if it has at least one value
if (expression instanceof Literal<?> literal)
return literal.getAll().length > 0;

// If the expression isn't a list, then we can't guarantee that it will loop
if (!(expression instanceof ExpressionList<?> list))
return false;

// If the list is an OR list (a, b or c), then it's guaranteed to loop iff all its values are guaranteed to loop
if (!list.getAnd()) {
for (Expression<?> expr : list.getExpressions()) {
if (!guaranteedToLoop(expr))
Expand All @@ -201,10 +205,13 @@ private static boolean guaranteedToLoop(Expression<?> expression) {
return true;
}

// If the list is an AND list (a, b and c), then it's guaranteed to loop if any of its values are guaranteed to loop
for (Expression<?> expr : list.getExpressions()) {
if (guaranteedToLoop(expr))
return true;
}

// Otherwise, we can't guarantee that it will loop
return false;
}

Expand Down

0 comments on commit 501253d

Please sign in to comment.