Class SectionUtils

java.lang.Object
ch.njol.skript.lang.util.SectionUtils

public final class SectionUtils extends Object
Utility methods for working with Sections and SectionExpressions.
  • Method Details

    • loadLinkedCode

      @Nullable public static @Nullable Trigger loadLinkedCode(String name, BiFunction<Runnable,Runnable,Trigger> triggerSupplier)
      This method is used for loading a section into a Trigger under different context (Events). However, unlike the traditional methods such as Section.loadCode(SectionNode, String, Runnable, Runnable, Class[]), this method assumes some level of linkage between the returned trigger and the section it was loaded from. These assumptions are:
      • Local variables (and at parse time, type hints) will be shared between the two sections.
      • Delays within the trigger are not permitted.
      As a result, this method takes action to ensure that type hints are shared and that delays are not permitted. At runtime, local variables will need to be copied by the caller using a method such as Variables.withLocalVariables(Event, Event, Runnable)
      Parameters:
      name - The name of the section being loaded.
      triggerSupplier - A function to load code using a trigger. The function has two runnable arguments. When using a method like Section.loadCode(SectionNode, String, Runnable, Runnable, Class[]), the runnable arguments represent the parameters beforeLoading and afterLoading, respectively. It is imperative that these runnable arguments be passed. If the method you are using does not support those arguments, use a different method.
      Returns:
      The result of triggerSupplier, or null if some issue occurred.
    • loadDelayableLinkedCode

      @Nullable public static @Nullable Trigger loadDelayableLinkedCode(String name, BiFunction<Runnable,Runnable,Trigger> triggerSupplier)
      A variant of loadLinkedCode(String, BiFunction) that permits delays within the loaded trigger. Type hints are still shared with the outer section, but delays inside the body do not cause a parse-time error. The caller is responsible for correctly handling any delays encountered while executing the returned trigger (e.g. by scheduling execution asynchronously or on a separate tick).
      Parameters:
      name - The name of the section being loaded.
      triggerSupplier - A function to load code using a trigger. See loadLinkedCode(String, BiFunction) for details on the expected behavior of this supplier.
      Returns:
      The result of triggerSupplier, or null if some issue occurred.
      See Also: