Class EntityDeathListener

java.lang.Object
com.ranull.graves.listener.EntityDeathListener
All Implemented Interfaces:
org.bukkit.event.Listener

public class EntityDeathListener extends Object implements org.bukkit.event.Listener
Listener for handling entity death events and creating graves.
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    private final Graves
     
  • Constructor Summary

    Constructors
    Constructor
    Description
    Constructs an EntityDeathListener with the specified Graves plugin.
  • Method Summary

    Modifier and Type
    Method
    Description
    private void
    createGrave(org.bukkit.event.entity.EntityDeathEvent event, org.bukkit.entity.LivingEntity livingEntity, String entityName, List<String> permissionList, List<org.bukkit.inventory.ItemStack> removedItemStackList, List<org.bukkit.inventory.ItemStack> graveItemStackList, org.bukkit.Location location)
    Creates a grave for the specified entity.
    private org.bukkit.Location
    findGraveLocation(Grave grave, org.bukkit.entity.LivingEntity livingEntity, org.bukkit.Location location)
     
    private List<org.bukkit.inventory.ItemStack>
    getGraveItemStackList(org.bukkit.event.entity.EntityDeathEvent event, org.bukkit.entity.LivingEntity livingEntity, List<String> permissionList)
    Retrieves the list of item stacks for the grave.
    private int
    getMaxGravesPermission(org.bukkit.entity.Player player)
    Retrieves the maximum number of graves a player is allowed to have based on their permissions.
    private List<org.bukkit.inventory.ItemStack>
    getRemovedItemStacks(org.bukkit.entity.LivingEntity livingEntity)
    Retrieves the list of removed item stacks for the specified entity.
    private void
    handleFailedGravePlacement(org.bukkit.event.entity.EntityDeathEvent event, Grave grave, org.bukkit.Location location, org.bukkit.entity.LivingEntity livingEntity)
    Handles failed grave placement.
    private boolean
    handlePlayerDeath(org.bukkit.entity.Player player, String entityName)
    Handles player death and checks if a grave should be created.
    private boolean
    hasGravesXMetadata(org.bukkit.entity.Zombie zombie)
    Checks if the given entity has the GravesX metadata.
    private boolean
    hasValidToken(org.bukkit.entity.LivingEntity livingEntity, List<String> permissionList, String entityName, List<org.bukkit.inventory.ItemStack> drops)
    Checks if the entity has a valid grave token.
    private boolean
    isConfiguredZombieType(org.bukkit.entity.Zombie zombie)
    Checks if the zombie is of the type configured in config.yml.
    private boolean
    isEnabledGrave(org.bukkit.entity.LivingEntity livingEntity, List<String> permissionList, String entityName)
    Checks if graves are enabled for the specified entity.
    private boolean
    isInvalidCreatureSpawn(org.bukkit.entity.LivingEntity livingEntity, List<String> permissionList, String entityName)
    Checks if the creature spawn reason is valid.
    private boolean
    isInvalidGraveZombie(org.bukkit.event.entity.EntityDeathEvent event, org.bukkit.entity.LivingEntity livingEntity, String entityName)
    Checks if the entity is an invalid grave zombie.
    private boolean
    isInvalidMohistDeath(org.bukkit.event.entity.EntityDeathEvent event)
    Checks if the entity death event is an invalid Mohist death.
    private boolean
    isKeepInventory(org.bukkit.event.entity.PlayerDeathEvent event, String entityName)
    Checks if the player has keep inventory enabled.
    private boolean
    isValidDamageCause(org.bukkit.entity.LivingEntity livingEntity, List<String> permissionList, String entityName)
    Checks if the damage cause is valid for creating a grave.
    private boolean
    isValidWorld(List<String> worldList, org.bukkit.entity.LivingEntity livingEntity, String entityName)
    Checks if the entity is in a valid world.
    private void
    notifyGraveCreation(org.bukkit.event.entity.EntityDeathEvent event, Grave grave, Map<org.bukkit.Location,BlockData.BlockType> locationMap, org.bukkit.entity.LivingEntity livingEntity, List<String> permissionList)
    Notifies the creation of the grave and places the grave blocks.
    void
    onEntityDeath(org.bukkit.event.entity.EntityDeathEvent event)
    Handles the EntityDeathEvent to create a grave based on various conditions.
    private void
    performPlayerEconomyWithdrawal(Grave grave, org.bukkit.entity.LivingEntity livingEntity)
    Performs an economy withdrawal from a player's balance upon death, based on configuration and permissions.
    private void
    placeGrave(org.bukkit.event.entity.EntityDeathEvent event, Grave grave, GraveCreateEvent graveCreateEvent, List<org.bukkit.inventory.ItemStack> graveItemStackList, List<org.bukkit.inventory.ItemStack> removedItemStackList, org.bukkit.Location location, org.bukkit.entity.LivingEntity livingEntity, List<String> permissionList)
    Places the grave at the specified location.
    private void
    placeGraveBlocks(org.bukkit.event.entity.EntityDeathEvent event, Grave grave, Map<org.bukkit.Location,BlockData.BlockType> locationMap, org.bukkit.entity.LivingEntity livingEntity)
    Places the grave blocks at the specified locations.
    private void
    removePlayerSkullFromDrops(org.bukkit.entity.LivingEntity entity, org.bukkit.event.entity.EntityDeathEvent event)
    Removes player skull from the drops of the entity if it is wearing one.
    private void
    setGraveExperience(Grave grave, org.bukkit.event.entity.EntityDeathEvent event, org.bukkit.entity.LivingEntity livingEntity)
    Sets the experience for the grave.
    private void
    setupGrave(Grave grave, org.bukkit.entity.LivingEntity livingEntity, String entityName, List<String> permissionList)
    Sets up the basic properties of the grave.
    private void
    setupGraveKiller(Grave grave, org.bukkit.entity.LivingEntity livingEntity)
    Sets up the killer details for the grave.
    private void
    setupGraveProtection(org.bukkit.entity.LivingEntity livingEntity, Grave grave)
    Sets up the protection details for the grave.
    private void
    setupObituary(Grave grave, List<org.bukkit.inventory.ItemStack> graveItemStackList, org.bukkit.entity.LivingEntity livingEntity, org.bukkit.Location location)
    Sets up the obituary item for the grave.
    private void
    setupSkull(Grave grave, List<org.bukkit.inventory.ItemStack> graveItemStackList, org.bukkit.entity.LivingEntity livingEntity, org.bukkit.Location location)
    Sets up the skull item for the grave.
    private boolean
    shouldAddObituaryItem(double percentage)
    Determines whether to add the obituary item based on the percentage.

    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
  • Constructor Details

    • EntityDeathListener

      public EntityDeathListener(Graves plugin)
      Constructs an EntityDeathListener with the specified Graves plugin.
      Parameters:
      plugin - The Graves plugin instance.
  • Method Details

    • onEntityDeath

      public void onEntityDeath(org.bukkit.event.entity.EntityDeathEvent event) throws InvocationTargetException
      Handles the EntityDeathEvent to create a grave based on various conditions.
      Parameters:
      event - The EntityDeathEvent to handle.
      Throws:
      InvocationTargetException
    • getMaxGravesPermission

      private int getMaxGravesPermission(org.bukkit.entity.Player player)
      Retrieves the maximum number of graves a player is allowed to have based on their permissions.

      The method checks for permissions related to grave limits and returns the highest limit found. If the player has the "grave.max.limit.unlimited" permission, the method will return Integer.MAX_VALUE indicating that the player has no limit on the number of graves. If no specific permissions are found, the method returns 0 by default, which should be interpreted as no specific limit set by permissions.

      Parameters:
      player - The player whose grave limit is being checked.
      Returns:
      The maximum number of graves the player is allowed to have. Returns Integer.MAX_VALUE for unlimited graves, or 0 if no specific limit is set by permissions.
    • isConfiguredZombieType

      private boolean isConfiguredZombieType(org.bukkit.entity.Zombie zombie)
      Checks if the zombie is of the type configured in config.yml.
      Parameters:
      zombie - the zombie entity to check
      Returns:
      true if the zombie is of the configured type, false otherwise
    • removePlayerSkullFromDrops

      private void removePlayerSkullFromDrops(org.bukkit.entity.LivingEntity entity, org.bukkit.event.entity.EntityDeathEvent event)
      Removes player skull from the drops of the entity if it is wearing one.
      Parameters:
      entity - the entity whose drops are to be modified
      event - the EntityDeathEvent containing the drops
    • hasGravesXMetadata

      private boolean hasGravesXMetadata(org.bukkit.entity.Zombie zombie)
      Checks if the given entity has the GravesX metadata.
      Parameters:
      zombie - the zombie entity to check
      Returns:
      true if the entity has the GravesX metadata, false otherwise
    • getRemovedItemStacks

      private List<org.bukkit.inventory.ItemStack> getRemovedItemStacks(org.bukkit.entity.LivingEntity livingEntity)
      Retrieves the list of removed item stacks for the specified entity.
      Parameters:
      livingEntity - The entity whose removed item stacks are to be retrieved.
      Returns:
      The list of removed item stacks.
    • isInvalidMohistDeath

      private boolean isInvalidMohistDeath(org.bukkit.event.entity.EntityDeathEvent event)
      Checks if the entity death event is an invalid Mohist death.
      Parameters:
      event - The entity death event to check.
      Returns:
      True if the event is an invalid Mohist death, false otherwise.
    • isInvalidGraveZombie

      private boolean isInvalidGraveZombie(org.bukkit.event.entity.EntityDeathEvent event, org.bukkit.entity.LivingEntity livingEntity, String entityName)
      Checks if the entity is an invalid grave zombie.
      Parameters:
      event - The entity death event.
      livingEntity - The entity to check.
      entityName - The name of the entity.
      Returns:
      True if the entity is an invalid grave zombie, false otherwise.
    • handlePlayerDeath

      private boolean handlePlayerDeath(org.bukkit.entity.Player player, String entityName) throws InvocationTargetException
      Handles player death and checks if a grave should be created.
      Parameters:
      player - The player who died.
      entityName - The name of the player.
      Returns:
      True if a grave should not be created, false otherwise.
      Throws:
      InvocationTargetException
    • isEnabledGrave

      private boolean isEnabledGrave(org.bukkit.entity.LivingEntity livingEntity, List<String> permissionList, String entityName)
      Checks if graves are enabled for the specified entity.
      Parameters:
      livingEntity - The entity to check.
      permissionList - The list of permissions.
      entityName - The name of the entity.
      Returns:
      True if graves are enabled, false otherwise.
    • isKeepInventory

      private boolean isKeepInventory(org.bukkit.event.entity.PlayerDeathEvent event, String entityName)
      Checks if the player has keep inventory enabled.
      Parameters:
      event - The player death event.
      entityName - The name of the player.
      Returns:
      True if the player has keep inventory enabled, false otherwise.
    • isInvalidCreatureSpawn

      private boolean isInvalidCreatureSpawn(org.bukkit.entity.LivingEntity livingEntity, List<String> permissionList, String entityName)
      Checks if the creature spawn reason is valid.
      Parameters:
      livingEntity - The creature entity.
      permissionList - The list of permissions.
      entityName - The name of the entity.
      Returns:
      True if the spawn reason is invalid, false otherwise.
    • isValidWorld

      private boolean isValidWorld(List<String> worldList, org.bukkit.entity.LivingEntity livingEntity, String entityName)
      Checks if the entity is in a valid world.
      Parameters:
      worldList - The list of valid worlds.
      livingEntity - The entity to check.
      entityName - The name of the entity.
      Returns:
      True if the entity is in a valid world, false otherwise.
    • isValidDamageCause

      private boolean isValidDamageCause(org.bukkit.entity.LivingEntity livingEntity, List<String> permissionList, String entityName)
      Checks if the damage cause is valid for creating a grave.
      Parameters:
      livingEntity - The entity that was damaged.
      permissionList - The list of permissions.
      entityName - The name of the entity.
      Returns:
      True if the damage cause is valid, false otherwise.
    • hasValidToken

      private boolean hasValidToken(org.bukkit.entity.LivingEntity livingEntity, List<String> permissionList, String entityName, List<org.bukkit.inventory.ItemStack> drops)
      Checks if the entity has a valid grave token.
      Parameters:
      livingEntity - The entity to check.
      permissionList - The list of permissions.
      entityName - The name of the entity.
      drops - The list of item drops.
      Returns:
      True if the entity has a valid grave token, false otherwise.
    • getGraveItemStackList

      private List<org.bukkit.inventory.ItemStack> getGraveItemStackList(org.bukkit.event.entity.EntityDeathEvent event, org.bukkit.entity.LivingEntity livingEntity, List<String> permissionList)
      Retrieves the list of item stacks for the grave.
      Parameters:
      event - The entity death event.
      livingEntity - The entity that died.
      permissionList - The list of permissions.
      Returns:
      The list of item stacks for the grave.
    • createGrave

      private void createGrave(org.bukkit.event.entity.EntityDeathEvent event, org.bukkit.entity.LivingEntity livingEntity, String entityName, List<String> permissionList, List<org.bukkit.inventory.ItemStack> removedItemStackList, List<org.bukkit.inventory.ItemStack> graveItemStackList, org.bukkit.Location location)
      Creates a grave for the specified entity.
      Parameters:
      event - The entity death event.
      livingEntity - The entity that died.
      entityName - The name of the entity.
      permissionList - The list of permissions.
      removedItemStackList - The list of removed item stacks.
      graveItemStackList - The list of item stacks for the grave.
      location - The location of the grave.
    • setupGrave

      private void setupGrave(Grave grave, org.bukkit.entity.LivingEntity livingEntity, String entityName, List<String> permissionList)
      Sets up the basic properties of the grave.
      Parameters:
      grave - The grave to set up.
      livingEntity - The entity that died.
      entityName - The name of the entity.
      permissionList - The list of permissions.
    • setGraveExperience

      private void setGraveExperience(Grave grave, org.bukkit.event.entity.EntityDeathEvent event, org.bukkit.entity.LivingEntity livingEntity)
      Sets the experience for the grave.
      Parameters:
      grave - The grave to set the experience for.
      event - The entity death event.
      livingEntity - The entity that died.
    • setupGraveKiller

      private void setupGraveKiller(Grave grave, org.bukkit.entity.LivingEntity livingEntity)
      Sets up the killer details for the grave.
      Parameters:
      grave - The grave to set up.
      livingEntity - The entity that died.
    • setupGraveProtection

      private void setupGraveProtection(org.bukkit.entity.LivingEntity livingEntity, Grave grave)
      Sets up the protection details for the grave.
      Parameters:
      grave - The grave to set up.
    • placeGrave

      private void placeGrave(org.bukkit.event.entity.EntityDeathEvent event, Grave grave, GraveCreateEvent graveCreateEvent, List<org.bukkit.inventory.ItemStack> graveItemStackList, List<org.bukkit.inventory.ItemStack> removedItemStackList, org.bukkit.Location location, org.bukkit.entity.LivingEntity livingEntity, List<String> permissionList)
      Places the grave at the specified location.
      Parameters:
      event - The entity death event.
      grave - The grave to place.
      graveCreateEvent - The grave create event.
      graveItemStackList - The list of item stacks for the grave.
      removedItemStackList - The list of removed item stacks.
      location - The location to place the grave.
      livingEntity - The entity that died.
      permissionList - The list of permissions.
    • performPlayerEconomyWithdrawal

      private void performPlayerEconomyWithdrawal(Grave grave, org.bukkit.entity.LivingEntity livingEntity)
      Performs an economy withdrawal from a player's balance upon death, based on configuration and permissions.

      This method checks if the economy system is enabled and properly integrated via Vault. It then attempts to deduct an amount from the player's balance depending on the configuration and the first matching permission under graves.deduct.<name> from the configured cost list.

      The cost can either be a fixed value or a percentage of the player's balance, controlled via the death.economy.use-as-percentage config option.

      Parameters:
      grave - The grave associated with the player's death.
      livingEntity - The entity that died (must be a Player to apply economy deductions).
    • setupObituary

      private void setupObituary(Grave grave, List<org.bukkit.inventory.ItemStack> graveItemStackList, org.bukkit.entity.LivingEntity livingEntity, org.bukkit.Location location)
      Sets up the obituary item for the grave.
      Parameters:
      grave - The grave to set up.
      graveItemStackList - The list of item stacks for the grave.
    • shouldAddObituaryItem

      private boolean shouldAddObituaryItem(double percentage)
      Determines whether to add the obituary item based on the percentage.
      Parameters:
      percentage - The percentage value (between 0 and 1).
      Returns:
      true if the obituary item should be added; false otherwise.
    • setupSkull

      private void setupSkull(Grave grave, List<org.bukkit.inventory.ItemStack> graveItemStackList, org.bukkit.entity.LivingEntity livingEntity, org.bukkit.Location location)
      Sets up the skull item for the grave.
      Parameters:
      grave - The grave to set up.
      graveItemStackList - The list of item stacks for the grave.
    • notifyGraveCreation

      private void notifyGraveCreation(org.bukkit.event.entity.EntityDeathEvent event, Grave grave, Map<org.bukkit.Location,BlockData.BlockType> locationMap, org.bukkit.entity.LivingEntity livingEntity, List<String> permissionList)
      Notifies the creation of the grave and places the grave blocks.
      Parameters:
      event - The entity death event.
      grave - The grave that was created.
      locationMap - The map of locations for the grave.
      livingEntity - The entity that died.
      permissionList - The list of permissions.
    • placeGraveBlocks

      private void placeGraveBlocks(org.bukkit.event.entity.EntityDeathEvent event, Grave grave, Map<org.bukkit.Location,BlockData.BlockType> locationMap, org.bukkit.entity.LivingEntity livingEntity)
      Places the grave blocks at the specified locations.
      Parameters:
      event - The entity death event.
      grave - The grave to place.
      locationMap - The map of locations for the grave.
      livingEntity - The entity that died.
    • handleFailedGravePlacement

      private void handleFailedGravePlacement(org.bukkit.event.entity.EntityDeathEvent event, Grave grave, org.bukkit.Location location, org.bukkit.entity.LivingEntity livingEntity)
      Handles failed grave placement.
      Parameters:
      event - The entity death event.
      grave - The grave that failed to be placed.
      location - The location where the grave was to be placed.
      livingEntity - The entity that died.
    • findGraveLocation

      private org.bukkit.Location findGraveLocation(Grave grave, org.bukkit.entity.LivingEntity livingEntity, org.bukkit.Location location)