Skip to content

Commit

Permalink
Fix conditionals with inline conditions or exit section effects (#4175)
Browse files Browse the repository at this point in the history
  • Loading branch information
TPGamesNL authored Jul 10, 2021
1 parent 64d0a67 commit ef7f9a2
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 6 deletions.
27 changes: 21 additions & 6 deletions src/main/java/ch/njol/skript/sections/SecConditional.java
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ public boolean init(Expression<?>[] exprs,

// Change event if using 'parse if'
if (parseIf) {
//noinspection unchecked
parser.setCurrentEvents(new Class[]{SkriptParseEvent.class});
parser.setCurrentEventName("parse");
parser.setCurrentSkriptEvent(null);
Expand Down Expand Up @@ -145,25 +146,39 @@ && getElseIfs(triggerItems).stream().map(SecConditional::getHasDelayAfter).allMa
return true;
}

@Override
@Nullable
public TriggerItem getNext() {
return getSkippedNext();
}

@Nullable
public TriggerItem getNormalNext() {
return super.getNext();
}

@Nullable
@Override
protected TriggerItem walk(Event e) {
if (parseIf && !parseIfPassed) {
return getNext();
return getNormalNext();
} else if (type == ConditionalType.ELSE || parseIf || condition.check(e)) {
TriggerItem skippedNext = getSkippedNext();
setNext(skippedNext);

if (last != null)
last.setNext(getSkippedNext());
return first != null ? first : getSkippedNext();
last.setNext(skippedNext);
return first != null ? first : skippedNext;
} else {
return getNext();
return getNormalNext();
}
}

@Nullable
private TriggerItem getSkippedNext() {
TriggerItem next = getNext();
TriggerItem next = getNormalNext();
while (next instanceof SecConditional && ((SecConditional) next).type != ConditionalType.IF)
next = next.getNext();
next = ((SecConditional) next).getNormalNext();
return next;
}

Expand Down
19 changes: 19 additions & 0 deletions src/test/skript/tests/syntaxes/sections/SecConditional.sk
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,22 @@ test "SecConditional - ParseIf":
else:
#this code in this section SHOULD be parsed but should NOT be ran
assert 10 = 1 with "ParseIf/Else section was parsed and failed"

test "SecConditional":
set {_b} to true
if 1 is 1:
delete {_b}
1 = 2
else if 1 = 1:
assert 1 = 2 with "conditional failed ##1"
else:
assert 1 = 2 with "conditional failed ##2"
if {_b} is set:
assert 1 = 2 with "conditional failed ##3"

if 1 = 2:
assert 1 = 2 with "conditional failed ##4"
else if 1 = 1:
exit 1 section
else:
assert 1 = 2 with "conditional failed ##5"

0 comments on commit ef7f9a2

Please sign in to comment.