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
Constructors -
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 thedeltato be.@Nullable Object[]beforeChange(Expression<?> changed, @Nullable Object[] delta)This method is called before this expression is set to another one.voidchange(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).booleangetAnd()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.intgetTime()booleanReturns whether this value represents the default value of its type for the event, i.e.booleanisSingle()iterator(org.bukkit.event.Event e)Returns the same asExpression.getArray(Event)but as an iterator.protected voidsetExpr(Expression<? extends T> expr)Sets wrapped expression.booleansetTime(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, toStringMethods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, waitMethods inherited from interface ch.njol.skript.lang.Debuggable
toStringMethods inherited from interface ch.njol.skript.lang.Expression
streamMethods 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:SimpleExpressionConverts 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:
getConvertedExprin 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:SimpleExpressionThis 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:
getin classSimpleExpression<T>- Parameters:
e- The event- Returns:
- An array of values for this event. May not contain nulls.
-
iterator
Description copied from interface:ExpressionReturns 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:
iteratorin interfaceExpression<T>- Overrides:
iteratorin 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:ExpressionReturns 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)andCondIsSetand thus breaks conditions that use this expression if it returns a wrong value.This method must return true if this is a
singleexpression. // TODO make this method irrelevant for single expressions- Specified by:
getAndin interfaceExpression<T>- Overrides:
getAndin classSimpleExpression<T>- Returns:
- Whether this expression returns all values at once or only part of them.
-
getReturnType
Description copied from interface:ExpressionGets 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:ExpressionTests whether this expression supports the given mode, and if yes what type it expects thedeltato 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
returnTypethis 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:
acceptChangein interfaceExpression<T>- Overrides:
acceptChangein classSimpleExpression<T>- Returns:
- An array of types that
Expression.change(Event, Object[], ChangeMode)accepts as itsdeltaparameter (which can be arrays to denote that multiple of that type are accepted), or null if the given mode is not supported. ForChanger.ChangeMode.DELETEandChanger.ChangeMode.RESETthis can return any non-null array to mark them as supported.
-
change
Description copied from interface:ExpressionChanges the expression's value by the given amount. This will only be called on supported modes and with the desireddeltatype as returned byExpression.acceptChange(ChangeMode)- Specified by:
changein interfaceExpression<T>- Overrides:
changein 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.DELETEandChanger.ChangeMode.RESET). This can be a Object[], thus casting is not allowed.
-
setTime
public boolean setTime(int time)Description copied from class:SimpleExpressionSets 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_ERRORto be printed (NB:Skript.error(String)always creates semantic errors).This implementation sets the time but returns false.
- Specified by:
setTimein interfaceExpression<T>- Overrides:
setTimein 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:
getTimein interfaceExpression<T>- Overrides:
getTimein 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:ExpressionReturns 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:
isDefaultin interfaceExpression<T>- Overrides:
isDefaultin classSimpleExpression<T>- Returns:
- Whether is is the return types' default expression
-
simplify
Description copied from interface:ExpressionSimplifies 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:
simplifyin interfaceExpression<T>- Overrides:
simplifyin 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:ExpressionThis 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.
-