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 current section update issues #6845

Merged
merged 4 commits into from
Jul 1, 2024
Merged
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
12 changes: 9 additions & 3 deletions src/main/java/ch/njol/skript/lang/Section.java
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
import org.bukkit.event.Event;
import org.eclipse.jdt.annotation.Nullable;

import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import java.util.function.Supplier;
Expand Down Expand Up @@ -81,12 +82,17 @@ public abstract boolean init(Expression<?>[] expressions,
* (although the loaded code may change it), the calling code must deal with this.
*/
protected void loadCode(SectionNode sectionNode) {
List<TriggerSection> currentSections = getParser().getCurrentSections();
currentSections.add(this);
ParserInstance parser = getParser();
List<TriggerSection> previousSections = parser.getCurrentSections();

List<TriggerSection> sections = new ArrayList<>(previousSections);
sections.add(this);
parser.setCurrentSections(sections);

try {
setTriggerItems(ScriptLoader.loadItems(sectionNode));
} finally {
currentSections.remove(currentSections.size() - 1);
parser.setCurrentSections(previousSections);
}
}

Expand Down
12 changes: 9 additions & 3 deletions src/main/java/ch/njol/skript/lang/TriggerSection.java
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
import org.bukkit.event.Event;
import org.eclipse.jdt.annotation.Nullable;

import java.util.ArrayList;
import java.util.List;

/**
Expand All @@ -42,12 +43,17 @@ protected TriggerSection(List<TriggerItem> items) {
}

protected TriggerSection(SectionNode node) {
List<TriggerSection> currentSections = ParserInstance.get().getCurrentSections();
currentSections.add(this);
ParserInstance parser = ParserInstance.get();
List<TriggerSection> previousSections = parser.getCurrentSections();

List<TriggerSection> sections = new ArrayList<>(previousSections);
sections.add(this);
parser.setCurrentSections(sections);

try {
setTriggerItems(ScriptLoader.loadItems(node));
} finally {
currentSections.remove(currentSections.size() - 1);
parser.setCurrentSections(previousSections);
}
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
test "outdated current section references":
parse:
loop {_list::*}:
spawn a sheep at {_loc}:
set {_e} to event-entity
loop {_list::*}:
set {_var} to loop-value
set {_var} to loop-value-1
assert last parse logs is not set with "loop-value and loop-value-1 should've worked"