Skip to content

Commit

Permalink
Implement changes from SkriptLang/Skript#4175
Browse files Browse the repository at this point in the history
  • Loading branch information
Matocolotoe committed Aug 26, 2021
1 parent ec55e57 commit efe23dd
Showing 1 changed file with 23 additions and 8 deletions.
31 changes: 23 additions & 8 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 @@ -125,8 +126,8 @@ public boolean init(Expression<?>[] exprs,
if (type == ConditionalType.ELSE) {
// In an else section, ...
if (hasDelayAfter.isTrue()
&& lastIf.hasDelayAfter.isTrue()
&& getElseIfs(triggerItems).stream().map(SecConditional::getHasDelayAfter).allMatch(Kleenean::isTrue)) {
&& lastIf.hasDelayAfter.isTrue()
&& getElseIfs(triggerItems).stream().map(SecConditional::getHasDelayAfter).allMatch(Kleenean::isTrue)) {
// ... if the if section, all else-if sections and the else section have definite delays,
// mark delayed as TRUE.
getParser().setHasDelayBefore(Kleenean.TRUE);
Expand All @@ -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

0 comments on commit efe23dd

Please sign in to comment.