Package redempt.redlib.blockdata
Class BlockDataManager
java.lang.Object
redempt.redlib.blockdata.BlockDataManager
- All Implemented Interfaces:
org.bukkit.event.Listener
Manages
DataBlock instances, which allow you to attach persistent metadata to blocks,
Keeps track of managed blocks, removing data if a block is destroyed or moving it if a block is pushed
by a piston.-
Field Summary
Fields -
Constructor Summary
ConstructorsConstructorDescriptionBlockDataManager(Path saveFile) Create a BlockDataManager instance with a save file location, to be saved to and loaded from. -
Method Summary
Modifier and TypeMethodDescriptionensureExists(org.bukkit.World world, redempt.redlib.blockdata.BlockDataManager.ChunkPosition pos) getAll()Loads and returns a set of all DataBlocks managed by this BlockDataManager.static List<BlockDataManager>getDataBlock(org.bukkit.block.Block block) Gets a DataBlock from a given Block, creating a new one if that Block had no data attached to it.getExisting(org.bukkit.block.Block block) Gets an existing DataBlock, returning null if that Block has no data attached to it.getLoaded(org.bukkit.Chunk chunk) Gets all the loaded DataBlocks in a chunkgetLoaded(org.bukkit.World world, int cx, int cz) Gets all the loaded DataBlocks in a chunkgetNearby(org.bukkit.Location loc, int radius) Gets all the DataBlocks near an approximate locationbooleanisChunkLoaded(org.bukkit.Chunk chunk) booleanisChunkLoaded(org.bukkit.World world, int cx, int cz) load(org.bukkit.Chunk chunk) Loads all of the DataBlocks in a given chunk, or retrieves the already-loaded set of DataBlocksload(org.bukkit.World world, int cx, int cz) Loads all of the DataBlocks in a given chunk, or retrieves the already-loaded set of DataBlocksvoidonBlockExplode(org.bukkit.event.block.BlockExplodeEvent e) voidonBlockPull(org.bukkit.event.block.BlockPistonRetractEvent e) voidonBlockPush(org.bukkit.event.block.BlockPistonExtendEvent e) voidonBreakBlock(org.bukkit.event.block.BlockBreakEvent e) voidonBucketEmpty(org.bukkit.event.player.PlayerBucketEmptyEvent e) voidonBurnBlock(org.bukkit.event.block.BlockBurnEvent e) voidonChunkUnload(org.bukkit.event.world.ChunkUnloadEvent e) voidonEntityExplode(org.bukkit.event.entity.EntityExplodeEvent e) voidonFlowBreakBlock(org.bukkit.event.block.BlockFromToEvent e) protected voidvoidRemoves a DataBlock from this DataBlockManagervoidsave()Saves all data to the save file.voidSaves all data to the save file, and closes the SQL connection.voidsetAutoSave(boolean autoSave) Sets whether this BlockDataManager will automatically save every 5 minutes.voidsetAutoUnload(boolean autoUnload) Sets whether this BlockDataManager will automatically unload chunks of DataBlocks when a chunk is unloadedprotected redempt.redlib.blockdata.BlockDataManager.ChunkPositiontoChunkPosition(org.bukkit.block.Block block) protected redempt.redlib.blockdata.BlockDataManager.ChunkPositiontoChunkPosition(org.bukkit.Location loc) tryExists(org.bukkit.World world, redempt.redlib.blockdata.BlockDataManager.ChunkPosition pos) voidunload(org.bukkit.Chunk chunk) Saves and unloads all of the DataBlocks in a chunkvoidunload(org.bukkit.World world, int cx, int cz) Saves and unloads all of the DataBlocks in a chunkvoidSaves and unloads all DataBlocks from this BlockDataManager
-
Field Details
-
sql
-
-
Constructor Details
-
BlockDataManager
Create a BlockDataManager instance with a save file location, to be saved to and loaded from. This constructor immediately loads from the given file.- Parameters:
saveFile- The Path to load from immediately, and save to when save is called
-
-
Method Details
-
getAllManagers
- Returns:
- The list of all active BlockDataManagers
-
setAutoSave
public void setAutoSave(boolean autoSave) Sets whether this BlockDataManager will automatically save every 5 minutes. Defaults to true.- Parameters:
autoSave- Whether to save automatically every 5 minutes
-
setAutoUnload
public void setAutoUnload(boolean autoUnload) Sets whether this BlockDataManager will automatically unload chunks of DataBlocks when a chunk is unloaded- Parameters:
autoUnload- Whether to automatically unload DataBlocks
-
save
public void save()Saves all data to the save file. -
saveAndClose
public void saveAndClose()Saves all data to the save file, and closes the SQL connection. Call this in your onDisable. -
ensureExists
-
tryExists
-
toChunkPosition
protected redempt.redlib.blockdata.BlockDataManager.ChunkPosition toChunkPosition(org.bukkit.Location loc) -
toChunkPosition
protected redempt.redlib.blockdata.BlockDataManager.ChunkPosition toChunkPosition(org.bukkit.block.Block block) -
getExisting
Gets an existing DataBlock, returning null if that Block has no data attached to it.- Parameters:
block- The block to check- Returns:
- A DataBlock, or null
-
getDataBlock
Gets a DataBlock from a given Block, creating a new one if that Block had no data attached to it.- Parameters:
block- The block to check or create a DataBlock from- Returns:
- An existing or new DataBlock
-
register
-
remove
Removes a DataBlock from this DataBlockManager- Parameters:
db- The DataBlock to remove
-
getNearby
Gets all the DataBlocks near an approximate location- Parameters:
loc- The location to check nearradius- The radius to check in- Returns:
- The nearby DataBlocks
-
getLoaded
Gets all the loaded DataBlocks in a chunk- Parameters:
chunk- The chunk to get the loaded DataBlocks in- Returns:
- A set of DataBlocks in the chunk, or null if the chunk is not loaded
-
getLoaded
Gets all the loaded DataBlocks in a chunk- Parameters:
world- The world the chunk is incx- The chunk Xcz- The chunk Z- Returns:
- A set of DataBlocks in the chunk, or an empty set if the chunk is not loaded
-
load
Loads all of the DataBlocks in a given chunk, or retrieves the already-loaded set of DataBlocks- Parameters:
world- The world the chunk is incx- The chunk Xcz- The chunk Z- Returns:
- The set of DataBlocks in the chunk
-
load
Loads all of the DataBlocks in a given chunk, or retrieves the already-loaded set of DataBlocks- Parameters:
chunk- The chunk to load DataBlocks in- Returns:
- The set of DataBlocks in the chunk
-
unload
public void unload(org.bukkit.World world, int cx, int cz) Saves and unloads all of the DataBlocks in a chunk- Parameters:
world- The world the chunk is incx- The chunk Xcz- The chunk Z
-
unload
public void unload(org.bukkit.Chunk chunk) Saves and unloads all of the DataBlocks in a chunk- Parameters:
chunk- The chunk to unload the DataBlocks in
-
unloadAll
public void unloadAll()Saves and unloads all DataBlocks from this BlockDataManager -
isChunkLoaded
public boolean isChunkLoaded(org.bukkit.Chunk chunk) - Parameters:
chunk- The chunk to check- Returns:
- Whether the DataBlocks in the chunk are loaded in this BlockDataManager
-
isChunkLoaded
public boolean isChunkLoaded(org.bukkit.World world, int cx, int cz) - Parameters:
world- The world the chunk is incx- The X coordinate of the chunkcz- The Z coordinate of the chunk- Returns:
- Whether the DataBlocks in the chunk are loaded in this BlockDataManager
-
getAllLoaded
- Returns:
- The set of all loaded DataBlocks
-
getAll
Loads and returns a set of all DataBlocks managed by this BlockDataManager. Avoid calling this if possible. Will not return DataBlocks in unloaded worlds.- Returns:
- The set of all DataBlocks managed by this BlockDataManager
-
onBreakBlock
public void onBreakBlock(org.bukkit.event.block.BlockBreakEvent e) -
onBucketEmpty
public void onBucketEmpty(org.bukkit.event.player.PlayerBucketEmptyEvent e) -
onFlowBreakBlock
public void onFlowBreakBlock(org.bukkit.event.block.BlockFromToEvent e) -
onBurnBlock
public void onBurnBlock(org.bukkit.event.block.BlockBurnEvent e) -
onEntityExplode
public void onEntityExplode(org.bukkit.event.entity.EntityExplodeEvent e) -
onBlockExplode
public void onBlockExplode(org.bukkit.event.block.BlockExplodeEvent e) -
onBlockPush
public void onBlockPush(org.bukkit.event.block.BlockPistonExtendEvent e) -
onBlockPull
public void onBlockPull(org.bukkit.event.block.BlockPistonRetractEvent e) -
onChunkUnload
public void onChunkUnload(org.bukkit.event.world.ChunkUnloadEvent e)
-