Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
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
38 changes: 38 additions & 0 deletions src/main/java/ch/njol/skript/effects/EffExit.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import ch.njol.skript.Skript;
import ch.njol.skript.classes.data.JavaClasses;
import ch.njol.skript.config.SectionNode;
import ch.njol.skript.doc.Description;
import ch.njol.skript.doc.Examples;
import ch.njol.skript.doc.Name;
Expand All @@ -15,6 +16,7 @@
import org.jetbrains.annotations.Nullable;
import org.jetbrains.annotations.UnknownNullability;

import java.util.Collection;
import java.util.List;

@Name("Exit")
Expand Down Expand Up @@ -88,6 +90,42 @@ public boolean init(Expression<?>[] exprs, int matchedPattern, Kleenean isDelaye
breakLevels = innerSections.size();
}
}

Collection<SectionNode> delaySections = getParser().getDelaySections();

if (getParser().getCurrentSection(TriggerSection.class) instanceof Section currentSection
&& currentSection.getNode() instanceof SectionNode currentNode) {

// set hasDelay to false if the only delayed section is the current one
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this safe in the following scenario? I don't think it is

loop 3 times:
    wait 1 tick # the loop is delayed
    exit loop # only this section is delayed, so we set delayed before to false
set damage to 2 # setting damage after event has passed

if (delaySections.size() == 1 && delaySections.contains(currentNode)) {
getParser().setHasDelayBefore(Kleenean.FALSE);
}
// set hasDelay to false if only child sections are delayed
else if (delaySections.size() >= 1) {
boolean isOnlyChildSectionsDelayed = true;
for (SectionNode delaySection : delaySections) {
if(delaySection == null)
continue;
// check if currentNode is parent of delaySection
boolean isChildSection = false;
SectionNode section = delaySection;
while (section.getParent() != null) {
section = section.getParent();
if (section == currentNode) {
isChildSection = true;
break;
}
}
if (!isChildSection) {
isOnlyChildSectionsDelayed = false;
break;
}
}
if (isOnlyChildSectionsDelayed)
getParser().setHasDelayBefore(Kleenean.FALSE);
}
}

assert innerSections != null;
sectionsToExit = innerSections.stream()
.filter(SectionExitHandler.class::isInstance)
Expand Down
1 change: 1 addition & 0 deletions src/main/java/ch/njol/skript/effects/EffTeleport.java
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ public boolean init(Expression<?>[] exprs, int matchedPattern, Kleenean isDelaye

if (async)
getParser().setHasDelayBefore(Kleenean.UNKNOWN); // UNKNOWN because it isn't async if the chunk is already loaded.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change

return true;
}

Expand Down
22 changes: 18 additions & 4 deletions src/main/java/ch/njol/skript/lang/parser/ParserInstance.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,8 @@
import ch.njol.skript.SkriptAPIException;
import ch.njol.skript.config.Config;
import ch.njol.skript.config.Node;
import ch.njol.skript.lang.Expression;
import ch.njol.skript.lang.SkriptEvent;
import ch.njol.skript.lang.SkriptParser;
import ch.njol.skript.lang.TriggerSection;
import ch.njol.skript.config.SectionNode;
import ch.njol.skript.lang.*;
import ch.njol.skript.log.HandlerList;
import ch.njol.skript.structures.StructOptions.OptionsData;
import ch.njol.skript.variables.HintManager;
Expand Down Expand Up @@ -400,6 +398,7 @@ public final boolean isCurrentSection(Class<? extends TriggerSection>... section
// Delay API

private Kleenean hasDelayBefore = Kleenean.FALSE;
private final Collection<SectionNode> delaySectionNodes = new HashSet<>();

/**
* This method should be called to indicate that
Expand All @@ -409,6 +408,14 @@ public final boolean isCurrentSection(Class<? extends TriggerSection>... section
*/
public void setHasDelayBefore(Kleenean hasDelayBefore) {
this.hasDelayBefore = hasDelayBefore;
if (hasDelayBefore == Kleenean.TRUE
&& getCurrentSection(TriggerSection.class) instanceof Section
&& getCurrentSection(Section.class).getNode() instanceof SectionNode sectionNode) {

delaySectionNodes.add(sectionNode);
} else if (hasDelayBefore == Kleenean.FALSE) {
delaySectionNodes.clear();
}
}

/**
Expand All @@ -422,6 +429,13 @@ public Kleenean getHasDelayBefore() {
return hasDelayBefore;
}

/**
* @return the sections from which a delay has occurred.
*/
public Collection<SectionNode> getDelaySections() {
return delaySectionNodes;
}

// Logging API

private final HandlerList handlers = new HandlerList();
Expand Down