Skip to content

Commit c9965d4

Browse files
sovdeetherenkarakal
authored andcommitted
Expose SectionContext (SkriptLang#8158)
1 parent 6ceb45c commit c9965d4

1 file changed

Lines changed: 13 additions & 3 deletions

File tree

src/main/java/ch/njol/skript/lang/Section.java

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -196,8 +196,18 @@ public static Section parse(String expr, @Nullable String defaultError, SectionN
196196
ParserInstance.registerData(SectionContext.class, SectionContext::new);
197197
}
198198

199-
@SuppressWarnings("NotNullFieldNotInitialized")
200-
protected static class SectionContext extends ParserInstance.Data {
199+
/**
200+
* Data stored in the {@link ParserInstance} to keep track of the current section being parsed.
201+
* <br>
202+
* This is used to allow syntaxes to claim sections, and to provide the section node and trigger items
203+
* to syntaxes that need them. Failure to correctly manage this context via {@link #modify(SectionNode, List, Supplier)}
204+
* may result in sections being double claimed or infinite parsing loops.
205+
* <br>
206+
* Most users should never need to interact with this class, only those dealing with manual parsing of expressions
207+
* and similar behavior. Context is automatically handled in normal behavior via {@link Statement#parse(String, String)}
208+
* and other similar methods.
209+
*/
210+
public static class SectionContext extends ParserInstance.Data {
201211

202212
protected SectionNode sectionNode;
203213
protected List<TriggerItem> triggerItems;
@@ -216,7 +226,7 @@ public SectionContext(ParserInstance parserInstance) {
216226
* <br>
217227
* See <a href="https://github.com/SkriptLang/Skript/pull/4353">Pull Request #4353</a> and <a href="https://github.com/SkriptLang/Skript/issues/4473">Issue #4473</a>.
218228
*/
219-
protected <T> T modify(SectionNode sectionNode, List<TriggerItem> triggerItems, Supplier<T> supplier) {
229+
public <T> T modify(SectionNode sectionNode, List<TriggerItem> triggerItems, Supplier<T> supplier) {
220230
SectionNode prevSectionNode = this.sectionNode;
221231
List<TriggerItem> prevTriggerItems = this.triggerItems;
222232
Debuggable owner = this.owner;

0 commit comments

Comments
 (0)