Class CacheManager
java.lang.Object
com.ranull.graves.manager.CacheManager
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidaddEntityData(EntityData entityData) Adds or replaces tracked entity data in the cache.voidaddRightClickedBlock(String playerName, org.bukkit.Location location) Adds a right-clicked block location for a specified player.booleancanAccessGrave(UUID graveUUID, UUID viewerUUID) Checks if a player can access a grave right now.voidclearAllGraveViewersFor(UUID viewerUUID) Clears any grave-viewer locks held by the specified player.voidclearGraveViewer(UUID graveUUID) Force-clears the viewer lock for a grave (regardless of who is viewing).Returns the map of chunk identifiers to their correspondingChunkDataobjects.getEntityData(UUID entityUUID) Retrieves tracked entity data by entity UUID.Returns the map of entity UUIDs to their correspondingEntityData.Retrieves aGravefrom the cache by its UUIDgetGrave(org.bukkit.block.Block block) Convenience method to retrieve aGravefrom the cache based on aBlock.getGrave(org.bukkit.Location location) Retrieves theGravewhose block is located at the givenLocation.Returns the map of grave UUIDs to their correspondingGraveobjects.getGraveViewer(UUID graveUUID) Gets the UUID of the player currently viewing a grave, ornullif none.Returns the map of entity UUIDs to their last knownLocation.getOldestGrave(UUID playerUUID) Returns the oldest grave for a given player.Returns the map of entity UUIDs to lists of removedItemStackobjects.org.bukkit.LocationgetRightClickedBlock(String playerName) Retrieves the location of the right-clicked block for a specified player.booleanhasRightClickedBlock(String playerName) Checks if a right-clicked block location exists for a specified player.booleanisGraveBeingViewed(UUID graveUUID) Checks whether a grave is currently being viewed by someone.voidremoveEntityData(EntityData entityData) Removes tracked entity data from the cache.voidremoveEntityData(UUID entityUUID) Removes tracked entity data from the cache by entity UUID.voidremoveRightClickedBlock(String playerName, org.bukkit.Location location) Removes the right-clicked block location for a specified player.booleanstartViewingGrave(UUID graveUUID, UUID viewerUUID) Marks a grave as currently being viewed by the given player.voidstopViewingGrave(UUID graveUUID, UUID viewerUUID) Clears the viewer lock for a grave if the given player is the current viewer.
-
Constructor Details
-
CacheManager
public CacheManager()Constructs a newCacheManagerwith initialized maps.The constructor initializes all the maps used for caching data related to graves, chunks, locations, and items
-
-
Method Details
-
getGraveMap
-
addRightClickedBlock
Adds a right-clicked block location for a specified player.- Parameters:
playerName- the name of the playerlocation- the location of the right-clicked block
-
getRightClickedBlock
Retrieves the location of the right-clicked block for a specified player.- Parameters:
playerName- the name of the player- Returns:
- the location of the right-clicked block, or
nullif not found
-
removeRightClickedBlock
Removes the right-clicked block location for a specified player.- Parameters:
playerName- the name of the playerlocation- the location of the right-clicked block
-
hasRightClickedBlock
Checks if a right-clicked block location exists for a specified player.- Parameters:
playerName- the name of the player- Returns:
trueif the right-clicked block location exists,falseotherwise
-
getChunkMap
-
getLastLocationMap
-
getRemovedItemStackMap
-
startViewingGrave
Marks a grave as currently being viewed by the given player.If the grave is already being viewed by someone else, this will NOT overwrite the current viewer. Use
canAccessGrave(UUID, UUID)/isGraveBeingViewed(UUID)to check first.- Parameters:
graveUUID- the grave UUIDviewerUUID- the player's UUID- Returns:
trueif the viewer was set (lock acquired),falseif someone else already holds it
-
stopViewingGrave
-
clearGraveViewer
Force-clears the viewer lock for a grave (regardless of who is viewing). Useful for cleanup if a viewer disconnects unexpectedly.- Parameters:
graveUUID- the grave UUID
-
clearAllGraveViewersFor
Clears any grave-viewer locks held by the specified player. Useful to call on PlayerQuitEvent.- Parameters:
viewerUUID- the player's UUID
-
isGraveBeingViewed
Checks whether a grave is currently being viewed by someone.- Parameters:
graveUUID- the grave UUID- Returns:
trueif the grave is being viewed, otherwisefalse
-
getGraveViewer
-
canAccessGrave
Checks if a player can access a grave right now.Access is allowed if the grave is not being viewed, or if it is being viewed by the same player.
- Parameters:
graveUUID- the grave UUIDviewerUUID- the player's UUID- Returns:
trueif access is allowed, otherwisefalse
-
getGrave
-
getGrave
Convenience method to retrieve aGravefrom the cache based on aBlock.Internally delegates to
getGrave(Location)using the block's location.- Parameters:
block- the block to check- Returns:
- the matching
Grave, ornullif none is found
-
getOldestGrave
-
getGrave
Retrieves theGravewhose block is located at the givenLocation.This compares block coordinates (world + block X/Y/Z) instead of raw double coordinates to ensure it matches the actual block the grave is placed on.
- Parameters:
location- the location of the grave block- Returns:
- the matching
Grave, ornullif none is found
-
getEntityMap
Returns the map of entity UUIDs to their correspondingEntityData.- Returns:
- the entity map
-
getEntityData
Retrieves tracked entity data by entity UUID.- Parameters:
entityUUID- the entity UUID- Returns:
- the tracked entity data, or
nullif not cached
-
addEntityData
Adds or replaces tracked entity data in the cache.- Parameters:
entityData- the entity data to cache
-
removeEntityData
Removes tracked entity data from the cache by entity UUID.- Parameters:
entityUUID- the entity UUID
-
removeEntityData
Removes tracked entity data from the cache.- Parameters:
entityData- the entity data to remove
-