Class ConvertedLiteral<F,T>

java.lang.Object
ch.njol.skript.lang.util.ConvertedExpression<F,T>
ch.njol.skript.lang.util.ConvertedLiteral<F,T>
All Implemented Interfaces:
Debuggable, Expression<T>, Literal<T>, SyntaxElement

public class ConvertedLiteral<F,T> extends ConvertedExpression<F,T> implements Literal<T>
See Also:
  • Field Details

    • data

      protected transient T[] data
  • Constructor Details

    • ConvertedLiteral

      public ConvertedLiteral(Literal<F> source, T[] data, Class<T> to)
  • Method Details

    • getConvertedExpression

      public <R> @Nullable Literal<? extends R> getConvertedExpression(Class<R>... to)
      Description copied from interface: Expression
      Tries to convert this expression to the given type. This method can print an error prior to returning null to specify the cause.

      Please note that expressions whose returnType is not Object will not be parsed at all for a certain class if there's no converter from the expression's returnType to the desired class. Thus this method should only be overridden if this expression's returnType is Object.

      The returned expression should delegate this method to the original expression's method to prevent excessive converted expression chains (see also ConvertedExpression).

      Specified by:
      getConvertedExpression in interface Expression<F>
      Specified by:
      getConvertedExpression in interface Literal<F>
      Overrides:
      getConvertedExpression in class ConvertedExpression<F,T>
      Parameters:
      to - The desired return type of the returned expression
      Returns:
      Expression with the desired return type or null if the expression can't be converted to the given type. Returns the expression itself if it already returns the desired type.
      See Also:
    • toString

      public String toString(@Nullable org.bukkit.event.Event e, boolean debug)
      Specified by:
      toString in interface Debuggable
      Overrides:
      toString in class ConvertedExpression<F,T>
      Parameters:
      e - The event to get information to. 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
    • getArray

      public T[] getArray()
      Specified by:
      getArray in interface Literal<F>
    • getAll

      public T[] getAll()
      Specified by:
      getAll in interface Literal<F>
    • getArray

      public T[] getArray(org.bukkit.event.Event e)
      Description copied from interface: Expression
      Get all the values of this expression. The returned array is empty if this expression doesn't have any values for the given event.

      The returned array must not contain any null values.

      Do not use this in conditions, use Expression.check(Event, Checker, boolean) instead.

      Specified by:
      getArray in interface Expression<F>
      Overrides:
      getArray in class ConvertedExpression<F,T>
      Parameters:
      e - The event
      Returns:
      An array of values of this expression which must neither be null nor contain nulls, and which must not be an internal array.
    • getSingle

      public T getSingle()
      Specified by:
      getSingle in interface Literal<F>
    • getSingle

      public T getSingle(org.bukkit.event.Event e)
      Description copied from interface: Expression
      Get the single value of this expression.

      This method may only return null if it always returns null for the given event, i.e. it is equivalent to getting a random element out of Expression.getAll(Event) or null iff that array is empty.

      Do not use this in conditions, use Expression.check(Event, Checker, boolean) instead.

      Specified by:
      getSingle in interface Expression<F>
      Overrides:
      getSingle in class ConvertedExpression<F,T>
      Parameters:
      e - The event
      Returns:
      The value or null if this expression doesn't have any value for the event
    • iterator

      public @Nullable Iterator<T> iterator(org.bukkit.event.Event e)
      Description copied from interface: Expression
      Returns the same as Expression.getArray(Event) but as an iterator. This method should be overriden by expressions intended to be looped to increase performance.
      Specified by:
      iterator in interface Expression<F>
      Overrides:
      iterator in class ConvertedExpression<F,T>
      Parameters:
      e - The event
      Returns:
      An iterator to iterate over all values of this expression which may be empty and/or null, but must not return null elements.
    • check

      public boolean check(org.bukkit.event.Event e, Checker<? super T> c)
      Description copied from interface: Expression
      Checks this expression against the given checker. This method must only be used around other checks, use Expression.check(Event, Checker, boolean) for a simple ckeck or the innermost check of a nested check.
      Specified by:
      check in interface Expression<F>
      Overrides:
      check in class ConvertedExpression<F,T>
      Parameters:
      e - The event
      c - A checker
      Returns:
      Whether this expression matches the given checker
      See Also:
    • check

      public boolean check(org.bukkit.event.Event e, Checker<? super T> c, boolean negated)
      Description copied from interface: Expression
      Checks this expression against the given checker. This is the normal version of this method and the one which must be used for simple checks, or as the innermost check of nested checks.

      Usual implementation (may differ, e.g. may return false for nonexistent values independent of negated):

       return negated ^ Expression.check(Event, Checker);
       
      Specified by:
      check in interface Expression<F>
      Overrides:
      check in class ConvertedExpression<F,T>
      Parameters:
      e - The event
      c - A checker
      negated - The checking condition's negated state. This is used to invert the output of the checker if set to true (i.e. negated ^ checker.check(...))
      Returns:
      Whether this expression matches or doesn't match the given checker depending on the condition's negated state.
      See Also: