Package com.ranull.graves.manager
Class CacheManager
java.lang.Object
com.ranull.graves.manager.CacheManager
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidaddRightClickedBlock(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.intclearAllGraveViewersFor(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.Retrieves aGravefrom the cache by its UUIDReturns 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.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.booleanstopViewingGrave(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
Returns the map of grave UUIDs to their correspondingGraveobjects.- Returns:
- the map of graves
-
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
Returns the map of chunk identifiers to their correspondingChunkDataobjects.- Returns:
- the map of chunk data
-
getLastLocationMap
Returns the map of entity UUIDs to their last knownLocation.- Returns:
- the map of last known locations
-
getRemovedItemStackMap
Returns the map of entity UUIDs to lists of removedItemStackobjects.- Returns:
- the map of removed item stacks
-
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
Clears the viewer lock for a grave if the given player is the current viewer.- Parameters:
graveUUID- the grave UUIDviewerUUID- the player's UUID- Returns:
trueif the lock was cleared,falseif it was held by someone else or not set
-
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- Returns:
- number of locks removed
-
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
Gets the UUID of the player currently viewing a grave, ornullif none.- Parameters:
graveUUID- the grave UUID- Returns:
- the viewer UUID, or
null
-
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
Retrieves aGravefrom the cache by its UUID- Parameters:
graveUUID- the UUID of the grave to retrieve- Returns:
- the
Graveassociated with the UUID provided, ornullif not present
-
getOldestGrave
Returns the oldest grave for a given player.- Parameters:
playerUUID- The UUID of the player whose graves to consider.- Returns:
- The oldest grave for the specified player.
-