Class PropertyExpression<O,T>

java.lang.Object
io.github.syst3ms.skriptparser.lang.properties.PropertyExpression<O,T>
Type Parameters:
O - The type of the owner of this expression.
T - The returned type of this expression.
All Implemented Interfaces:
Expression<T>, SyntaxElement
Direct Known Subclasses:
ExprAmount, ExprColorValues, ExprDateTimestamp, ExprLength

public abstract class PropertyExpression<O,T> extends Object implements Expression<T>
A base class for expressions that contain general properties. In English, one can express properties in many different ways:
  • Mwexim's book
  • the book of Mwexim
This utility class acknowledges how useful and common such 'property expressions' are, and provides a simple way to implement them. The class also provides default implementations of init(Expression[], int, ParseContext) and getValues(TriggerContext). Their default functionality is specified below.
  • Field Details

  • Constructor Details

    • PropertyExpression

      public PropertyExpression()
  • Method Details

    • init

      public boolean init(Expression<?>[] expressions, int matchedPattern, ParseContext parseContext)
      This default init() implementation automatically properly sets the owner of this property, which can be accessed using getOwner(). If this implementation is overridden for one reason or another, it must call setOwner(Expression) properly.
      Specified by:
      init in interface SyntaxElement
      Parameters:
      expressions - an array of expressions representing all the expressions that are being passed to this syntax element.
      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:
      whether the initialization was successful or not.
      See Also:
    • getValues

      public T[] getValues(TriggerContext ctx)
      A simple default method that will apply getProperty(Object) on the owner of this property.
      Specified by:
      getValues in interface Expression<O>
      Parameters:
      ctx - the event
      Returns:
      the values of this property after applying the getProperty(Object) function on the owner.
      See Also:
    • getProperty

      @Nullable public T getProperty(O owner)
      For each owner, this method will be ran individually to convert it to this particular property.
      Parameters:
      owner - the owner
      Returns:
      the property value
    • isSingle

      public boolean isSingle()
      Specified by:
      isSingle in interface Expression<O>
      Returns:
      whether this expression returns a single value. By default, this is defined on registration, but it can be overridden.
    • toString

      public String toString(TriggerContext ctx, boolean debug)
      Specified by:
      toString in interface SyntaxElement
      Parameters:
      ctx - the event
      debug - whether to show additional information or not
      Returns:
      a String that should aim to resemble what is written in the script as closely as possible
    • toString

      protected String toString(TriggerContext ctx, boolean debug, String property)
    • getOwner

      public Expression<O> getOwner()
    • setOwner

      public void setOwner(Expression<O> owner)
    • isGenitive

      public boolean isGenitive()
      You can express possession in two different ways:
      • genitive: Mwexim's book
      • regular: book of Mwexim
      One may use this method to check if the pattern used is in the genitive form.
      Returns:
      whether the pattern is in the genitive form or not.
    • composePatterns

      public static String[] composePatterns(String property, String owner)