Interface PropertyHandler.ExpressionPropertyHandler<Type,ReturnType>
- Type Parameters:
Type
- The type of object this property can be applied to.ReturnType
- The type of object that is returned by this property.
- All Superinterfaces:
PropertyHandler<Type>
- All Known Subinterfaces:
PropertyHandler.TypedValuePropertyHandler<Type,
ValueType>
- All Known Implementing Classes:
PlayerClassInfo.PlayerDisplayNameHandler
- Enclosing interface:
PropertyHandler<Type>
@Experimental
public static interface PropertyHandler.ExpressionPropertyHandler<Type,ReturnType>
extends PropertyHandler<Type>
A handler that can get and optionally change a property value. This interface is suitable for properties that act
like expressions, such as "name", "display name", etc. Properties that use this interface should also use
PropertyBaseExpression
for the parent expression.- See Also:
-
Nested Class Summary
Nested classes/interfaces inherited from interface org.skriptlang.skript.lang.properties.PropertyHandler
PropertyHandler.ConditionPropertyHandler<Type>, PropertyHandler.ContainsHandler<Container,
Element>, PropertyHandler.ExpressionPropertyHandler<Type, ReturnType>, PropertyHandler.TypedValuePropertyHandler<Type, ValueType> -
Method Summary
Modifier and TypeMethodDescriptiondefault Class<?> @Nullable []
Returns the types of changes that this property supports.default void
change
(Type propertyHolder, Object @Nullable [] delta, Changer.ChangeMode mode) Changes the property value of the given object.Converts the given object to the property value.static <Type,
ReturnType>
@NotNull PropertyHandler.ExpressionPropertyHandler<Type, ReturnType> Creates a simple property handler from the given converter function and return type.default Class<?> @NotNull []
The possible return types of this property.default boolean
Whether changing this property requires the source expression to be re-set.@NotNull Class
<ReturnType> The return type of this property.Methods inherited from interface org.skriptlang.skript.lang.properties.PropertyHandler
init, newInstance
-
Method Details
-
convert
Converts the given object to the property value. This method may return arrays if the property is multi-valued.- Parameters:
propertyHolder
- The object to convert.- Returns:
- The property value.
-
acceptChange
Returns the types of changes that this property supports. If the property does not support any changes, this method should returnnull
. If the property supports changes, it should return the classes that are accepted for each change mode.Changer.ChangeMode.RESET
andChanger.ChangeMode.DELETE
do not require any specific types, so they can return an empty or non-empty array.
The default implementation returnsnull
, indicating that the property is read-only.- Parameters:
mode
- The change mode to check.- Returns:
- The types supported by this property for the given change mode, or
null
if the property is read-only. - See Also:
-
change
Changes the property value of the given object. This method is only called ifacceptChange(ChangeMode)
returns a non-null value for the given change mode.- Parameters:
propertyHolder
- The object to change.delta
- The new value(s) to set. This isnull
forChanger.ChangeMode.RESET
andChanger.ChangeMode.DELETE
.mode
- The change mode to apply.- Throws:
UnsupportedOperationException
- If the property is read-only and does not support changes.
-
requiresSourceExprChange
default boolean requiresSourceExprChange()Whether changing this property requires the source expression to be re-set. For example, `set x of (velocity of player) to 1` requires the velocity to be re-set. `set name of tool of player` does not, since the slot property updates the item.- Returns:
- Whether the source expression for this property needs to be changed.
-
returnType
The return type of this property. This is used for type checking and auto-completion. If the property can return multiple types, it should return the most general type that encompasses all possible return types.- Returns:
- The return type of this property.
-
possibleReturnTypes
The possible return types of this property. This is used for type checking and auto-completion. The default implementation returns an array containing the type returned byreturnType()
. If the property can return multiple types, it should return all possible return types.- Returns:
- The possible return types of this property.
-
of
@Contract(value="_, _ -> new", pure=true) @NotNull static <Type,ReturnType> @NotNull PropertyHandler.ExpressionPropertyHandler<Type,ReturnType> of(Function<Type, ReturnType> converter, @NotNull @NotNull Class<ReturnType> returnType) Creates a simple property handler from the given converter function and return type. This is a convenience method for creating property handlers that only need to convert a value and do not support changing the property or hold any state.- Type Parameters:
Type
- The type of object this property can be applied to.ReturnType
- The type of object that is returned by this property.- Parameters:
converter
- The function to convert the object to the property value.returnType
- The return type of the property.- Returns:
- A new property handler that uses the given converter and return type.
-