Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix conditionals with inline conditions or exit section effects #4175

Merged
merged 3 commits into from
Jul 10, 2021
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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