Class PropertyExpression<F,​T>

java.lang.Object
ch.njol.skript.lang.util.SimpleExpression<T>
ch.njol.skript.expressions.base.PropertyExpression<F,​T>
All Implemented Interfaces:
Debuggable, Expression<T>, SyntaxElement
Direct Known Subclasses:
ExprBiome, ExprBurnCookTime, ExprChunk, ExprColorOf, ExprColoured, ExprDamagedItem, ExprEntityAttribute, ExprFoodLevel, ExprFormatTime, ExprFurnaceSlot, ExprGameMode, ExprHash, ExprHealth, ExprIdOf, ExprItemWithCustomModelData, ExprItemWithLore, ExprLastDamageCause, ExprLightLevel, ExprNamed, ExprOpenedInventory, ExprPlayerViewDistance, ExprRound, ExprSaturation, ExprSeed, ExprShooter, ExprSpawn, ExprTarget, ExprTargetedBlock, ExprTime, ExprTool, ExprUnbreakable, ExprWeather, ExprWorld, ExprXOf, SimplePropertyExpression

public abstract class PropertyExpression<F,​T> extends SimpleExpression<T>
Represents an expression which represents a property of another one. Remember to set the expression with setExpr(Expression) in init().
See Also:
SimplePropertyExpression, register(Class, Class, String, String)
  • Constructor Details

    • PropertyExpression

      public PropertyExpression()
  • Method Details

    • register

      public static <T> void register(Class<? extends Expression<T>> c, Class<T> type, String property, String fromType)
      Registers an expression as ExpressionType.PROPERTY with the two default property patterns "property of %types%" and "%types%'[s] property"
      Parameters:
      c -
      type -
      property - The name of the property
      fromType - Should be plural but doesn't have to be
    • setExpr

      protected final void setExpr(Expression<? extends F> expr)
      Sets the expression this expression represents a property of. No reference to the expression should be kept.
      Parameters:
      expr -
    • getExpr

      public final Expression<? extends F> getExpr()
    • get

      protected final T[] get(org.bukkit.event.Event e)
      Description copied from class: SimpleExpression
      This is the internal method to get an expression's values.
      To get the expression's value from the outside use SimpleExpression.getSingle(Event) or SimpleExpression.getArray(Event).
      Specified by:
      get in class SimpleExpression<T>
      Parameters:
      e - The event
      Returns:
      An array of values for this event. May not contain nulls.
    • getAll

      public final T[] getAll(org.bukkit.event.Event e)
      Description copied from class: SimpleExpression
      Gets all possible return values of this expression, i.e. it returns the same as Expression.getArray(Event) if Expression.getAnd() is true, otherwise all possible values for Expression.getSingle(Event).

      Unlike SimpleExpression.get(Event) you have to make sure that the this method's returned array is neither null nor contains null elements.

      Specified by:
      getAll in interface Expression<F>
      Overrides:
      getAll in class SimpleExpression<T>
      Parameters:
      e - The event
      Returns:
      An array of all possible values of this expression for the given event which must neither be null nor contain nulls, and which must not be an internal array.
    • get

      protected abstract T[] get(org.bukkit.event.Event e, F[] source)
      Converts the given source object(s) to the correct type.

      Please note that the returned array must neither be null nor contain any null elements!

      Parameters:
      e -
      source -
      Returns:
      An array of the converted objects, which may contain less elements than the source array, but must not be null.
      See Also:
      Converters.convert(Object[], Class, Converter)
    • get

      protected T[] get(F[] source, Converter<? super F,​? extends T> converter)
      Parameters:
      source -
      converter - must return instances of Expression.getReturnType()
      Returns:
      An array containing the converted values
      Throws:
      ArrayStoreException - if the converter returned invalid values
    • isSingle

      public final boolean isSingle()
      Returns:
      true if this expression will ever only return one value at most, false if it can return multiple values.
    • getAnd

      public final boolean getAnd()
      Description copied from interface: Expression
      Returns true if this expression returns all possible values, false if it only returns some of them.

      This method significantly influences Expression.check(Event, Checker), Expression.check(Event, Checker, boolean) and CondIsSet and thus breaks conditions that use this expression if it returns a wrong value.

      This method must return true if this is a single expression. // TODO make this method irrelevant for single expressions

      Specified by:
      getAnd in interface Expression<F>
      Overrides:
      getAnd in class SimpleExpression<T>
      Returns:
      Whether this expression returns all values at once or only part of them.
    • simplify

      public Expression<? extends T> simplify()
      Description copied from interface: Expression
      Simplifies the expression, e.g. if it only contains literals the expression may be simplified to a literal, and wrapped expressions are unwrapped.

      After this method was used the toString methods are likely not useful anymore.

      This method is not yet used but will be used to improve efficiency in the future.

      Specified by:
      simplify in interface Expression<F>
      Overrides:
      simplify in class SimpleExpression<T>
      Returns:
      A reference to a simpler version of this expression. Can change this expression directly and return itself if applicable, i.e. no references to the expression before this method call should be kept!