Class TownyObject

java.lang.Object
com.palmergames.bukkit.towny.object.TownyObject
All Implemented Interfaces:
Nameable, Savable
Direct Known Subclasses:
Government, ObjectGroup, Resident, TownBlock, TownyWorld

public abstract class TownyObject extends Object implements Nameable, Savable
  • Constructor Details

    • TownyObject

      protected TownyObject(String name)
  • Method Details

    • setName

      public void setName(String name)
    • getName

      public String getName()
      Description copied from interface: Nameable
      Get the name of the specified object
      Specified by:
      getName in interface Nameable
      Returns:
      A String representing the name of the object.
    • getTreeString

      public List<String> getTreeString(int depth)
    • getTreeDepth

      public String getTreeDepth(int depth)
    • toString

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

      public void addMetaData(@NotNull @NotNull CustomDataField<?> md)
      Add a specific metadata to this TownyObject. Overrides existing metadata of the same key. Most implementations will save the object after this method is called.
      Parameters:
      md - CustomDataField to add.
    • addMetaData

      public void addMetaData(@NotNull @NotNull CustomDataField<?> md, boolean save)
      Add a specific metadata to this TownyObject. Overrides existing metadata of the same key.
      Parameters:
      md - CustomDataField to add.
      save - whether to save this object after the metadata is added.
    • removeMetaData

      public void removeMetaData(@NotNull @NotNull CustomDataField<?> md)
      Remove a specific metadata from the TownyObject. The metadata does not need to be the same instance of the one added, but must have the same key. Most implementations will save the TownyObject after removing the metadata.
      Parameters:
      md - CustomDataField to remove.
    • removeMetaData

      public boolean removeMetaData(@NotNull @NotNull CustomDataField<?> md, boolean save)
      Remove a specific metadata from the TownyObject. The metadata does not need to be the same instance of the one added, but must have the same key.
      Parameters:
      md - CustomDataField to remove.
      save - whether to save the object or not after the metadata is removed.
      Returns:
      whether the metadata was successfully removed.
    • removeMetaData

      public boolean removeMetaData(@NotNull @NotNull String key)
      Remove a specific metadata from the TownyObject. Most implementations will save the TownyObject after removing the metadata.
      Parameters:
      key - Key of the data field to remove.
      Returns:
      whether the metadata was successfully removed.
    • removeMetaData

      public boolean removeMetaData(@NotNull @NotNull String key, boolean save)
      Remove a specific metadata from the TownyObject.
      Parameters:
      key - Key of the data field to remove.
      save - whether to save the object or not after the metadata is removed.
      Returns:
      whether the metadata was successfully removed.
    • getMetadata

      public @Unmodifiable Collection<CustomDataField<?>> getMetadata()
      A collection of all metadata on the TownyObject. This collection cannot be modified. Collection reflects current metadata, and is not thread safe.
      Returns:
      an unmodifiable collection of all metadata on the object.
    • getMetadata

      @Nullable public @Nullable CustomDataField<?> getMetadata(@NotNull @NotNull String key)
      Fetch the metadata associated with the specific key.
      Parameters:
      key - Key of the metadata to fetch.
      Returns:
      the metadata associated with the key or null if none associated.
    • getMetadata

      @Nullable public <T extends CustomDataField<?>> T getMetadata(@NotNull @NotNull String key, @NotNull @NotNull Class<T> cdfClass)
      Fetch the metadata associated with the specific key and class.
      Type Parameters:
      T - The Class.
      Parameters:
      key - Key of the metadata to fetch.
      cdfClass - Class of the CustomDataField to fetch.
      Returns:
      the specific metadata associated with the key and class or null if none exist.
    • hasMeta

      public boolean hasMeta()
      Returns:
      whether this object has metadata or not.
    • hasMeta

      public boolean hasMeta(@NotNull @NotNull String key)
      Check whether metadata associated with the key exists.
      Parameters:
      key - Key of the metadata to check.
      Returns:
      whether metadata associated with the key exists.
    • hasMeta

      public <T extends CustomDataField<?>> boolean hasMeta(@NotNull @NotNull String key, @NotNull @NotNull Class<T> cdfClass)
      Check whether metadata associated with the given key and class exists.
      Type Parameters:
      T - The Class.
      Parameters:
      key - Key of the metadata to check
      cdfClass - Class extending CustomDataField to check.
      Returns:
      whether metadata associated with the key and class exists.
    • exists

      @Internal public abstract boolean exists()
      An internal method used to determine if an object exists in the TownyUniverse's maps.
      Returns:
      true if this TownyObject exists.