Class SectionValue<S extends ArgumentSection, T>

java.lang.Object
io.github.syst3ms.skriptparser.lang.lambda.SectionValue<S,T>
Type Parameters:
S - the type of the section from which to retrieve arguments
T - the return value of the expression
All Implemented Interfaces:
Expression<T>, SyntaxElement
Direct Known Subclasses:
ExprLoopValue, ExprSingleParameter

public abstract class SectionValue<S extends ArgumentSection, T> extends Object implements Expression<T>
An expression that is tied to a given ArgumentSection, and acts as a way to retrieve the arguments passed through an Expression.
  • Constructor Details

    • SectionValue

      public SectionValue()
  • Method Details

    • init

      public boolean init(Expression<?>[] expressions, int matchedPattern, ParseContext parseContext)
      Description copied from interface: SyntaxElement
      Initializes this SyntaxElement before being used. This method is always called before all the others in an extending class, the only exception being CodeSection.loadSection(FileSection, ParserState, SkriptLogger).
      Specified by:
      init in interface SyntaxElement
      Parameters:
      expressions - an array of expressions representing all the expressions that are being passed to this syntax element. As opposed to Skript, elements of this array can't be null.
      matchedPattern - the index of the pattern that was successfully matched. It corresponds to the order of the syntaxes in registration
      parseContext - an object containing additional information about the parsing of this syntax element, like regex matches and parse marks
      Returns:
      true if the syntax element was initialized successfully, false otherwise.
      See Also:
    • getValues

      public T[] getValues(TriggerContext ctx)
      Description copied from interface: Expression
      Retrieves all values of this Expression, accounting for possible modifiers. This means that if this is an or-list, it will choose a random value to return.
      Specified by:
      getValues in interface Expression<S extends ArgumentSection>
      Parameters:
      ctx - the event
      Returns:
      an array of the values
      See Also:
    • preInitialize

      public abstract boolean preInitialize(Expression<?>[] expressions, int matchedPattern, ParseContext parseContext)
      This method is run before the section linked to this SectionValue is identified, and should be used to initialize fields and other class data using the usual parameters of the SyntaxElement.init(Expression[], int, ParseContext) function.
      Parameters:
      expressions - an array of expressions representing all the expressions that are being passed to this SectionValue. As opposed to Skript, elements of this array can't be null.
      matchedPattern - the index of the pattern that was successfully matched. It corresponds to the order of the syntaxes in registration
      parseContext - an object containing additional information about the parsing of this SectionValue, like regex matches and parse marks
      Returns:
      true if the SectionValue was pre-initialized successfully, false otherwise.
      See Also:
    • postInitialize

      public boolean postInitialize(S section, ParseContext parseContext)
      This method is run after the section linked to this SectionValue is identified, and should be used to make some additional verifications/setup operations on the linked ArgumentSection that was identified. By default, this function always returns true with no added operations.
      Parameters:
      section - the section that was identified as corresponding to this SectionValue
      parseContext - the parse context used previously
      Returns:
      true if the SectionValue was post-initialized successfully, false otherwise.
    • getSelectorFunction

      public Function<? super List<? extends S>, Optional<? extends S>> getSelectorFunction()
      Returns the selector function for this SectionValue. This function is supplied with a list of all the sections of the type described by getSectionClass(), and returns an Optional describing the section that this SectionValue should be linked to, or an empty Optional if no matching section was found. This is useful for targeting a specific section out of multiple surrounding ones based on criteria specific to the implementation. By default, this always picks the first matching function (i.e the innermost one), if there is one.
      Returns:
      the selector function for this SectionValue.
    • getSectionValues

      public abstract T[] getSectionValues(S section, TriggerContext ctx)
      Returns the values of this SectionValue, akin to the output of Expression.getValues(TriggerContext), given the linked section and the TriggerContext.
      Parameters:
      section - the linked section
      ctx - the TriggerContext
      Returns:
      the values of this SectionValue
    • getSectionClass

      public abstract Class<? extends S> getSectionClass()
      Returns:
      the class of the ArgumentSection this SectionValue is linked to.