Class DataRegistry

java.lang.Object
me.thehandsomeyoni.persistentdataapi.manager.DataRegistry

public class DataRegistry extends Object
Handles all persistent data registry operations.
Since:
1.0
Author:
TheHandsomeYoni
  • Constructor Details

    • DataRegistry

      public DataRegistry(org.bukkit.entity.Player player) throws NullPointerException
      Initializes the DataRegistry of a player.
      Parameters:
      player - The player that the data is stored in.
      Throws:
      NullPointerException - If the player is null.
    • DataRegistry

      public DataRegistry(org.bukkit.inventory.ItemStack itemStack) throws NullPointerException
      Initializes the DataRegistry of an item.
      Parameters:
      itemStack - The item that the data is stored in.
      Throws:
      NullPointerException - If the item is null.
    • DataRegistry

      public DataRegistry(org.bukkit.block.Block block) throws UnacceptableBlockException, NullPointerException
      Initializes the DataRegistry of a block.
      Parameters:
      block - The block that the data is stored in.
      Throws:
      UnacceptableBlockException - If the block isn't acceptable/doesn't have a persistent data container.
      NullPointerException - If the block is null.
  • Method Details

    • registerData

      public void registerData(String dataName, Serializable dataValue) throws DataException
      Registers a new data with the given name and type.
      Parameters:
      dataName - the name of the data.
      dataValue - the value of the data.
      Throws:
      DataException - if the data already exists.
    • registerData

      public void registerData(AbstractPersistentData data) throws DataException
      Registers a new data from a class that extends AbstractPersistentData.
      Parameters:
      data - The data that is being registered. This data must extend AbstractPersistentData.
      Throws:
      DataException - if the data already exists.
    • unregisterData

      public void unregisterData(String dataName) throws DataException
      Removes a data from the data container.
      Parameters:
      dataName - The name of the data that is being removed.
      Throws:
      DataException
    • unregisterData

      public void unregisterData(AbstractPersistentData data) throws DataException
      Removes a data from the data container.
      Parameters:
      data - The data that is being removed.
      Throws:
      DataException
    • setData

      public void setData(AbstractPersistentData data)
      Changes the values of a data.
      Parameters:
      data - the data that is being changed.
    • setData

      public void setData(String dataName, Serializable dataValue)
      Changes the values of a data.
      Parameters:
      dataName - name of the data that is being changed.
      dataValue - the new value of the data.
    • getData

      public Serializable getData(String dataName) throws DataException
      Gets the value of a data.
      Parameters:
      dataName - the name of the data.
      Returns:
      the value of the data.
      Throws:
      DataException - if the data doesn't exist.
    • getData

      public Serializable getData(AbstractPersistentData data) throws DataException
      Gets the value of a data.
      Parameters:
      data - the data that is being gotten.
      Returns:
      the value of the data.
      Throws:
      DataException - if the data doesn't exist.
    • getAllData

      public HashMap<String,Serializable> getAllData()
    • getKeys

      public Set<String> getKeys()
    • getDataAsBytes

      public byte[] getDataAsBytes(String dataName) throws DataException
      Gets the value of a data as its primitive type.
      Parameters:
      dataName - the name of the data.
      Returns:
      the value of the data in bytes.
      Throws:
      DataException - if the data doesn't exist.
    • getDataAsBytes

      public byte[] getDataAsBytes(AbstractPersistentData data) throws DataException
      Gets the value of a data as its primitive type.
      Parameters:
      data - the data that is being gotten.
      Returns:
      the value of the data in bytes.
      Throws:
      DataException - if the data doesn't exist.
    • dataExists

      public boolean dataExists(String dataName)
      Checks if a data exists.
      Parameters:
      dataName - the name of the data.
      Returns:
      true if the data exists, false if it doesn't.
    • dataExists

      public boolean dataExists(AbstractPersistentData data)
      Checks if a data exists.
      Parameters:
      data - the data that is being checked.
      Returns:
      true if the data exists, false if it doesn't.