Class CustomDataField<T>

java.lang.Object
com.palmergames.bukkit.towny.object.metadata.CustomDataField<T>
All Implemented Interfaces:
Cloneable
Direct Known Subclasses:
BooleanDataField, ByteDataField, DecimalDataField, IntegerDataField, ListDataField, LocationDataField, LongDataField, StringDataField

public abstract class CustomDataField<T> extends Object implements Cloneable
  • Field Details

    • label

      protected String label
  • Constructor Details

    • CustomDataField

      public CustomDataField(String key, T value, String label)
    • CustomDataField

      public CustomDataField(String key, T value)
    • CustomDataField

      public CustomDataField(String key, String label)
    • CustomDataField

      public CustomDataField(String key)
  • Method Details

    • getTypeID

      @NotNull public abstract @NotNull String getTypeID()
      Gets the type id for the given CustomDataField class. This value is attached to the class, and not a specific instance. Used for serialization purposes.
      Returns:
      type id of the given CustomDataField class.
    • getValue

      public T getValue()
    • setValue

      public void setValue(T value)
    • setValueFromString

      public abstract void setValueFromString(String strValue)
      Sets the value based on the given input. Used when admins want to edit metadata in-game.
      Parameters:
      strValue - input.
    • serializeValueToString

      @Nullable protected @Nullable String serializeValueToString()
      Serializes the current value to a string. Used for saving the CustomDataField object.
      Returns:
      serialized string
    • getKey

      @NotNull public @NotNull String getKey()
    • shouldDisplayInStatus

      public boolean shouldDisplayInStatus()
    • getLabel

      @NotNull public @NotNull String getLabel()
    • getLabelAsComp

      @NotNull public @NotNull net.kyori.adventure.text.Component getLabelAsComp()
      Get label as a formatted component.

      This function is intentionally overridable by child classes.

      Returns:
      formatted label component.
    • hasLabel

      public boolean hasLabel()
    • setLabel

      public void setLabel(String label)
    • toString

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

      protected boolean canParseFromString(String strValue)
      Determines whether the given input can be parsed to the appropriate value. Used to parse admin input for in-game metadata editing.
      Parameters:
      strValue - admin input
      Returns:
      whether the string can be parsed or not
    • isValidType

      public final void isValidType(String str) throws InvalidMetadataTypeException
      Throws:
      InvalidMetadataTypeException
    • displayFormattedValue

      protected abstract String displayFormattedValue()
      Formats and colors the value of the custom data field object.
      Returns:
      the formatted value of this data field.
    • formatValueAsComp

      public net.kyori.adventure.text.Component formatValueAsComp()
      Get the value as a formatted component.

      This function is intentionally overridable by child classes.

      Returns:
      formatted component of value.
    • equals

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

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

      @NotNull public abstract @NotNull CustomDataField<T> clone()
      Overrides:
      clone in class Object