Class Section

All Implemented Interfaces:
Debuggable, SyntaxElement
Direct Known Subclasses:
EffectSection

public abstract class Section extends TriggerSection implements SyntaxElement
A section that can decide what it does with its contents, as code isn't parsed by default.

In most cases though, a section should load its code through one of the following loading methods: loadCode(SectionNode), loadCode(SectionNode, String, Class[]), loadOptionalCode(SectionNode)

Every section must override the TriggerSection.walk(Event) method. In this method, you can determine whether or not the section should run. If you have stored a Trigger from loadCode(SectionNode, String, Class[]), you should not run it with this event passed in this walk method.

In the walk method, it is recommended that you return TriggerSection.walk(Event, boolean). This method is very useful, as it will handle most of the things you need to do. The boolean parameter for the method determines whether or not the section should run. If it is true, Skript will attempt to run the section's code if it has been loaded. If the section's code hasn't be loaded, Skript will behave as if false was passed. If it is false, Skript will just move onto the next syntax element after this section. So, if you are using a normal section and your code should run immediately, you should just return the result of this method with true for the parameter. However, in cases where you have loaded your code into a trigger using loadCode(SectionNode, String, Class[]), it does not matter if true or false is passed, as the section's code was never actually loaded into the current trigger. Please note that this will result in all code after the section to run. If you wish to delay the entire execution, you should return null and Skript will not continue on. You should generally make sure that code after the section will run at some point though. Also note, that if you aren't returning the result of TriggerSection.walk(Event, boolean), you should probably call TriggerItem.debug(Event, boolean). The boolean parameter should be false in most cases.
See Also:
  • Constructor Details

    • Section

      public Section()
  • Method Details

    • init

      public boolean init(Expression<?>[] exprs, int matchedPattern, Kleenean isDelayed, SkriptParser.ParseResult parseResult)
      This method should not be overridden unless you know what you are doing!
      Specified by:
      init in interface SyntaxElement
      Parameters:
      exprs - all %expr%s included in the matching pattern in the order they appear in the pattern. If an optional value was left out it will still be included in this list holding the default value of the desired type which usually depends on the event.
      matchedPattern - The index of the pattern which matched
      isDelayed - Whether this expression is used after a delay or not (i.e. if the event has already passed when this expression will be called)
      parseResult - Additional information about the match.
      Returns:
      Whether this expression was initialised successfully. An error should be printed prior to returning false to specify the cause.
      See Also:
    • init

      public abstract boolean init(Expression<?>[] exprs, int matchedPattern, Kleenean isDelayed, SkriptParser.ParseResult parseResult, SectionNode sectionNode, List<TriggerItem> triggerItems)
    • loadCode

      protected void loadCode(SectionNode sectionNode)
      Loads the code in the given SectionNode, appropriately modifying ParserInstance.getCurrentSections().
      This method itself does not modify ParserInstance.getHasDelayBefore() (although the loaded code may change it), the calling code must deal with this.
    • loadCode

      @SafeVarargs protected final Trigger loadCode(SectionNode sectionNode, String name, Class<? extends org.bukkit.event.Event>... events)
      Loads the code in the given SectionNode, appropriately modifying ParserInstance.getCurrentSections(). This method differs from loadCode(SectionNode) in that it is meant for code that will be executed in a different event.
      Parameters:
      sectionNode - The section node to load.
      name - The name of the event(s) being used.
      events - The event(s) during the section's execution.
      Returns:
      A trigger containing the loaded section. This should be stored and used to run the section one or more times.
    • loadCode

      @SafeVarargs protected final Trigger loadCode(SectionNode sectionNode, String name, @Nullable Runnable afterLoading, Class<? extends org.bukkit.event.Event>... events)
      Loads the code in the given SectionNode, appropriately modifying ParserInstance.getCurrentSections(). This method differs from loadCode(SectionNode) in that it is meant for code that will be executed in a different event.
      Parameters:
      sectionNode - The section node to load.
      name - The name of the event(s) being used.
      afterLoading - A Runnable to execute after the SectionNode has been loaded. This occurs before ParserInstance states are reset.
      events - The event(s) during the section's execution.
      Returns:
      A trigger containing the loaded section. This should be stored and used to run the section one or more times.
    • loadOptionalCode

      protected void loadOptionalCode(SectionNode sectionNode)
      Loads the code using loadCode(SectionNode).
      This method also adjusts ParserInstance.getHasDelayBefore() to expect the code to be called zero or more times. This is done by setting hasDelayBefore to Kleenean.UNKNOWN if the loaded section has a possible or definite delay in it.
    • parse

      public static @Nullable Section parse(String expr, @Nullable String defaultError, SectionNode sectionNode, List<TriggerItem> triggerItems)