Class 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
-
Field Summary
Fields inherited from class ch.njol.skript.lang.util.SimpleLiteral
data, type
-
Constructor Summary
ConstructorsConstructorDescriptionSimplifiedLiteral
(T[] data, Class<T> type, boolean and, Expression<T> source) Creates a new simplified literal. -
Method Summary
Modifier and TypeMethodDescriptionClass<?> @Nullable []
Tests whether this expression supports the given mode, and if yes what type it expects thedelta
to be.Object @Nullable []
beforeChange
(Expression<?> changed, Object @Nullable [] delta) This method is called before this expression is set to another one.void
change
(org.bukkit.event.Event event, Object @Nullable [] delta, Changer.ChangeMode mode) Changes the expression's value by the given amount.<R> void
changeInPlace
(org.bukkit.event.Event event, Function<T, R> changeFunction) Changes the contents of an expression using the givenFunction
.<R> void
changeInPlace
(org.bukkit.event.Event event, Function<T, R> changeFunction, boolean getAll) Changes the contents of an expression using the givenFunction
.static <T> SimplifiedLiteral
<T> fromExpression
(Expression<T> original) Creates a new simplified literal from an expression by evaluating it with aContextlessEvent
.Expression
<?> Returns the original expression that was parsed, i.e.boolean
Checks whether the given 'loop-...' expression should match this loop, e.g.toString
(@Nullable org.bukkit.event.Event event, boolean debug) Methods inherited from class ch.njol.skript.lang.util.SimpleLiteral
check, check, getAll, getAll, getAnd, getArray, getArray, getConvertedExpression, getReturnType, getSingle, getSingle, getTime, init, init, isDefault, isSingle, iterator, setTime, simplify, toString
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
Methods inherited from interface ch.njol.skript.lang.Expression
canBeSingle, canReturn, getAcceptedChangeModes, getOptionalSingle, getSyntaxTypeName, possibleReturnTypes, stream, streamAll
Methods inherited from interface ch.njol.skript.lang.Loopable
supportsLoopPeeking
Methods inherited from interface ch.njol.skript.lang.SyntaxElement
getParser, preInit
-
Constructor Details
-
SimplifiedLiteral
Creates a new simplified literal.- Parameters:
data
- the data of the literaltype
- the type of the literaland
- whether the literal is an "and" literalsource
- the source expression this literal was created from. Used for toString values.
-
-
Method Details
-
fromExpression
Creates a new simplified literal from an expression by evaluating it with aContextlessEvent
. 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
Description copied from interface:Expression
Tests whether this expression supports the given mode, and if yes what type it expects thedelta
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) inExpression.change(Event, Object[], ChangeMode)
with super.change(...).Unlike
Changer.acceptChange(ChangeMode)
this method may print errors.- Specified by:
acceptChange
in interfaceExpression<T>
- Overrides:
acceptChange
in classSimpleLiteral<T>
- Parameters:
mode
- The mode to check- Returns:
- An array of types that
Expression.change(Event, Object[], ChangeMode)
accepts as itsdelta
parameter (which can be arrays to denote that multiple of that type are accepted), or null if the given mode is not supported. ForChanger.ChangeMode.DELETE
andChanger.ChangeMode.RESET
this can return any non-null array to mark them as supported.
-
beforeChange
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 altogetherDefault 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 desireddelta
type as returned byExpression.acceptChange(ChangeMode)
- Specified by:
change
in interfaceExpression<T>
- Overrides:
change
in classSimpleLiteral<T>
- Parameters:
event
- The eventdelta
- An array with one or more instances of one or more of the classes returned byExpression.acceptChange(ChangeMode)
for the given change mode (null forChanger.ChangeMode.DELETE
andChanger.ChangeMode.RESET
). This can be a Object[], thus casting is not allowed.mode
- TheChanger.ChangeMode
of the attempted change- Throws:
UnsupportedOperationException
- (optional) - If this method was called on an unsupported ChangeMode.
-
isLoopOf
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.
-
changeInPlace
Description copied from interface:Expression
Changes the contents of an expression using the givenFunction
. 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 thanset {_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 byExpression.acceptChange(ChangeMode)
forChanger.ChangeMode.SET
will depend on the implementer. The default implementation will remove the element.
This expression must supportChanger.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)
} forChanger.ChangeMode.SET
.- Parameters:
event
- The event to use for local variables and evaluationchangeFunction
- 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 byExpression.acceptChange(ChangeMode)
forChanger.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 givenFunction
. 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 thanset {_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 byExpression.acceptChange(ChangeMode)
forChanger.ChangeMode.SET
will depend on the implementer. The default implementation will remove the element.
This expression must supportChanger.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)
} forChanger.ChangeMode.SET
.- Parameters:
event
- The event to use for local variables and evaluationchangeFunction
- 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 byExpression.acceptChange(ChangeMode)
forChanger.ChangeMode.SET
will depend on the implementer. The default implementation will remove the element.getAll
- Whether to evaluate withExpression.getAll(Event)
orExpression.getArray(Event)
.
-
getSource
Description copied from interface:Expression
Returns the original expression that was parsed, i.e. without any conversions done.- Specified by:
getSource
in interfaceExpression<T>
- Overrides:
getSource
in classSimpleLiteral<T>
- Returns:
- The unconverted source expression of this expression or this expression itself if it was never converted.
-
toString
- Specified by:
toString
in interfaceDebuggable
- Overrides:
toString
in classSimpleLiteral<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
-