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

    • sectionNode

      protected SectionNode sectionNode
    • triggerItems

      protected List<TriggerItem> triggerItems
    • owner

      @Nullable protected @Nullable Debuggable owner
    • ownerErrorRepresentation

      @Nullable protected @Nullable String ownerErrorRepresentation
  • 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.
    • attemptClaim

      @Internal public <Syntax extends SyntaxElement & Debuggable> boolean attemptClaim(Syntax syntax, String errorRepresentation, BiFunction<Section.SectionContext,Syntax,Boolean> runIfClaimed)
      Attempts to claim the section this context represents for the given syntax. If the claim is successful, the provided function will be run. If the function returns false, the claim will be reverted. Once a syntax has claimed a section, another syntax may not claim it.
      Parameters:
      syntax - The syntax that wants to own this section. This will likely not yet be initialized.
      errorRepresentation - A string representation of the syntax for error messages, as Debuggable.toString(Event, boolean) cannot be used yet.
      runIfClaimed - A function that will be run if the claim was successful. Usually this is the syntax's init method.
      Returns:
      True if this was successfully claimed and the provided function ran successfully, false otherwise
    • claim

      @Internal public <Syntax extends SyntaxElement & Debuggable> boolean claim(Syntax syntax, String errorRepresentation)
      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. This will likely not yet be initialized.
      errorRepresentation - A string representation of the syntax for error messages, as Debuggable.toString(Event, boolean) cannot be used yet.
      Returns:
      True if this was successfully claimed, false if it was already owned
    • unclaim

      @Internal public <Syntax extends SyntaxElement & Debuggable> void unclaim(Syntax syntax)
      Removes this syntax's claim on this section. A new syntax may claim it later.
      Parameters:
      syntax - The syntax that wants to unclaim this section
    • 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