Class WrapperExpression<T>
- All Implemented Interfaces:
Debuggable
,Expression<T>
,SyntaxElement
- Direct Known Subclasses:
ExprBlock
,ExprEventExpression
,ExprLocation
,ExprLocationOf
,ExprTimeState
WrapperExpression(SimpleExpression)
)
or with setExpr(Expression)
in init()
.If you override
get(Event)
you must override iterator(Event)
as well.-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescription@Nullable Class<?>[]
acceptChange(Changer.ChangeMode mode)
Tests whether this expression supports the given mode, and if yes what type it expects thedelta
to be.@Nullable Object[]
beforeChange(Expression<?> changed, @Nullable Object[] delta)
This method is called before this expression is set to another one.void
change(org.bukkit.event.Event e, @Nullable Object[] delta, Changer.ChangeMode mode)
Changes the expression's value by the given amount.protected T[]
get(org.bukkit.event.Event e)
This is the internal method to get an expression's values.
To get the expression's value from the outside useSimpleExpression.getSingle(Event)
orSimpleExpression.getArray(Event)
.boolean
getAnd()
Returns true if this expression returns all possible values, false if it only returns some of them.protected <R> @Nullable ConvertedExpression<T,? extends R>
getConvertedExpr(Class<R>... to)
Converts this expression to another type.Expression<?>
getExpr()
Gets the return type of this expression.int
getTime()
boolean
Returns whether this value represents the default value of its type for the event, i.e.boolean
isSingle()
iterator(org.bukkit.event.Event e)
Returns the same asExpression.getArray(Event)
but as an iterator.protected void
setExpr(Expression<? extends T> expr)
Sets wrapped expression.boolean
setTime(int time)
Sets the time of this expression, i.e.Expression<? extends T>
simplify()
Simplifies the expression, e.g.Methods inherited from class ch.njol.skript.lang.util.SimpleExpression
check, check, check, getAll, getArray, getConvertedExpression, getSingle, getSource, isLoopOf, setTime, setTime, setTime, 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.Debuggable
toString
Methods inherited from interface ch.njol.skript.lang.Expression
stream
Methods inherited from interface ch.njol.skript.lang.SyntaxElement
getParser, init
-
Constructor Details
-
WrapperExpression
protected WrapperExpression() -
WrapperExpression
-
-
Method Details
-
setExpr
Sets wrapped expression. Parser instance is automatically copied from this expression.- Parameters:
expr
- Wrapped expression.
-
getExpr
-
getConvertedExpr
Description copied from class:SimpleExpression
Converts this expression to another type. Unless the expression is special, the default implementation is sufficient.This method is never called with a supertype of the return type of this expression, or the return type itself.
- Overrides:
getConvertedExpr
in classSimpleExpression<T>
- Parameters:
to
- The desired return type of the returned expression- Returns:
- Expression with the desired return type or null if it can't be converted to the given type
- See Also:
Expression.getConvertedExpression(Class...)
,ConvertedExpression.newInstance(Expression, Class...)
,Converter
-
get
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 useSimpleExpression.getSingle(Event)
orSimpleExpression.getArray(Event)
.- Specified by:
get
in classSimpleExpression<T>
- Parameters:
e
- The event- Returns:
- An array of values for this event. May not contain nulls.
-
iterator
Description copied from interface:Expression
Returns the same asExpression.getArray(Event)
but as an iterator. This method should be overriden by expressions intended to be looped to increase performance.- Specified by:
iterator
in interfaceExpression<T>
- Overrides:
iterator
in classSimpleExpression<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.
-
isSingle
public boolean isSingle()- Returns:
- true if this expression will ever only return one value at most, false if it can return multiple values.
-
getAnd
public 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)
andCondIsSet
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 interfaceExpression<T>
- Overrides:
getAnd
in classSimpleExpression<T>
- Returns:
- Whether this expression returns all values at once or only part of them.
-
getReturnType
Description copied from interface:Expression
Gets the return type of this expression.- Returns:
- A supertype of any objects returned by
Expression.getSingle(Event)
and the component type of any arrays returned byExpression.getArray(Event)
-
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 classSimpleExpression<T>
- 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.
-
change
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 classSimpleExpression<T>
delta
- An array with one or more instances of one or more of the 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.
-
setTime
public boolean setTime(int time)Description copied from class:SimpleExpression
Sets the time of this expression, i.e. whether the returned value represents this expression before or after the event.This method will not be called if this expression is guaranteed to be used after a delay (an error will be printed immediately), but will be called if it only can be after a delay (e.g. if the preceding delay is in an if or a loop) as well as if there's no delay involved.
If this method returns false the expression will be discarded and an error message is printed. Custom error messages must be of
ErrorQuality.SEMANTIC_ERROR
to be printed (NB:Skript.error(String)
always creates semantic errors).This implementation sets the time but returns false.
- Specified by:
setTime
in interfaceExpression<T>
- Overrides:
setTime
in classSimpleExpression<T>
- Parameters:
time
- -1 for past or 1 for future. 0 is never passed to this method as it represents the default state.- Returns:
- Whether this expression has distinct time states, e.g. a player never changes but a block can. This should be sensitive for the event (using
ParserInstance.isCurrentEvent(Class)
). - See Also:
SimpleExpression.setTime(int, Class, Expression...)
,SimpleExpression.setTime(int, Expression, Class...)
-
getTime
public int getTime()- Specified by:
getTime
in interfaceExpression<T>
- Overrides:
getTime
in classSimpleExpression<T>
- Returns:
- The value passed to
Expression.setTime(int)
or 0 if it was never changed. - See Also:
Expression.setTime(int)
-
isDefault
public boolean isDefault()Description copied from interface:Expression
Returns whether this value represents the default value of its type for the event, i.e. it can be replaced with a call to event.getXyz() if one knows the event & value type.This method might be removed in the future as it's better to check whether value == event.getXyz() for every value an expression returns.
- Specified by:
isDefault
in interfaceExpression<T>
- Overrides:
isDefault
in classSimpleExpression<T>
- Returns:
- Whether is is the return types' default expression
-
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 interfaceExpression<T>
- Overrides:
simplify
in classSimpleExpression<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!
-
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.
-