Class GraveManager
-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate final Graves
The main plugin instance associated with Graves.private final ConcurrentHashMap
<String, org.bukkit.scheduler.BukkitTask> A thread-safe map that holds references to scheduledBukkitTask
instances. -
Constructor Summary
ConstructorsConstructorDescriptionGraveManager
(Graves plugin) Initializes the GraveManager with the specified plugin instance. -
Method Summary
Modifier and TypeMethodDescriptionvoid
abandonGrave
(Grave grave) Abandons a grave.private boolean
arePlayersInChunk
(org.bukkit.Chunk chunk) Checks if there are any players in the given chunk.void
autoLootGrave
(org.bukkit.entity.Entity entity, org.bukkit.Location location, Grave grave) Automatically loots a grave for a player.void
breakGrave
(Grave grave) Breaks a grave at its death location.void
breakGrave
(org.bukkit.Location location, Grave grave) Breaks a grave at the specified location.private void
Checks and updates graves, entities, and blocks, removing expired elements and triggering necessary events.void
cleanupCompasses
(org.bukkit.entity.Player player, Grave grave) Cleans up compasses from a player's inventory that are associated with a grave.void
closeGrave
(Grave grave) Closes any open inventories associated with a grave.createGrave
(org.bukkit.entity.Entity entity, List<org.bukkit.inventory.ItemStack> itemStackList) Creates a new grave for the specified entity and list of item stacks.createGrave
(org.bukkit.entity.Entity entity, List<org.bukkit.inventory.ItemStack> itemStackList, List<String> permissionList) Creates a new grave for the specified entity, list of item stacks, and permissions.org.bukkit.inventory.Inventory
createGraveInventory
(org.bukkit.inventory.InventoryHolder inventoryHolder, org.bukkit.Location location, List<org.bukkit.inventory.ItemStack> itemStackList, String title, Grave.StorageMode storageMode) Creates a grave inventory with the specified parameters.void
dropGraveExperience
(org.bukkit.Location location, Grave grave) Drops the experience from a grave at the specified location.void
dropGraveItems
(org.bukkit.Location location, Grave grave) Drops the items from a grave at the specified location.List
<org.bukkit.inventory.ItemStack> filterGraveItemStackList
(List<org.bukkit.inventory.ItemStack> itemStackList, List<org.bukkit.inventory.ItemStack> removedItemStackList, org.bukkit.entity.LivingEntity livingEntity, List<String> permissionList) Filters the grave item stack list based on the living entity, removed item stacks, and permission list.List
<org.bukkit.inventory.ItemStack> filterGraveItemStackList
(List<org.bukkit.inventory.ItemStack> itemStackList, org.bukkit.entity.LivingEntity livingEntity, List<String> permissionList) Filters the grave item stack list based on the living entity and permission list.Gets a list of all graves.getDamageReason
(org.bukkit.event.entity.EntityDamageEvent.DamageCause damageCause, Grave grave) Retrieves the damage reason for a specified damage cause and grave.int
getGraveCount
(org.bukkit.entity.Entity entity) Retrieves the number of graves associated with an entity.org.bukkit.inventory.Inventory
getGraveInventory
(Grave grave, org.bukkit.entity.LivingEntity livingEntity, List<org.bukkit.inventory.ItemStack> graveItemStackList, List<org.bukkit.inventory.ItemStack> removedItemStackList, List<String> permissionList) Retrieves the grave inventory for a specified grave and living entity.getGraveList
(UUID uuid) Retrieves a list of graves associated with a UUID.getGraveList
(org.bukkit.entity.Entity entity) Retrieves a list of graves associated with an entity.getGraveList
(org.bukkit.entity.Player player) Retrieves a list of graves associated with a player.getGraveList
(org.bukkit.OfflinePlayer player) Retrieves a list of graves associated with an offline player.org.bukkit.Location
getGraveLocation
(org.bukkit.Location location, Grave grave) Retrieves the nearest grave location to a specified location.List
<org.bukkit.Location> getGraveLocationList
(org.bukkit.Location baseLocation, Grave grave) Retrieves a list of locations associated with a grave.int
getItemStacksSize
(org.bukkit.inventory.ItemStack[] itemStacks) Gets the size of the item stacks array.getStorageMode
(String string) Retrieves the storage mode for a given string representation.void
giveGraveExperience
(org.bukkit.entity.Player player, Grave grave) Gives the experience from a grave to a player.void
graveParticle
(org.bukkit.Location location, Grave grave) Spawns particle effects around a grave.private void
handleGraveTimeout
(Grave grave, List<Grave> graveRemoveList) Handles the timeout or abandonment of a grave by firing the GraveTimeoutEvent and then either dropping its contents (timeout) or moving it into abandoned logic.boolean
hasGraveAtLocation
(org.bukkit.Location location) Checks if there is a grave at the specified location.boolean
isGraveAbandoned
(Grave grave) Checks if a block should be ignored based on the entity and permissions.boolean
isGravePlaced
(Grave grave) Determines if the grave is placed in the world by checking for any physical block or entity presence at the grave's location.boolean
isNearGrave
(org.bukkit.Location location) Checks if the given location is within configured blocks of any grave.boolean
isNearGrave
(org.bukkit.Location location, org.bukkit.block.Block block) Overload for block-specific checks.boolean
isNearGrave
(org.bukkit.Location location, org.bukkit.entity.Player player) Overload for player-specific checks.boolean
isNearGrave
(org.bukkit.Location location, org.bukkit.entity.Player player, org.bukkit.block.Block block) Checks if the given location is within configured blocks of any grave.boolean
Opens a grave for a player.boolean
openGrave
(org.bukkit.entity.Entity entity, org.bukkit.Location location, Grave grave, boolean preview) Opens a grave for a player.void
placeGrave
(org.bukkit.Location location, Grave grave) Places a grave at a specified location.void
playEffect
(String string, org.bukkit.Location location) Plays an effect at a specified location.void
playEffect
(String string, org.bukkit.Location location, int data, Grave grave) Plays an effect at a specified location with additional data for a grave.void
playEffect
(String string, org.bukkit.Location location, Grave grave) Plays an effect at a specified location for a grave.private void
processBlockData
(ChunkData chunkData, List<BlockData> blockDataRemoveList) Processes the block data within the given chunk.private void
processChunks
(List<EntityData> entityDataRemoveList, List<BlockData> blockDataRemoveList) Processes all chunks to handle entities and blocks within them.private void
processEntityData
(ChunkData chunkData, List<EntityData> entityDataRemoveList, org.bukkit.Location location) Processes the entity data within the given chunk.private void
processGraves
(List<Grave> graveRemoveList) Processes all graves to check their remaining time and protection status.private void
processHologramData
(HologramData hologramData, org.bukkit.Location location, List<EntityData> entityDataRemoveList) Processes hologram data within the chunk.void
removeEntityData
(EntityData entityData) Removes entity data associated with a grave.private void
removeExpiredElements
(List<Grave> graveRemoveList, List<EntityData> entityDataRemoveList, List<BlockData> blockDataRemoveList) Removes expired graves, entities, and blocks from the system.void
removeGrave
(Grave grave) Removes a grave and its associated data.void
removeOldestGrave
(org.bukkit.entity.LivingEntity livingEntity) Removes the oldest grave.private void
Restores graves that are in cache but missing from the world.private void
sendPlayerMessage
(Grave grave, String messageKey, org.bukkit.Location location) Utility to send a message to the grave owner if they're online.boolean
shouldIgnoreBlock
(org.bukkit.block.Block block, org.bukkit.entity.Entity entity, Grave grave) Deprecated.This method is deprecated.boolean
shouldIgnoreBlock
(org.bukkit.block.Block block, org.bukkit.entity.Entity entity, List<String> permissionList) Checks if a block should be ignored based on the entity and permissions.boolean
shouldIgnoreItemStack
(org.bukkit.inventory.ItemStack itemStack, org.bukkit.entity.Entity entity, Grave grave) Checks if an item stack should be ignored based on the entity and grave.boolean
shouldIgnoreItemStack
(org.bukkit.inventory.ItemStack itemStack, org.bukkit.entity.Entity entity, List<String> permissionList) Checks if an item stack should be ignored based on the entity and permissions.private void
Starts the grave timer task that periodically checks and updates graves.void
toggleGraveProtection
(Grave grave) Toggles the protection state of a grave.void
unload()
Unloads all open grave inventories for online players.
-
Field Details
-
plugin
The main plugin instance associated with Graves.This
Graves
instance represents the core plugin that this Graves is part of. It provides access to the plugin's functionality, configuration, and other services. -
tasks
A thread-safe map that holds references to scheduledBukkitTask
instances.The key is a unique identifier for the task, typically based on the specific action or entity associated with the task. This map allows for efficient tracking and management of scheduled tasks, including the ability to cancel or reschedule tasks if necessary.
Example use case: If you have a task related to a specific grave, you might use a unique identifier for that grave as the key to manage the task associated with it.
-
-
Constructor Details
-
GraveManager
Initializes the GraveManager with the specified plugin instance.- Parameters:
plugin
- the Graves plugin instance.
-
-
Method Details
-
startGraveTimer
private void startGraveTimer()Starts the grave timer task that periodically checks and updates graves. -
checkAndUpdateGraves
private void checkAndUpdateGraves()Checks and updates graves, entities, and blocks, removing expired elements and triggering necessary events. -
processGraves
Processes all graves to check their remaining time and protection status.- Parameters:
graveRemoveList
- the list to which graves to be removed will be added.
-
handleGraveTimeout
Handles the timeout or abandonment of a grave by firing the GraveTimeoutEvent and then either dropping its contents (timeout) or moving it into abandoned logic.- Parameters:
grave
- the grave to check.graveRemoveList
- graves to remove get added here.
-
sendPlayerMessage
Utility to send a message to the grave owner if they're online. -
arePlayersInChunk
private boolean arePlayersInChunk(org.bukkit.Chunk chunk) Checks if there are any players in the given chunk.- Parameters:
chunk
- the chunk to check.- Returns:
- true if there are players in the chunk, false otherwise.
-
processChunks
private void processChunks(List<EntityData> entityDataRemoveList, List<BlockData> blockDataRemoveList) Processes all chunks to handle entities and blocks within them.- Parameters:
entityDataRemoveList
- the list to which entity data to be removed will be added.blockDataRemoveList
- the list to which block data to be removed will be added.
-
removeExpiredElements
private void removeExpiredElements(List<Grave> graveRemoveList, List<EntityData> entityDataRemoveList, List<BlockData> blockDataRemoveList) Removes expired graves, entities, and blocks from the system.- Parameters:
graveRemoveList
- the list of graves to be removed.entityDataRemoveList
- the list of entity data to be removed.blockDataRemoveList
- the list of block data to be removed.
-
processEntityData
private void processEntityData(ChunkData chunkData, List<EntityData> entityDataRemoveList, org.bukkit.Location location) Processes the entity data within the given chunk.- Parameters:
chunkData
- the data of the chunk being processed.entityDataRemoveList
- the list to which entity data to be removed will be added.location
- the location representing the chunk coordinates.
-
processHologramData
private void processHologramData(HologramData hologramData, org.bukkit.Location location, List<EntityData> entityDataRemoveList) Processes hologram data within the chunk.- Parameters:
hologramData
- the hologram data to be processed.location
- the location representing the chunk coordinates.entityDataRemoveList
- the list to which hologram data to be removed will be added.
-
processBlockData
Processes the block data within the given chunk.- Parameters:
chunkData
- the data of the chunk being processed.blockDataRemoveList
- the list to which block data to be removed will be added.
-
unload
public void unload()Unloads all open grave inventories for online players. -
toggleGraveProtection
Toggles the protection state of a grave.- Parameters:
grave
- the grave to toggle protection for.
-
abandonGrave
Abandons a grave.- Parameters:
grave
- the grave to abandon.
-
graveParticle
Spawns particle effects around a grave.- Parameters:
location
- the location of the grave.grave
- the grave to spawn particles for.
-
removeOldestGrave
public void removeOldestGrave(org.bukkit.entity.LivingEntity livingEntity) Removes the oldest grave. -
removeGrave
Removes a grave and its associated data.- Parameters:
grave
- the grave to remove.
-
removeEntityData
Removes entity data associated with a grave.- Parameters:
entityData
- the entity data to remove.
-
closeGrave
Closes any open inventories associated with a grave.- Parameters:
grave
- the grave to close inventories for.
-
createGrave
public Grave createGrave(org.bukkit.entity.Entity entity, List<org.bukkit.inventory.ItemStack> itemStackList) Creates a new grave for the specified entity and list of item stacks.- Parameters:
entity
- the entity to create the grave for.itemStackList
- the list of item stacks to be included in the grave.- Returns:
- the created grave.
-
createGrave
public Grave createGrave(org.bukkit.entity.Entity entity, List<org.bukkit.inventory.ItemStack> itemStackList, List<String> permissionList) Creates a new grave for the specified entity, list of item stacks, and permissions.This method supports both players and non-player entities. For players, it ensures Floodgate compatibility by normalizing UUIDs and usernames for Bedrock users.
- Parameters:
entity
- the entity to create the grave for (can be a Player or any Entity).itemStackList
- the list of item stacks to be included in the grave.permissionList
- the list of permissions associated with the grave.- Returns:
- the created grave.
-
restoreMissingGraves
private void restoreMissingGraves()Restores graves that are in cache but missing from the world. -
isGravePlaced
Determines if the grave is placed in the world by checking for any physical block or entity presence at the grave's location. This includes checking for FancyNPCs plugin entities (corpses).- Parameters:
grave
- the grave to check.- Returns:
- true if a block or entity is present at the grave's location, including FancyNPCs.
-
getStorageMode
Retrieves the storage mode for a given string representation.- Parameters:
string
- the string representation of the storage mode.- Returns:
- the corresponding storage mode.
-
placeGrave
Places a grave at a specified location.- Parameters:
location
- the location to place the grave.grave
- the grave to be placed.
-
getGraveInventory
public org.bukkit.inventory.Inventory getGraveInventory(Grave grave, org.bukkit.entity.LivingEntity livingEntity, List<org.bukkit.inventory.ItemStack> graveItemStackList, List<org.bukkit.inventory.ItemStack> removedItemStackList, List<String> permissionList) Retrieves the grave inventory for a specified grave and living entity.- Parameters:
grave
- the grave.livingEntity
- the living entity.graveItemStackList
- the list of item stacks to be included in the grave.removedItemStackList
- the list of item stacks to be removed.permissionList
- the list of permissions associated with the grave.- Returns:
- the created grave inventory.
-
createGraveInventory
public org.bukkit.inventory.Inventory createGraveInventory(org.bukkit.inventory.InventoryHolder inventoryHolder, org.bukkit.Location location, List<org.bukkit.inventory.ItemStack> itemStackList, String title, Grave.StorageMode storageMode) Creates a grave inventory with the specified parameters.- Parameters:
inventoryHolder
- the holder of the inventory.location
- the location of the grave.itemStackList
- the list of item stacks to be included in the inventory.title
- the title of the inventory.storageMode
- the storage mode for the inventory.- Returns:
- the created inventory.
-
getItemStacksSize
public int getItemStacksSize(org.bukkit.inventory.ItemStack[] itemStacks) Gets the size of the item stacks array.- Parameters:
itemStacks
- the array of item stacks.- Returns:
- the size of the item stacks array.
-
filterGraveItemStackList
public List<org.bukkit.inventory.ItemStack> filterGraveItemStackList(List<org.bukkit.inventory.ItemStack> itemStackList, org.bukkit.entity.LivingEntity livingEntity, List<String> permissionList) Filters the grave item stack list based on the living entity and permission list.- Parameters:
itemStackList
- the original list of item stacks.livingEntity
- the living entity.permissionList
- the list of permissions associated with the grave.- Returns:
- the filtered list of item stacks.
-
filterGraveItemStackList
public List<org.bukkit.inventory.ItemStack> filterGraveItemStackList(List<org.bukkit.inventory.ItemStack> itemStackList, List<org.bukkit.inventory.ItemStack> removedItemStackList, org.bukkit.entity.LivingEntity livingEntity, List<String> permissionList) Filters the grave item stack list based on the living entity, removed item stacks, and permission list.- Parameters:
itemStackList
- the original list of item stacks.removedItemStackList
- the list of item stacks to be removed.livingEntity
- the living entity.permissionList
- the list of permissions associated with the grave.- Returns:
- the filtered list of item stacks.
-
breakGrave
Breaks a grave at its death location.- Parameters:
grave
- the grave to be broken.
-
breakGrave
Breaks a grave at the specified location.- Parameters:
location
- the location to break the grave.grave
- the grave to be broken.
-
dropGraveItems
Drops the items from a grave at the specified location.- Parameters:
location
- the location to drop the items.grave
- the grave containing the items.
-
giveGraveExperience
Gives the experience from a grave to a player.- Parameters:
player
- the player to receive the experience.grave
- the grave containing the experience.
-
dropGraveExperience
Drops the experience from a grave at the specified location.- Parameters:
location
- the location to drop the experience.grave
- the grave containing the experience.
-
getGraveList
Retrieves a list of graves associated with a player.- Parameters:
player
- the player to retrieve the graves for.- Returns:
- the list of graves.
-
getGraveList
Retrieves a list of graves associated with an offline player.- Parameters:
player
- the offline player to retrieve the graves for.- Returns:
- the list of graves.
-
getGraveList
Retrieves a list of graves associated with an entity.- Parameters:
entity
- the entity to retrieve the graves for.- Returns:
- the list of graves.
-
getGraveList
Retrieves a list of graves associated with a UUID.- Parameters:
uuid
- the UUID to retrieve the graves for.- Returns:
- the list of graves.
-
getGraveCount
public int getGraveCount(org.bukkit.entity.Entity entity) Retrieves the number of graves associated with an entity.- Parameters:
entity
- the entity to retrieve the grave count for.- Returns:
- the number of graves.
-
openGrave
public boolean openGrave(org.bukkit.entity.Entity entity, org.bukkit.Location location, Grave grave) Opens a grave for a player.- Parameters:
entity
- the entity attempting to open the grave.location
- the location of the grave.grave
- the grave to be opened.- Returns:
- true if the grave was opened successfully, false otherwise.
-
openGrave
public boolean openGrave(org.bukkit.entity.Entity entity, org.bukkit.Location location, Grave grave, boolean preview) Opens a grave for a player.- Parameters:
entity
- the entity attempting to open the grave.location
- the location of the grave.grave
- the grave to be opened.- Returns:
- true if the grave was opened successfully, false otherwise.
-
cleanupCompasses
Cleans up compasses from a player's inventory that are associated with a grave.- Parameters:
player
- the player to clean up the compasses for.grave
- the grave associated with the compasses.
-
getGraveLocationList
public List<org.bukkit.Location> getGraveLocationList(org.bukkit.Location baseLocation, Grave grave) Retrieves a list of locations associated with a grave.- Parameters:
baseLocation
- the base location.grave
- the grave to retrieve the locations for.- Returns:
- the list of locations.
-
getGraveLocation
Retrieves the nearest grave location to a specified location.- Parameters:
location
- the base location.grave
- the grave to retrieve the location for.- Returns:
- the nearest grave location.
-
autoLootGrave
public void autoLootGrave(org.bukkit.entity.Entity entity, org.bukkit.Location location, Grave grave) Automatically loots a grave for a player.- Parameters:
entity
- the entity looting the grave.location
- the location of the grave.grave
- the grave to be looted.
-
isNearGrave
public boolean isNearGrave(org.bukkit.Location location) Checks if the given location is within configured blocks of any grave.- Parameters:
location
- The location to check.- Returns:
- True if the location is within configured blocks of any grave, false otherwise.
-
isNearGrave
public boolean isNearGrave(org.bukkit.Location location, org.bukkit.entity.Player player, org.bukkit.block.Block block) Checks if the given location is within configured blocks of any grave.- Parameters:
location
- The location to check.player
- Optional player to consider for additional logic.block
- Optional block to consider for additional logic.- Returns:
- True if the location is within configured blocks of any grave, false otherwise.
-
isNearGrave
public boolean isNearGrave(org.bukkit.Location location, org.bukkit.entity.Player player) Overload for player-specific checks. -
isNearGrave
public boolean isNearGrave(org.bukkit.Location location, org.bukkit.block.Block block) Overload for block-specific checks. -
getDamageReason
public String getDamageReason(org.bukkit.event.entity.EntityDamageEvent.DamageCause damageCause, Grave grave) Retrieves the damage reason for a specified damage cause and grave.- Parameters:
damageCause
- the cause of the damage.grave
- the grave associated with the damage.- Returns:
- the damage reason.
-
playEffect
Plays an effect at a specified location.- Parameters:
string
- the effect string.location
- the location to play the effect.
-
playEffect
Plays an effect at a specified location for a grave.- Parameters:
string
- the effect string.location
- the location to play the effect.grave
- the grave associated with the effect.
-
playEffect
Plays an effect at a specified location with additional data for a grave.- Parameters:
string
- the effect string.location
- the location to play the effect.data
- additional data for the effect.grave
- the grave associated with the effect.
-
shouldIgnoreItemStack
public boolean shouldIgnoreItemStack(org.bukkit.inventory.ItemStack itemStack, org.bukkit.entity.Entity entity, Grave grave) Checks if an item stack should be ignored based on the entity and grave.- Parameters:
itemStack
- the item stack to check.entity
- the entity.grave
- the grave.- Returns:
- true if the item stack should be ignored, false otherwise.
-
shouldIgnoreItemStack
public boolean shouldIgnoreItemStack(org.bukkit.inventory.ItemStack itemStack, org.bukkit.entity.Entity entity, List<String> permissionList) Checks if an item stack should be ignored based on the entity and permissions.- Parameters:
itemStack
- the item stack to check.entity
- the entity.permissionList
- the list of permissions.- Returns:
- true if the item stack should be ignored, false otherwise.
-
hasGraveAtLocation
public boolean hasGraveAtLocation(org.bukkit.Location location) Checks if there is a grave at the specified location.- Parameters:
location
- The location to check.- Returns:
- True if there is a grave at the location, false otherwise.
-
getAllGraves
Gets a list of all graves.- Returns:
- A list of all graves.
-
shouldIgnoreBlock
@Deprecated public boolean shouldIgnoreBlock(org.bukkit.block.Block block, org.bukkit.entity.Entity entity, Grave grave) Deprecated.This method is deprecated. UseshouldIgnoreBlock(Block, Entity, List<String>)
instead. -
isGraveAbandoned
Checks if a block should be ignored based on the entity and permissions.- Parameters:
grave
- checks to see if the following grave is abandoned.- Returns:
- true if grave is abandoned, false otherwise.
-
shouldIgnoreBlock
public boolean shouldIgnoreBlock(org.bukkit.block.Block block, org.bukkit.entity.Entity entity, List<String> permissionList) Checks if a block should be ignored based on the entity and permissions.- Parameters:
block
- the block to check.entity
- the entity.permissionList
- the list of permissions.- Returns:
- true if the block should be ignored, false otherwise.
-