Class GraveManager

java.lang.Object
com.ranull.graves.manager.GraveManager

public final class GraveManager extends Object
Manages the operations and lifecycle of graves within the Graves plugin.
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    private final Graves
    The main plugin instance associated with Graves.
  • Constructor Summary

    Constructors
    Constructor
    Description
    GraveManager(@NotNull Graves plugin)
    Initializes the GraveManager with the specified plugin instance.
  • Method Summary

    Modifier and Type
    Method
    Description
    void
    Abandons a grave.
    void
    autoLootGrave(org.bukkit.entity.Entity entity, org.bukkit.Location location, Grave grave)
    Automatically loots a grave for a player.
    void
    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
    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.
    private Set<String>
    extractNamespacedKeys(org.bukkit.inventory.ItemStack itemStack)
    Collects namespaced keys present on this item.
    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.
    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.
    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.
    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
    Checks if a block should be ignored based on the entity and permissions.
    boolean
    Determines if the grave is placed in the world by checking for any physical block or entity presence at the grave's location.
    private boolean
    isHeadBlock(org.bukkit.block.Block block)
     
    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.
    private boolean
    namespacedKeys(org.bukkit.inventory.ItemStack itemStack, List<String> keysToMatch)
    Exact match against any namespaced key on the item.
    private boolean
    namespacedKeysContains(org.bukkit.inventory.ItemStack itemStack, List<String> patterns)
    Substring match against any namespaced key on the item.
    boolean
    openGrave(org.bukkit.entity.Entity entity, org.bukkit.Location location, Grave grave)
    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
    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
    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
    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
    Toggles the protection state of a grave.
    void
    Unloads all open grave inventories for online players.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Field Details

    • plugin

      private final Graves 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.

  • Constructor Details

    • GraveManager

      public GraveManager(@NotNull @NotNull Graves plugin)
      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

      private void processGraves(List<Grave> graveRemoveList)
      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

      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.
      Parameters:
      grave - the grave to check.
      graveRemoveList - graves to remove get added here.
    • sendPlayerMessage

      private void sendPlayerMessage(Grave grave, String messageKey, org.bukkit.Location location)
      Utility to send a message to the grave owner if they're online.
      Parameters:
      grave - the grave whose owner should be notified
      messageKey - the message key to resolve from messages configuration
      location - the relevant location to include with the message
    • 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

      private void processBlockData(ChunkData chunkData, List<BlockData> blockDataRemoveList)
      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

      public void toggleGraveProtection(Grave grave)
      Toggles the protection state of a grave.
      Parameters:
      grave - the grave to toggle protection for.
    • abandonGrave

      public void abandonGrave(Grave grave)
      Abandons a grave.
      Parameters:
      grave - the grave to abandon.
    • graveParticle

      public void graveParticle(org.bukkit.Location location, Grave grave)
      Spawns particle effects around a grave.

      Folia-compatible: the actual particle spawning is scheduled on the correct region thread via the GravesX scheduler using the provided location.

      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.
      Parameters:
      livingEntity - the entity whose oldest grave should be removed
    • removeGrave

      public void removeGrave(Grave grave)
      Removes a grave and its associated data.
      Parameters:
      grave - the grave to remove.
    • removeEntityData

      public void removeEntityData(EntityData entityData)
      Removes entity data associated with a grave.
      Parameters:
      entityData - the entity data to remove.
    • closeGrave

      public void closeGrave(Grave grave)
      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.
      Parameters:
      entity - the entity to create the grave for.
      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

      public 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. This includes checking for plugin-provided furniture/blocks and NPC corpses.
      Parameters:
      grave - the grave to check.
      Returns:
      true if a block or entity is present at the grave's location (including integrations).
    • isHeadBlock

      private boolean isHeadBlock(org.bukkit.block.Block block)
    • getStorageMode

      public Grave.StorageMode getStorageMode(String string)
      Retrieves the storage mode for a given string representation.
      Parameters:
      string - the string representation of the storage mode.
      Returns:
      the corresponding storage mode.
    • placeGrave

      public void placeGrave(org.bukkit.Location location, Grave grave)
      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 number of non-null item stacks in the array.
    • 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

      public void breakGrave(Grave grave)
      Breaks a grave at its death location.
      Parameters:
      grave - the grave to be broken.
    • breakGrave

      public void breakGrave(org.bukkit.Location location, Grave grave)
      Breaks a grave at the specified location.
      Parameters:
      location - the location to break the grave.
      grave - the grave to be broken.
    • dropGraveItems

      public void dropGraveItems(org.bukkit.Location location, Grave grave)
      Drops the items from a grave at the specified location.

      Folia-compatible: item drops are executed on the correct region thread using location as the anchor.

      Parameters:
      location - the location to drop the items.
      grave - the grave containing the items.
    • giveGraveExperience

      public void giveGraveExperience(org.bukkit.entity.Player player, Grave grave)
      Gives the experience from a grave to a player.
      Parameters:
      player - the player to receive the experience.
      grave - the grave containing the experience.
    • dropGraveExperience

      public void dropGraveExperience(org.bukkit.Location location, Grave grave)
      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

      public List<Grave> getGraveList(org.bukkit.entity.Player player)
      Retrieves a list of graves associated with a player.
      Parameters:
      player - the player to retrieve the graves for.
      Returns:
      the list of graves.
    • getGraveList

      public List<Grave> getGraveList(org.bukkit.OfflinePlayer player)
      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

      public List<Grave> getGraveList(org.bukkit.entity.Entity entity)
      Retrieves a list of graves associated with an entity.
      Parameters:
      entity - the entity to retrieve the graves for.
      Returns:
      the list of graves.
    • getGraveList

      public List<Grave> getGraveList(UUID uuid)
      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.

      Folia-compatible: world/player interactions (auto-loot, opening inventories, running commands, playing sounds) are executed on the correct region thread using the provided location as the anchor. The method returns true once the operation has been scheduled (if permitted), not necessarily after it completes.

      Parameters:
      entity - the entity attempting to open the grave.
      location - the location of the grave.
      grave - the grave to be opened.
      preview - whether to open the grave in preview mode (when allowed by config).
      Returns:
      true if the open/auto-loot operation was scheduled, false otherwise.
    • cleanupCompasses

      public void cleanupCompasses(org.bukkit.entity.Player player, Grave grave)
      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 ordered by proximity in the same world, followed by other worlds.
    • getGraveLocation

      public org.bukkit.Location getGraveLocation(org.bukkit.Location location, Grave grave)
      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, or null if none found.
    • 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)
      Overload for player-specific checks.
    • isNearGrave

      public boolean isNearGrave(org.bukkit.Location location, org.bukkit.block.Block block)
      Overload for block-specific checks.
    • 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 the configured protection radius of any grave; false otherwise.
    • 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

      public void playEffect(String string, org.bukkit.Location location)
      Plays an effect at a specified location.
      Parameters:
      string - the effect string.
      location - the location to play the effect.
    • playEffect

      public void playEffect(String string, org.bukkit.Location location, Grave grave)
      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

      public 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.

      Folia-compatible: effect playback is scheduled on the correct region thread using location as the anchor.

      Parameters:
      string - the effect string (config key or enum name).
      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, 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.
    • getAllGraves

      public List<Grave> getAllGraves()
      Gets a list of all graves.
      Returns:
      a snapshot list of all graves currently known to the cache (never null).
    • isGraveAbandoned

      public boolean isGraveAbandoned(Grave grave)
      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.
    • namespacedKeys

      private boolean namespacedKeys(org.bukkit.inventory.ItemStack itemStack, List<String> keysToMatch)
      Exact match against any namespaced key on the item. Accepts "namespace:key" or just "key".
    • namespacedKeysContains

      private boolean namespacedKeysContains(org.bukkit.inventory.ItemStack itemStack, List<String> patterns)
      Substring match against any namespaced key on the item. Accepts partials like "silk" or "minecraft:".
    • extractNamespacedKeys

      private Set<String> extractNamespacedKeys(org.bukkit.inventory.ItemStack itemStack)
      Collects namespaced keys present on this item. Includes enchantment keys (applied and stored) and PDC keys. Keys are added in both "namespace:key" and "key" forms, lowercased.