java.lang.Object
nl.pim16aap2.animatedarchitecture.core.structures.properties.Property<T>
Type Parameters:
T - The type of the property.
All Implemented Interfaces:
IKeyed

public final class Property<T> extends Object implements IKeyed
Represents a property of a structure.

Several properties are predefined in this class. For example, the OPEN_STATUS property is used to represent whether a structure is open or closed.

  • Field Details

    • REGISTRY

      public static final Property.Registry REGISTRY
      The registry of all registered properties.
    • ANIMATION_SPEED_MULTIPLIER

      public static final Property<Double> ANIMATION_SPEED_MULTIPLIER
      A property for structures whose animation speed is variable.
    • BLOCKS_TO_MOVE

      public static final Property<Integer> BLOCKS_TO_MOVE
      A property for structures that move a certain amount of blocks when activated.
    • OPEN_STATUS

      public static final Property<Boolean> OPEN_STATUS
      A property for structures that have a defined open and closed state.
    • QUARTER_CIRCLES

      public static final Property<Integer> QUARTER_CIRCLES
      A property for structures that can rotate multiples of 90 degrees.
    • REDSTONE_MODE

      public static final Property<RedstoneMode> REDSTONE_MODE
      A property for structures that can have different redstone modes.
    • ROTATION_POINT

      public static final Property<Vector3Di> ROTATION_POINT
      A property for structures that have a defined rotation point.
  • Constructor Details

    • Property

      public Property(NamespacedKey namespacedKey, Class<T> type, @Nullable T defaultValue, PropertyAccessLevel propertyAccessLevel, PropertyScope... scopes)
      Creates a new property.
      Parameters:
      namespacedKey - The namespace and key of the property.
      type - The type of the property.
      defaultValue - The default value of the property.

      This is the value that will be used if a structure whose type has this property does not have a value set for this property.

      propertyAccessLevel - The level of access users have to this property.
      scopes - The scopes in which this property is used.

      This is used to prevent side effects of changing the property value. For example, clearing cached values related to the property, such as the animation range when changing the blocks to move.

    • Property

      public Property(String owner, String name, Class<T> type, @Nullable T defaultValue, PropertyAccessLevel propertyAccessLevel, PropertyScope... scopes)
      Creates a new property.
      Parameters:
      owner - The name of the plugin that owns this property. This is used to prevent conflicts between properties between different plugins.

      All properties supplied by this plugin are set to Constants.PLUGIN_NAME.

      Properties from other plugins should use the name of the plugin that owns the property.

      name - The name of the property that is used for serialization.
      type - The type of the property.
      defaultValue - The default value of the property.

      This is the value that will be used if a structure whose type has this property does not have a value set for this property.

      propertyAccessLevel - The level of access users have to this property.
      scopes - The scopes in which this property is used.

      This is used to prevent side effects of changing the property value. For example, clearing cached values related to the property, such as the animation range when changing the blocks to move.

  • Method Details

    • fromName

      @Nullable public static @Nullable Property<?> fromName(String propertyKey)
      Gets the property with the given serialization name.

      Shortcut for Property.Registry.fromName(String) with REGISTRY.

      Parameters:
      propertyKey - The serialization name of the property.
      Returns:
      The property with the given serialization name, or null if no property with that name exists.
    • cast

      @Nullable public T cast(@Nullable @Nullable Object value)
      Casts the given value to the type of the property.

      This method is a wrapper around Class.cast(Object) for getType().

      Parameters:
      value - The value to cast.
      Returns:
      The value cast to the type of the property.
      Throws:
      ClassCastException - If the value cannot be cast to the type of the property.
    • toString

      public String toString()
      Overrides:
      toString in class Object
    • equals

      public boolean equals(Object o)
      Overrides:
      equals in class Object
    • hashCode

      public int hashCode()
      Overrides:
      hashCode in class Object
    • getNamespacedKey

      public NamespacedKey getNamespacedKey()
      The namespace and key of the property.

      Note that this name should be unique for each property.

      Specified by:
      getNamespacedKey in interface IKeyed
      Returns:
      The name of the property.
    • getPropertyAccessLevel

      public PropertyAccessLevel getPropertyAccessLevel()
      The type of the property.
      Returns:
      The type of the property.
    • getType

      public Class<T> getType()
      The type of the property.
      Returns:
      The type of the property.
    • getDefaultValue

      @Nullable public T getDefaultValue()
      The default value of the property.
      Returns:
      The default value of the property.
    • getPropertyScopes

      public List<PropertyScope> getPropertyScopes()
      The scopes in which this property is used.