Interface Expression<T>

Type Parameters:
T - the type of value this expression returns
All Superinterfaces:
SyntaxElement
All Known Subinterfaces:
Literal<T>
All Known Implementing Classes:
CondExprCompare, CondExprContains, CondExprDateCompare, CondExprIsDivisible, CondExprIsEmpty, CondExprIsPrime, CondExprIsSet, CondExprMatch, CondExprStartsEnds, ConditionalExpression, ContextExpression, ConvertedExpression, ExecExprListOperators, ExecExprReplace, ExecutableExpression, ExprAmount, ExprAnswer, ExprArithmeticOperators, ExprBinaryMathFunctions, ExprBooleanOperators, ExprColorFromHex, ExprColorFromRGB, ExprColorValues, ExprDateAgoLater, ExprDateFormatted, ExprDateFromUnix, ExprDateInformation, ExprDateNow, ExprDateTimestamp, ExprDateTodayAt, ExprDefaultValue, ExprDifference, ExprDurationSinceUntil, ExprElement, ExpressionList, ExprFunctionCall, ExprLength, ExprLoopValue, ExprMutableList, ExprNumberConvertBase, ExprParseAs, ExprRandomNumber, ExprRange, ExprSingleParameter, ExprStringCase, ExprStringCharAt, ExprStringChars, ExprStringOccurrence, ExprStringSplitJoin, ExprSubstring, ExprTernary, ExprUnaryMathFunctions, ExprVariableIndices, ExprWhether, LiteralList, LitFunctionParameter, LitScriptName, LitTimeConstants, PropertyConditional, PropertyExpression, RestrictedExpression, SectionValue, SimpleExpression, SimpleLiteral, TaggedExpression, Variable, VariableString

public interface Expression<T> extends SyntaxElement
An expression, i.e a SyntaxElement representing a value with some type.
  • Method Details

    • getValues

      T[] getValues(TriggerContext ctx)
      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.
      Parameters:
      ctx - the event
      Returns:
      an array of the values
      See Also:
    • getArray

      default T[] getArray(TriggerContext ctx)
      Retrieves all values of this Expressions, without accounting for possible modifiers. This means that if this is an or-list, it will still return all possible values.
      Parameters:
      ctx - the event
      Returns:
      an array of the raw values
    • getSingle

      default Optional<? extends T> getSingle(TriggerContext ctx)
      Gets a single value out of this Expression
      Parameters:
      ctx - the event
      Returns:
      the single value of this Expression, or empty if it has no value
      Throws:
      SkriptRuntimeException - if the expression returns more than one value
    • isSingle

      default boolean isSingle()
      Returns:
      whether this expression returns a single value. By default, this is defined on registration, but it can be overridden.
    • getReturnType

      default Class<? extends T> getReturnType()
      Returns:
      the return type of this expression. By default, this is defined on registration, but, like isSingle(), can be overriden.
    • acceptsChange

      default Optional<Class<?>[]> acceptsChange(ChangeMode mode)
      Determines whether this expression can be changed according to a specific ChangeMode, and what type of values it can be changed with.
      Parameters:
      mode - the mode this Expression would be changed with
      Returns:
      an array of classes describing what types this Expression can be changed with, empty if it shouldn't be changed with the given change mode. If the change mode is ChangeMode.DELETE or ChangeMode.RESET, then an empty array should be returned.
    • acceptsChange

      default boolean acceptsChange(ChangeMode mode, Expression<?> changeWith)
      Determines whether this expression can be changed to a specific ChangeMode and type class.
      Parameters:
      mode - the mode this Expression would be changed with
      changeWith - the Expression you want to change with
      Returns:
      whether or not this Expression should be changed with the given change mode and class.
    • acceptsChange

      default boolean acceptsChange(ChangeMode mode, Class<?> needle, boolean isSingle)
      Determines whether this expression can be changed to a specific ChangeMode and type class.
      Parameters:
      mode - the mode this Expression would be changed with
      needle - the type class of the instance this Expression would be changed with
      isSingle - whether or not the instance this Expression would be changed with is single
      Returns:
      whether or not this Expression should be changed with the given change mode and class.
    • change

      default void change(TriggerContext ctx, ChangeMode changeMode, Object[] changeWith)
      Changes this expression with the given values according to the given mode
      Parameters:
      ctx - the event
      changeMode - the mode of change
      changeWith - the values to change this Expression with
    • iterator

      default Iterator<? extends T> iterator(TriggerContext ctx)
      Parameters:
      ctx - the event
      Returns:
      an iterator of the values of this expression
    • stream

      default Stream<? extends T> stream(TriggerContext ctx)
      Parameters:
      ctx - the event
      Returns:
      a stream of the values of this expression
    • convertExpression

      default <C> Optional<? extends Expression<C>> convertExpression(Class<C> to)
      Converts this expression from it's current type (T) to another type, using converters.
      Type Parameters:
      C - the type to convert this Expression to
      Parameters:
      to - the class of the type to convert this Expression to
      Returns:
      a converted Expression, or null if it couldn't be converted
    • isLoopOf

      default boolean isLoopOf(String s)
      When this expression is looped, returns what the loop reference (as in loop-<reference>) should be in order to describe each element of the values of this expression.
      Parameters:
      s - the loop reference
      Returns:
      whether the given reference describes this expression's elements. By default, returns true if the parameter is "value"
      See Also:
    • isAndList

      default boolean isAndList()
    • setAndList

      default void setAndList(boolean isAndList)
    • getSource

      default Expression<?> getSource()
    • check

      default boolean check(TriggerContext ctx, Predicate<? super T> predicate)
      Checks this expression against the given Predicate
      Parameters:
      ctx - the event
      predicate - the predicate
      Returns:
      whether the expression matches the predicate
    • check

      default boolean check(TriggerContext ctx, Predicate<? super T> predicate, boolean negated)
      Checks this expression against the given Predicate
      Parameters:
      ctx - the event
      predicate - the predicate
      negated - whether the result should be inverted
      Returns:
      whether the expression matches the predicate
    • check

      static <T> boolean check(T[] all, Predicate<? super T> predicate, boolean negated, boolean and)
      Checks an array of elements against a given predicate
      Type Parameters:
      T - the type of the elements to check
      Parameters:
      all - the array to check
      predicate - the predicate
      negated - whether the result should be inverted
      and - whether all elements of the array should match the predicate, or only one
      Returns:
      whether the elements match the given predicate
    • getMatchingSections

      static <S extends CodeSection> List<? extends S> getMatchingSections(ParserState parserState, Class<? extends S> sectionClass)
    • getLinkedSection

      static <S extends CodeSection> Optional<? extends S> getLinkedSection(ParserState parserState, Class<? extends S> sectionClass)
    • getLinkedSection

      static <S extends CodeSection> Optional<? extends S> getLinkedSection(ParserState parserState, Class<? extends S> sectionClass, Function<? super List<? extends S>, Optional<? extends S>> selector)