Class DataManager

java.lang.Object
com.ranull.graves.manager.DataManager

public final class DataManager extends Object
Manages data storage and retrieval for the Graves plugin.
  • Constructor Details

    • DataManager

      public DataManager(Graves plugin)
      Initializes the DataManager with the specified plugin instance and sets up the database connection.
      Parameters:
      plugin - the Graves plugin instance.
  • Method Details

    • getType

      public String getType()
    • reload

      public void reload()
      Reloads the data manager with the current type.
    • reload

      public void reload(DataManager.Type type)
      Reloads the data manager with the specified type.
      Parameters:
      type - the type of database.
    • loadType

      public void loadType(DataManager.Type type)
      Loads the database type and sets up the data source.
      Parameters:
      type - the type of database.
    • hasChunkData

      public boolean hasChunkData(org.bukkit.Location location)
      Checks if chunk data exists for a specified location.
      Parameters:
      location - the location to check.
      Returns:
      true if chunk data exists, false otherwise.
    • getChunkData

      public ChunkData getChunkData(org.bukkit.Location location)
      Retrieves chunk data for a specified location.
      Parameters:
      location - the location to retrieve chunk data for.
      Returns:
      the chunk data.
    • removeChunkData

      public void removeChunkData(ChunkData chunkData)
      Removes chunk data.
      Parameters:
      chunkData - the chunk data to remove.
    • getColumnList

      public List<String> getColumnList(String tableName)
      Retrieves a list of columns for a specified table.
      Parameters:
      tableName - the table name.
      Returns:
      the list of columns.
    • tableExists

      public boolean tableExists(String tableName)
      Checks if a table exists in the database.
      Parameters:
      tableName - the table name.
      Returns:
      true if the table exists, false otherwise.
    • setupGraveTable

      public void setupGraveTable() throws SQLException
      Sets up the grave table in the database.
      Throws:
      SQLException - if an SQL error occurs.
    • setupBlockTable

      public void setupBlockTable() throws SQLException
      Sets up the block table in the database.
      Throws:
      SQLException - if an SQL error occurs.
    • setupHologramTable

      public void setupHologramTable() throws SQLException
      Sets up the hologram table in the database.
      Throws:
      SQLException - if an SQL error occurs.
    • loadGraveMap

      public void loadGraveMap()
      Loads the grave map from the database.
    • loadBlockMap

      public void loadBlockMap()
      Loads the block map from the database (Folia-safe). - Reads DB asynchronously. - Batches rows per chunk and applies them on the chunk's region thread using plugin.getGravesXScheduler().execute(anchorLocation, ...).
    • loadHologramMap

      public void loadHologramMap()
      Loads the hologram map from the database.
    • addBlockData

      public void addBlockData(BlockData blockData)
      Adds block data to the database.
      Parameters:
      blockData - the block data to add.
    • removeBlockData

      public void removeBlockData(org.bukkit.Location location)
      Removes block data from the database.

      Uses GravesXScheduler (UniversalScheduler) to run the in-memory cache update at the block's location (Folia-safe). The database delete runs asynchronously.

      Parameters:
      location - the location of the block data to remove.
    • addHologramData

      public void addHologramData(HologramData hologramData)
      Adds hologram data to the database.

      Uses GravesXScheduler (UniversalScheduler) to execute the in-memory cache update at the hologram's location (Folia-safe). The database write is performed asynchronously.

      Parameters:
      hologramData - the hologram data to add.
    • removeHologramData

      public void removeHologramData(Grave grave)
      Removes hologram entries from the database based on the grave UUID. This is a fallback if entity data is not loaded in memory.
      Parameters:
      grave - the grave to remove hologram data.
    • addEntityData

      public void addEntityData(EntityData entityData)
      Adds entity data to the database.
      Parameters:
      entityData - the entity data to add.
    • removeEntityData

      public void removeEntityData(EntityData entityData)
      Removes entity data from the database.
      Parameters:
      entityData - the entity data to remove.
    • removeEntityData

      public void removeEntityData(List<EntityData> entityDataList)
      Removes a list of entity data from the database.
      Parameters:
      entityDataList - the list of entity data to remove.
    • hasGraveAtLocation

      @Deprecated(since="4.9.9.1", forRemoval=true) @ScheduledForRemoval(inVersion="4.9.11.1") public boolean hasGraveAtLocation(org.bukkit.Location location)
      Deprecated, for removal: This API element is subject to removal in a future version.
      Unused API. Deprecated as of 4.9.9.1 and scheduled for removal in 4.9.11.1.
      Checks whether a grave exists at the given location.

      Unused. This method is deprecated and will be removed.

      Parameters:
      location - the location to check
      Returns:
      true if a grave exists at the location; false otherwise
    • entityDataTypeTable

      public String entityDataTypeTable(EntityData.Type type)
      Returns the table name for the specified entity data type.
      Parameters:
      type - the entity data type.
      Returns:
      the table name.
    • addGrave

      public void addGrave(Grave grave)
      Adds a grave to the database.
      Parameters:
      grave - the grave to add.
    • removeGrave

      public void removeGrave(Grave grave)
      Removes a grave from the database.
      Parameters:
      grave - the grave to remove.
    • removeGrave

      public void removeGrave(UUID uuid)
    • updateGrave

      public void updateGrave(Grave grave, String column, int integer)
      Updates a grave in the database.
      Parameters:
      grave - the grave to update.
      column - the column to update.
      integer - the new integer value for the column.
    • updateGrave

      public void updateGrave(Grave grave, String column, String string)
      Updates a grave in the database.
      Parameters:
      grave - the grave to update.
      column - the column to update.
      string - the new value for the column.
    • updateGraveMainThread

      @Experimental public void updateGraveMainThread(Grave grave, String column, String string)
      Updates a grave in the database using the main thread.
      Parameters:
      grave - the grave to update.
      column - the column to update.
      string - the new value for the column.
    • resultSetToGrave

      public Grave resultSetToGrave(ResultSet resultSet)
      Converts a ResultSet to a Grave object.
      Parameters:
      resultSet - the ResultSet to convert.
      Returns:
      the Grave object, or null if an error occurs.
    • getDatabaseVersions

      public Map<String,Map<String,Integer>> getDatabaseVersions() throws SQLException
      Retrieves the versions of supported databases.
      Returns:
      a map of database types and their versions as integers.
      Throws:
      SQLException - if a database access error occurs.
    • getDatabaseVersion

      public String getDatabaseVersion()
      Retrieves the version of the database connection type.
      Returns:
      the database version as a string.
    • closeConnection

      public void closeConnection()
      Closes the database connection.