Class LifestealerPrePlayerDeathEvent

java.lang.Object
org.bukkit.event.Event
dev.chicoferreira.lifestealer.events.LifestealerPrePlayerDeathEvent
All Implemented Interfaces:
org.bukkit.event.Cancellable

public class LifestealerPrePlayerDeathEvent extends org.bukkit.event.Event implements org.bukkit.event.Cancellable
Called when a player dies, before the hearts have been removed from the player.

Thread-safety (WARNING): This event is called with no active locks on the user.

  • Nested Class Summary

    Nested classes/interfaces inherited from class org.bukkit.event.Event

    org.bukkit.event.Event.Result
  • Constructor Summary

    Constructors
    Constructor
    Description
    LifestealerPrePlayerDeathEvent(@NotNull org.bukkit.event.entity.PlayerDeathEvent deathEvent, @NotNull org.bukkit.entity.Player player, @NotNull LifestealerUser user, @NotNull org.bukkit.inventory.ItemStack itemStackToDrop, int heartsToRemove)
    Constructs a new LifestealerPrePlayerDeathEvent.
  • Method Summary

    Modifier and Type
    Method
    Description
    @NotNull org.bukkit.event.entity.PlayerDeathEvent
    Gets the death event that originated this event.
    static org.bukkit.event.HandlerList
    Gets the handler list.
    @NotNull org.bukkit.event.HandlerList
    Gets the handler list.
    int
    Gets the amount of hearts to remove from the player when they die.
    @Nullable org.bukkit.inventory.ItemStack
    Returns the ItemStack to drop when the player dies.
    @NotNull org.bukkit.entity.Player
    Gets the player that died.
    Gets the user related to the player.
    boolean
    Returns if the event had been cancelled.
    void
    setCancelled(boolean cancel)
    Sets if the event should be cancelled.
    void
    setHeartsToRemove(int heartsToRemove)
    Sets the amount of hearts to remove from the player when they die.
    void
    setItemStackToDrop(@Nullable org.bukkit.inventory.ItemStack itemStackToDrop)
    Sets the ItemStack to drop when the player dies.

    Methods inherited from class org.bukkit.event.Event

    callEvent, getEventName, isAsynchronous

    Methods inherited from class java.lang.Object

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

    • LifestealerPrePlayerDeathEvent

      public LifestealerPrePlayerDeathEvent(@NotNull @NotNull org.bukkit.event.entity.PlayerDeathEvent deathEvent, @NotNull @NotNull org.bukkit.entity.Player player, @NotNull @NotNull LifestealerUser user, @NotNull @NotNull org.bukkit.inventory.ItemStack itemStackToDrop, int heartsToRemove)
      Constructs a new LifestealerPrePlayerDeathEvent.
      Parameters:
      deathEvent - the death event that originated this event
      player - the player that died
      user - the user related to the player
      itemStackToDrop - the heart item to drop when the player dies
      heartsToRemove - the amount of hearts to remove from the player
  • Method Details

    • getDeathEvent

      @NotNull public @NotNull org.bukkit.event.entity.PlayerDeathEvent getDeathEvent()
      Gets the death event that originated this event. Changes to this event are not recommended. Please make sure to be sure of what you are doing.
      Returns:
      the death event that originated this event
    • getPlayer

      @NotNull public @NotNull org.bukkit.entity.Player getPlayer()
      Gets the player that died.
      Returns:
      the player that died
    • getUser

      @NotNull public @NotNull LifestealerUser getUser()
      Gets the user related to the player.
      Returns:
      the user related to the player
    • getItemStackToDrop

      @Nullable public @Nullable org.bukkit.inventory.ItemStack getItemStackToDrop()
      Returns the ItemStack to drop when the player dies. Initially the heart item is valid for consumption and contains the amount of hearts that getHeartsToRemove() returns.

      This is a reference to the ItemStack that will be dropped, so you can modify it directly to change it.

      If you wish to replace the ItemStack for other LifestealerHeartItem use LifestealerHeartItemManager.getItem(String), LifestealerHeartItemManager.generateItem(LifestealerHeartItem) and setItemStackToDrop(ItemStack).

      This can return null if a plugin has set the item to drop to null.

      Returns:
      the heart ItemStack to drop when the player dies
    • setItemStackToDrop

      public void setItemStackToDrop(@Nullable @Nullable org.bukkit.inventory.ItemStack itemStackToDrop)
      Sets the ItemStack to drop when the player dies.

      When setting a new ItemStack, you may need to set the amount of hearts to be removed from the player again if you wish to keep the amount of hearts consistent and the new ItemStack contains a different amount of hearts.

      If you wish to replace the ItemStack for other LifestealerHeartItem use LifestealerHeartItemManager.getItem(String), LifestealerHeartItemManager.generateItem(LifestealerHeartItem) to generate a new ItemStack and set it here.

      Setting this to null will make the player to not drop the heart item when they die.

      Parameters:
      itemStackToDrop - the heart ItemStack to drop when the player dies
    • getHeartsToRemove

      public int getHeartsToRemove()
      Gets the amount of hearts to remove from the player when they die. Unless changed, this is the amount of hearts contained in the ItemStack returned by getItemStackToDrop().
      Returns:
      the amount of hearts to remove from the player when they die
    • setHeartsToRemove

      public void setHeartsToRemove(int heartsToRemove)
      Sets the amount of hearts to remove from the player when they die.
      Parameters:
      heartsToRemove - the amount of hearts to remove from the player when they die
    • isCancelled

      public boolean isCancelled()
      Returns if the event had been cancelled.
      Specified by:
      isCancelled in interface org.bukkit.event.Cancellable
      Returns:
      if the event is cancelled
    • setCancelled

      public void setCancelled(boolean cancel)
      Sets if the event should be cancelled. If the event is cancelled, the player will not lose hearts, the ItemStack returned by getItemStackToDrop() will not be dropped. The player will also not be banned if they have less than the minimum amount of hearts.
      Specified by:
      setCancelled in interface org.bukkit.event.Cancellable
      Parameters:
      cancel - true if you wish to cancel this event and prevent the player from losing hearts and dropping the heart item, false otherwise
    • getHandlers

      @NotNull public @NotNull org.bukkit.event.HandlerList getHandlers()
      Gets the handler list.
      Specified by:
      getHandlers in class org.bukkit.event.Event
      Returns:
      the handler list
    • getHandlerList

      public static org.bukkit.event.HandlerList getHandlerList()
      Gets the handler list.
      Returns:
      the handler list