Class BlockDataManager

java.lang.Object
redempt.redlib.blockdata.BlockDataManager

public class BlockDataManager extends Object
Manages persistent data attached to blocks, backed by either SQLite or chunk PersistentDataContainers
  • Method Details

    • createPDC

      public static BlockDataManager createPDC(org.bukkit.plugin.Plugin plugin, boolean autoLoad, boolean events)
      Creates a BlockDataManager backed by chunk PersistentDataContainers
      Parameters:
      plugin - The Plugin that owns the data
      autoLoad - Whether to automatically load data for newly-loaded chunks asynchronously
      events - Whether to listen for events to automatically move and remove DataBlocks in response to their owning blocks being moved and removed
      Returns:
      The created BlockDataManager
    • createSQLite

      public static BlockDataManager createSQLite(org.bukkit.plugin.Plugin plugin, Path path, boolean autoLoad, boolean events)
      Creates a BlockDataManager backed by SQLite
      Parameters:
      plugin - The Plugin that owns the data
      path - The path to the SQLite database
      autoLoad - Whether to automatically load data for newly-loaded chunks
      events - Whether to listen for events to automatically move and remove DataBlocks in response to their owning blocks being moved and removed
      Returns:
      The created BlockDataManager
    • createAuto

      public static BlockDataManager createAuto(org.bukkit.plugin.Plugin plugin, Path path, boolean autoLoad, boolean events)
      Creates a BlockDataManager backed by SQLite if the server is running a version lower than 1.14, and chunk PersistentDataContainers otherwise
      Parameters:
      plugin - The Plugin that owns the data
      path - The path to the SQLite database
      autoLoad - Whether to automatically load data for newly-loaded chunks
      events - Whether to listen for events to automatically move and remove DataBlocks in response to their owning blocks being moved and removed
      Returns:
      The created BlockDataManager
    • getDataBlockAsync

      public CompletableFuture<DataBlock> getDataBlockAsync(org.bukkit.block.Block block, boolean create)
      Asynchronously retrieves a DataBlock
      Parameters:
      block - The Block the data is attached to
      create - Whether to create a new DataBlock if one does not exist for the given Block
      Returns:
      A CompletableFuture with the DataBlock
    • migrate

      public boolean migrate()
      Attempts to migrate SQLite from an older version of the database from the previous BlockDataManager library
      Returns:
      Whether a migration was completed successfully
    • getPlugin

      public org.bukkit.plugin.Plugin getPlugin()
      Returns:
      The plugin that owns this BlockDataManager
    • save

      public void save()
      Saves all data loaded in this BlockDataManager
    • saveAndClose

      public void saveAndClose()
      Saves all data loaded in this BlockDataManager and closes connections where needed
    • setModified

      protected void setModified(ChunkPosition pos)
    • getDataBlock

      public DataBlock getDataBlock(org.bukkit.block.Block block)
      Gets a DataBlock, creating one if it doesn't exist
      Parameters:
      block - The Block data will be attached to
      Returns:
      A DataBlock
    • remove

      public void remove(DataBlock db)
      Removes a DataBlock and its data from this BlockDataManager
      Parameters:
      db - The DataBlock to remove
    • moveAsync

      public CompletableFuture<DataBlock> moveAsync(DataBlock db, org.bukkit.block.Block location)
      Moves a DataBlock to a new location asynchronously
      Parameters:
      db - The DataBlock whose data should be moved
      location - The Block to move the data to
      Returns:
      A CompletableFuture for the moving task
    • move

      public DataBlock move(DataBlock db, org.bukkit.block.Block block)
      Moves a DataBlock to a new location
      Parameters:
      db - The DataBlock whose data should be moved
      block - The Block to move the data to
      Returns:
      The new DataBlock
    • loadAsync

      public CompletableFuture<Void> loadAsync(org.bukkit.World world, int cx, int cz)
      Loads the data for a chunk asynchronously
      Parameters:
      world - The world the data is in
      cx - The chunk X of the chunk the data is in
      cz - The chunk Z of the chunk the data is in
      Returns:
      A CompletableFuture for the loading task
    • load

      public void load(org.bukkit.World world, int cx, int cz)
      Loads the data for a chunk synchronously
      Parameters:
      world - The world the data is in
      cx - The chunk X of the chunk the data is in
      cz - The chunk Z of the chunk the data is in
    • unloadAsync

      public CompletableFuture<Void> unloadAsync(org.bukkit.World world, int cx, int cz)
      Unloads the data for a chunk asynchronously
      Parameters:
      world - The world the data is in
      cx - The chunk X of the chunk the data is in
      cz - The chunk Z of the chunk the data is in
      Returns:
      A CompletableFuture for the unloading task
    • unload

      public void unload(org.bukkit.World world, int cx, int cz)
      Unloads the data for a chunk synchronously
      Parameters:
      world - The world the data is in
      cx - The chunk X of the chunk the data is in
      cz - The chunk Z of the chunk the data is in
    • getLoaded

      public Collection<DataBlock> getLoaded(org.bukkit.World world, int cx, int cz)
      Gets the DataBlocks for a given chunk, if it is loaded already
      Parameters:
      world - The world the data is in
      cx - The chunk X of the chunk the data is in
      cz - The chunk Z of the chunk the data is in
      Returns:
      The DataBlocks if they are loaded, otherwise an empty collection
    • isLoaded

      public boolean isLoaded(org.bukkit.World world, int cx, int cz)
      Checks whether the DataBlocks for a given chunk are loaded
      Parameters:
      world - The world the data is in
      cx - The chunk X of the chunk the data is in
      cz - The chunk Z of the chunk the data is in
      Returns:
      Whether the DataBlocks for the given chunk are loaded
    • getDataBlock

      public DataBlock getDataBlock(org.bukkit.block.Block block, boolean create)
      Gets a DataBlock for the given Block
      Parameters:
      block - The Block data will be attached to
      create - Whether to create a new DataBlock if one does not exist already
      Returns:
      The DataBlock, or null
    • loadAll

      public CompletableFuture<Void> loadAll()
      Loads all DataBlocks stored by this BlockDataManager. Not supported for PDC.
      Returns:
      A CompletableFuture for the loading task.
    • getAllLoaded

      public Set<DataBlock> getAllLoaded()
      Returns:
      All DataBlocks currently loaded in this BlockDataManager