Class SimplifiedLiteral<T>

java.lang.Object
ch.njol.skript.lang.util.SimpleLiteral<T>
ch.njol.skript.lang.simplification.SimplifiedLiteral<T>
Type Parameters:
T - the type of the literal
All Implemented Interfaces:
Debuggable, DefaultExpression<T>, Expression<T>, Literal<T>, Loopable<T>, Simplifiable<Expression<? extends T>>, SyntaxElement

public class SimplifiedLiteral<T> extends SimpleLiteral<T>
Represents a literal, i.e. a static value like a number or a string, that was created by simplifying another expression. Maintains a reference to the original expression to allow for changers and toString generation.
  • Constructor Details

    • SimplifiedLiteral

      public SimplifiedLiteral(T[] data, Class<T> type, boolean and, Expression<T> source)
      Creates a new simplified literal.
      Parameters:
      data - the data of the literal
      type - the type of the literal
      and - whether the literal is an "and" literal
      source - the source expression this literal was created from. Used for toString values.
  • Method Details

    • fromExpression

      public static <T> SimplifiedLiteral<T> fromExpression(Expression<T> original)
      Creates a new simplified literal from an expression by evaluating it with a ContextlessEvent. Any expression that requires specific event data cannot be safely simplified to a literal. The original expression is stored for later toString generation.
      Type Parameters:
      T - the type of the literal
      Parameters:
      original - the original expression to simplify
      Returns:
      a new simplified literal
    • acceptChange

      public Class<?> @Nullable [] acceptChange(Changer.ChangeMode mode)
      Description copied from interface: Expression
      Tests whether this expression supports the given mode, and if yes what type it expects the delta to be.

      Use Changer.ChangerUtils.acceptsChange(Expression, ChangeMode, Class...) to test whether an expression supports changing, don't directly use this method!

      Please note that if a changer is registered for this expression's returnType this method does not have to be overridden. If you override it though make sure to return super.acceptChange(mode), and to handle the appropriate ChangeMode(s) in Expression.change(Event, Object[], ChangeMode) with super.change(...).

      Unlike Changer.acceptChange(ChangeMode) this method may print errors.

      Specified by:
      acceptChange in interface Expression<T>
      Overrides:
      acceptChange in class SimpleLiteral<T>
      Parameters:
      mode - The mode to check
      Returns:
      An array of types that Expression.change(Event, Object[], ChangeMode) accepts as its delta parameter (which can be arrays to denote that multiple of that type are accepted), or null if the given mode is not supported. For Changer.ChangeMode.DELETE and Changer.ChangeMode.RESET this can return any non-null array to mark them as supported.
    • beforeChange

      public Object @Nullable [] beforeChange(Expression<?> changed, Object @Nullable [] delta)
      Description copied from interface: Expression
      This method is called before this expression is set to another one. The return value is what will be used for change. You can use modified version of initial delta array or create a new one altogether

      Default implementation will convert slots to items when they're set to variables, as specified in Skript documentation.

      Parameters:
      changed - What is about to be set.
      delta - Initial delta array.
      Returns:
      Delta array to use for change.
    • change

      public void change(org.bukkit.event.Event event, Object @Nullable [] delta, Changer.ChangeMode mode) throws UnsupportedOperationException
      Description copied from interface: Expression
      Changes the expression's value by the given amount. This will only be called on supported modes and with the desired delta type as returned by Expression.acceptChange(ChangeMode)
      Specified by:
      change in interface Expression<T>
      Overrides:
      change in class SimpleLiteral<T>
      Parameters:
      event - The event
      delta - An array with one or more instances of one or more of the classes returned by Expression.acceptChange(ChangeMode) for the given change mode (null for Changer.ChangeMode.DELETE and Changer.ChangeMode.RESET). This can be a Object[], thus casting is not allowed.
      mode - The Changer.ChangeMode of the attempted change
      Throws:
      UnsupportedOperationException - (optional) - If this method was called on an unsupported ChangeMode.
    • isLoopOf

      public boolean isLoopOf(String input)
      Description copied from interface: Loopable
      Checks whether the given 'loop-...' expression should match this loop, e.g. loop-block matches any loops that loop through blocks and loop-argument matches an argument loop.

      You should usually just return false as e.g. loop-block will automatically match the expression if its returnType is Block or a subtype of it.

      Specified by:
      isLoopOf in interface Loopable<T>
      Overrides:
      isLoopOf in class SimpleLiteral<T>
      Parameters:
      input - The entered input string (the blank in loop-___)
      Returns:
      Whether this loop matches the given string
    • changeInPlace

      public <R> void changeInPlace(org.bukkit.event.Event event, Function<T,R> changeFunction)
      Description copied from interface: Expression
      Changes the contents of an expression using the given Function. Intended for changes that change properties of the values of the expression, rather than completely changing the expression. For example, set vector length of {_v} to 1, rather than set {_v} to vector(0,1,0).
      This is a 1 to 1 transformation and should not add elements. Returning null will remove the element. Returning a type not accepted by Expression.acceptChange(ChangeMode) for Changer.ChangeMode.SET will depend on the implementer. The default implementation will remove the element.
      This expression must support Changer.ChangeMode.SET for this method to work.
      Type Parameters:
      R - The output type of the change function. Must be a type returned by {Expression.acceptChange(ChangeMode)} for Changer.ChangeMode.SET.
      Parameters:
      event - The event to use for local variables and evaluation
      changeFunction - A 1-to-1 function that transforms a single input to a single output. Returning null will remove the element. Returning a type not accepted by Expression.acceptChange(ChangeMode) for Changer.ChangeMode.SET will depend on the implementer. The default implementation will remove the element.
    • changeInPlace

      public <R> void changeInPlace(org.bukkit.event.Event event, Function<T,R> changeFunction, boolean getAll)
      Description copied from interface: Expression
      Changes the contents of an expression using the given Function. Intended for changes that change properties of the values of the expression, rather than completely changing the expression. For example, set vector length of {_v} to 1, rather than set {_v} to vector(0,1,0).
      This is a 1 to 1 transformation and should not add elements. Returning null will remove the element. Returning a type not accepted by Expression.acceptChange(ChangeMode) for Changer.ChangeMode.SET will depend on the implementer. The default implementation will remove the element.
      This expression must support Changer.ChangeMode.SET for this method to work.
      Type Parameters:
      R - The output type of the change function. Must be a type returned by {Expression.acceptChange(ChangeMode)} for Changer.ChangeMode.SET.
      Parameters:
      event - The event to use for local variables and evaluation
      changeFunction - A 1-to-1 function that transforms a single input to a single output. Returning null will remove the element. Returning a type not accepted by Expression.acceptChange(ChangeMode) for Changer.ChangeMode.SET will depend on the implementer. The default implementation will remove the element.
      getAll - Whether to evaluate with Expression.getAll(Event) or Expression.getArray(Event).
    • getSource

      public Expression<?> getSource()
      Description copied from interface: Expression
      Returns the original expression that was parsed, i.e. without any conversions done.
      Specified by:
      getSource in interface Expression<T>
      Overrides:
      getSource in class SimpleLiteral<T>
      Returns:
      The unconverted source expression of this expression or this expression itself if it was never converted.
    • toString

      public String toString(@Nullable @Nullable org.bukkit.event.Event event, boolean debug)
      Specified by:
      toString in interface Debuggable
      Overrides:
      toString in class SimpleLiteral<T>
      Parameters:
      event - The event to get information from. This is always null if debug == false.
      debug - If true this should print more information, if false this should print what is shown to the end user
      Returns:
      String representation of this object