Package redempt.redlib.blockdata
Class BlockDataManager
java.lang.Object
redempt.redlib.blockdata.BlockDataManager
Manages persistent data attached to blocks, backed by either SQLite or chunk PersistentDataContainers
-
Method Summary
Modifier and TypeMethodDescriptionstatic 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 otherwisestatic BlockDataManager
createPDC
(org.bukkit.plugin.Plugin plugin, boolean autoLoad, boolean events) Creates a BlockDataManager backed by chunk PersistentDataContainersstatic BlockDataManager
createSQLite
(org.bukkit.plugin.Plugin plugin, Path path, boolean autoLoad, boolean events) Creates a BlockDataManager backed by SQLitegetDataBlock
(org.bukkit.block.Block block) Gets a DataBlock, creating one if it doesn't existgetDataBlock
(org.bukkit.block.Block block, boolean create) Gets a DataBlock for the given BlockgetDataBlockAsync
(org.bukkit.block.Block block, boolean create) Asynchronously retrieves a DataBlockgetLoaded
(org.bukkit.World world, int cx, int cz) Gets the DataBlocks for a given chunk, if it is loaded alreadyorg.bukkit.plugin.Plugin
boolean
isLoaded
(org.bukkit.World world, int cx, int cz) Checks whether the DataBlocks for a given chunk are loadedvoid
load
(org.bukkit.World world, int cx, int cz) Loads the data for a chunk synchronouslyloadAll()
Loads all DataBlocks stored by this BlockDataManager.loadAsync
(org.bukkit.World world, int cx, int cz) Loads the data for a chunk asynchronouslyboolean
migrate()
Attempts to migrate SQLite from an older version of the database from the previous BlockDataManager libraryMoves a DataBlock to a new locationMoves a DataBlock to a new location asynchronouslyvoid
Removes a DataBlock and its data from this BlockDataManagervoid
save()
Saves all data loaded in this BlockDataManagervoid
Saves all data loaded in this BlockDataManager and closes connections where neededprotected void
setModified
(ChunkPosition pos) void
unload
(org.bukkit.World world, int cx, int cz) Unloads the data for a chunk synchronouslyunloadAsync
(org.bukkit.World world, int cx, int cz) Unloads the data for a chunk asynchronously
-
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 dataautoLoad
- Whether to automatically load data for newly-loaded chunks asynchronouslyevents
- 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 datapath
- The path to the SQLite databaseautoLoad
- Whether to automatically load data for newly-loaded chunksevents
- 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 datapath
- The path to the SQLite databaseautoLoad
- Whether to automatically load data for newly-loaded chunksevents
- 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
Asynchronously retrieves a DataBlock- Parameters:
block
- The Block the data is attached tocreate
- 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
-
getDataBlock
Gets a DataBlock, creating one if it doesn't exist- Parameters:
block
- The Block data will be attached to- Returns:
- A DataBlock
-
remove
Removes a DataBlock and its data from this BlockDataManager- Parameters:
db
- The DataBlock to remove
-
moveAsync
Moves a DataBlock to a new location asynchronously- Parameters:
db
- The DataBlock whose data should be movedlocation
- The Block to move the data to- Returns:
- A CompletableFuture for the moving task
-
move
Moves a DataBlock to a new location- Parameters:
db
- The DataBlock whose data should be movedblock
- The Block to move the data to- Returns:
- The new DataBlock
-
loadAsync
Loads the data for a chunk asynchronously- Parameters:
world
- The world the data is incx
- The chunk X of the chunk the data is incz
- 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 incx
- The chunk X of the chunk the data is incz
- The chunk Z of the chunk the data is in
-
unloadAsync
Unloads the data for a chunk asynchronously- Parameters:
world
- The world the data is incx
- The chunk X of the chunk the data is incz
- 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 incx
- The chunk X of the chunk the data is incz
- The chunk Z of the chunk the data is in
-
getLoaded
Gets the DataBlocks for a given chunk, if it is loaded already- Parameters:
world
- The world the data is incx
- The chunk X of the chunk the data is incz
- 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 incx
- The chunk X of the chunk the data is incz
- The chunk Z of the chunk the data is in- Returns:
- Whether the DataBlocks for the given chunk are loaded
-
getDataBlock
Gets a DataBlock for the given Block- Parameters:
block
- The Block data will be attached tocreate
- Whether to create a new DataBlock if one does not exist already- Returns:
- The DataBlock, or null
-
loadAll
Loads all DataBlocks stored by this BlockDataManager. Not supported for PDC.- Returns:
- A CompletableFuture for the loading task.
-
getAllLoaded
- Returns:
- All DataBlocks currently loaded in this BlockDataManager
-