Class Property<T>

java.lang.Object
nl.pim16aap2.animatedarchitecture.core.structures.properties.Property<T>
Type Parameters:
T - The type of the value 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

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

    • builder

      public static <U> Property.PropertyBuilder<U> builder(String owner, String name, Class<U> type)
      Creates a new property builder.

      This is a shortcut for builder(NamespacedKey, Class).

      Type Parameters:
      U - The type of the value of the 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.
      Returns:
      The property builder.
    • builder

      public static <U> Property.PropertyBuilder<U> builder(NamespacedKey namespacedKey, Class<U> type)
      Creates a new property builder.
      Type Parameters:
      U - The type of the value of the property.
      Parameters:
      namespacedKey - The namespace and key of the property.
      type - The type of the property.
      Returns:
      The property builder.
    • getDebuggableRegistry

      public static IDebuggable getDebuggableRegistry()
      Gets the debuggable registry of all registered properties.
      Returns:
      The debuggable registry of all registered properties.
    • userHasAccessLevel

      public boolean userHasAccessLevel(PropertyAccessLevel propertyAccessLevel)
      Gets the full key of the property.
      Parameters:
      propertyAccessLevel - The access level to check.
      Returns:
      True if the user has the given access level.
    • adminHasAccessLevel

      public boolean adminHasAccessLevel(PropertyAccessLevel propertyAccessLevel)
      Checks if the admin has the given access level.
      Parameters:
      propertyAccessLevel - The access level to check.
      Returns:
      True if the admin has the given access level.
    • fromName

      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.
    • fromKey

      public static @Nullable Property<?> fromKey(NamespacedKey propertyKey)
      Gets the property with the given
      Parameters:
      propertyKey - The key of the property.
      Returns:
      The property with the given key, or null if no property with that key exists.
    • cast

      @Contract("null -> null; !null -> !null") public @Nullable T cast(@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.
    • getAccessLevel

      @CheckReturnValue public int getAccessLevel(ICommandSender commandSender, IStructureConst structure)
      Gets the access level to this property for the given command sender and structure.

      Defaults to 0 if the command sender is not an owner of the structure.

      The returned value is a bit flag whose values refer to the PropertyAccessLevel enum.

      Parameters:
      commandSender - The command sender to get the access level for.
      structure - The structure to get the access level for.
      Returns:
      The access level for the given command sender and structure.
    • getAccessLevel

      @CheckReturnValue public int getAccessLevel(PermissionLevel permissionLevel)
      Gets the access level for the given permission level.

      Defaults to 0 if the command sender is not an owner of the structure.

      The returned value is a bit flag whose values refer to the PropertyAccessLevel enum.

      Parameters:
      permissionLevel - The permission level to get the access level for.
      Returns:
      The access level for the given permission level.
    • toString

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

      public boolean equals(@Nullable 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.
    • getType

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

      public T getDefaultValue()
      The default value of the property.
      Returns:
      The default value of the property.
    • getUserAccessLevel

      public int getUserAccessLevel()
      The level of access users have to this property.

      This is a bit flag whose values refer to the PropertyAccessLevel enum.

    • getAdminAccessLevel

      public int getAdminAccessLevel()
      The level of access admins have to this property.

      This is a bit flag whose values refer to the PropertyAccessLevel enum.

    • getPropertyScopes

      public List<PropertyScope> getPropertyScopes()
      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.