Class Section.SectionContext

java.lang.Object
ch.njol.skript.lang.parser.ParserInstance.Data
ch.njol.skript.lang.Section.SectionContext
Enclosing class:
Section

public static class Section.SectionContext extends ParserInstance.Data
Data stored in the ParserInstance to keep track of the current section being parsed.
This is used to allow syntaxes to claim sections, and to provide the section node and trigger items to syntaxes that need them. Failure to correctly manage this context via modify(SectionNode, List, Supplier) may result in sections being double claimed or infinite parsing loops.
Most users should never need to interact with this class, only those dealing with manual parsing of expressions and similar behavior. Context is automatically handled in normal behavior via Statement.parse(String, String) and other similar methods.
  • Field Details

  • Constructor Details

    • SectionContext

      public SectionContext(ParserInstance parserInstance)
  • Method Details

    • modify

      public <T> T modify(SectionNode sectionNode, List<TriggerItem> triggerItems, Supplier<T> supplier)
      Modifies this SectionContext temporarily, for the duration of the Supplier.get() call, reverting the changes afterwards.
      This must be used instead of manually modifying the fields of this instance, unless you also revert the changes afterwards.
      See Pull Request #4353 and Issue #4473.
    • claim

      @Internal public <Syntax extends SyntaxElement & Debuggable> boolean claim(Syntax syntax)
      Marks the section this context represents as having been 'claimed' by the current syntax. Once a syntax has claimed a section, another syntax may not claim it.
      Parameters:
      syntax - The syntax that wants to own this section
      Returns:
      True if this was successfully claimed, false if it was already owned
    • claimed

      public boolean claimed()
      Used to keep track of whether a syntax is managing the current section. Every section needs exactly one manager. This is used to detect errors such as:
      1. Two syntax both want to manage the section (e.g. an effectsection and an expression or two expressions).
      2. No syntax wants to manage the section.
      Returns:
      Whether a syntax is already managing this section context