Package ch.njol.skript.expressions.base
Class PropertyExpression<F,T>
java.lang.Object
ch.njol.skript.lang.util.SimpleExpression<T>
ch.njol.skript.expressions.base.PropertyExpression<F,T>
- All Implemented Interfaces:
Debuggable
,Expression<T>
,SyntaxElement
- Direct Known Subclasses:
ExprBiome
,ExprBurnCookTime
,ExprChunk
,ExprColorOf
,ExprColoured
,ExprDamagedItem
,ExprEntityAttribute
,ExprFoodLevel
,ExprFormatDate
,ExprFurnaceSlot
,ExprGameMode
,ExprHash
,ExprHealth
,ExprItemWithCustomModelData
,ExprItemWithLore
,ExprLastDamageCause
,ExprLightLevel
,ExprNamed
,ExprOpenedInventory
,ExprRound
,ExprSeed
,ExprShooter
,ExprSpawn
,ExprTarget
,ExprTargetedBlock
,ExprTime
,ExprTool
,ExprUnbreakable
,ExprWeather
,ExprWorld
,ExprXOf
,SimplePropertyExpression
Represents an expression which represents a property of another one. Remember to set the expression with
setExpr(Expression)
in
init()
.-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprotected T[]
protected final T[]
get
(org.bukkit.event.Event event) 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)
.protected abstract T[]
Converts the given source object(s) to the correct type.final T[]
getAll
(org.bukkit.event.Event event) Gets all possible return values of this expression, i.e.final boolean
getAnd()
Returns true if this expression returns all possible values, false if it only returns some of them.final Expression<? extends F>
getExpr()
boolean
isSingle()
static <T> void
Registers an expression asExpressionType.PROPERTY
with the two default property patterns "property of %types%" and "%types%'[s] property"static <T> void
registerDefault
(Class<? extends Expression<T>> c, Class<T> type, String property, String fromType) Registers an expression asExpressionType.PROPERTY
with the two default property patterns "property [of %types%]" and "%types%'[s] property" This method also makes the expression type optional to force a default expression on the property expression.protected final void
setExpr
(Expression<? extends F> expr) Sets the expression this expression represents a property of.Expression<? extends T>
simplify()
Simplifies the expression, e.g.Methods inherited from class ch.njol.skript.lang.util.SimpleExpression
acceptChange, change, check, check, check, getArray, getConvertedExpr, getConvertedExpression, getSingle, getSource, getTime, isDefault, isLoopOf, iterator, setTime, setTime, 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
beforeChange, getAcceptedChangeModes, getOptionalSingle, getReturnType, stream
Methods inherited from interface ch.njol.skript.lang.SyntaxElement
getParser, init
-
Constructor Details
-
PropertyExpression
public PropertyExpression()
-
-
Method Details
-
register
public static <T> void register(Class<? extends Expression<T>> c, Class<T> type, String property, String fromType) Registers an expression asExpressionType.PROPERTY
with the two default property patterns "property of %types%" and "%types%'[s] property"- Parameters:
c
- the PropertyExpression class being registered.type
- the main expression type the property is based off of.property
- the name of the property.fromType
- should be plural to support multiple objects but doesn't have to be.
-
registerDefault
public static <T> void registerDefault(Class<? extends Expression<T>> c, Class<T> type, String property, String fromType) Registers an expression asExpressionType.PROPERTY
with the two default property patterns "property [of %types%]" and "%types%'[s] property" This method also makes the expression type optional to force a default expression on the property expression.- Parameters:
c
- the PropertyExpression class being registered.type
- the main expression type the property is based off of.property
- the name of the property.fromType
- should be plural to support multiple objects but doesn't have to be.
-
setExpr
Sets the expression this expression represents a property of. No reference to the expression should be kept.- Parameters:
expr
-
-
getExpr
-
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:
event
- The event- Returns:
- An array of values for this event. May not contain nulls.
-
getAll
Description copied from class:SimpleExpression
Gets all possible return values of this expression, i.e. it returns the same asExpression.getArray(Event)
ifExpression.getAnd()
is true, otherwise all possible values forExpression.getSingle(Event)
.Unlike
SimpleExpression.get(Event)
you have to make sure that the this method's returned array is neither null nor contains null elements.- Specified by:
getAll
in interfaceExpression<F>
- Overrides:
getAll
in classSimpleExpression<T>
- Parameters:
event
- The event- Returns:
- An array of all possible values of this expression for the given event which must neither be null nor contain nulls, and which must not be an internal array.
-
get
Converts the given source object(s) to the correct type.Please note that the returned array must neither be null nor contain any null elements!
- Parameters:
event
- the event involved at the time of runtime calling.source
- the array of the objects from the expressions.- Returns:
- An array of the converted objects, which may contain less elements than the source array, but must not be null.
- See Also:
-
get
- Parameters:
source
- the array of the objects from the expressions.converter
- must return instances ofExpression.getReturnType()
- Returns:
- An array containing the converted values
- Throws:
ArrayStoreException
- if the converter returned invalid values
-
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 final 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<F>
- Overrides:
getAnd
in classSimpleExpression<T>
- Returns:
- Whether this expression returns all values at once or only part of them.
-
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<F>
- 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!
-