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:
  • Method Details

    • convert

      @Nullable ReturnType convert(Type propertyHolder)
      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

      default Class<?> @Nullable [] acceptChange(Changer.ChangeMode mode)
      Returns the types of changes that this property supports. If the property does not support any changes, this method should return null. If the property supports changes, it should return the classes that are accepted for each change mode. Changer.ChangeMode.RESET and Changer.ChangeMode.DELETE do not require any specific types, so they can return an empty or non-empty array.
      The default implementation returns null, 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

      default void change(Type propertyHolder, Object @Nullable [] delta, Changer.ChangeMode mode)
      Changes the property value of the given object. This method is only called if acceptChange(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 is null for Changer.ChangeMode.RESET and Changer.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

      @NotNull @NotNull Class<ReturnType> 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

      default Class<?> @NotNull [] 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 by returnType(). 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.