Class LifestealerHeartItemManager

java.lang.Object
dev.chicoferreira.lifestealer.item.LifestealerHeartItemManager

public class LifestealerHeartItemManager extends Object
  • Field Details

    • HEARTS_AMOUNT_KEY

      public static final org.bukkit.NamespacedKey HEARTS_AMOUNT_KEY
    • ITEM_TYPE_KEY

      public static final org.bukkit.NamespacedKey ITEM_TYPE_KEY
  • Constructor Details

  • Method Details

    • updateSettings

      public void updateSettings(LifestealerHeartItemManager.Settings settings)
      Updates this item manager with new settings. Used when the configuration is reloaded.
      Parameters:
      settings - the new settings
    • getItemNameToDropWhenPlayerDies

      @NotNull public @NotNull String getItemNameToDropWhenPlayerDies()
      This method returns the item type name to drop when the player dies. By the other invariants, this item type name must exist in the items map.
      Returns:
      The item type name to drop when the player dies
    • getItemToDropWhenPlayerDies

      @NotNull public @NotNull LifestealerHeartItem getItemToDropWhenPlayerDies()
      Returns the @LifestealerHeartItem to drop when the player dies. This method will never return null
      Returns:
      The @LifestealerHeartItem to drop when the player dies
    • generateItem

      @Nullable public @Nullable org.bukkit.inventory.ItemStack generateItem(String heartItemType)
      Gets a LifestealerHeartItem from the item type name and calls generateItem(LifestealerHeartItem).
      Parameters:
      heartItemType - The type name of the heart item
      Returns:
      The generated item stack or null if the item type does not exist
    • generateItem

      @NotNull public @NotNull org.bukkit.inventory.ItemStack generateItem(@NotNull @NotNull LifestealerHeartItem heartItem)
      Generates an item stack from a LifestealerHeartItem with the correct properties from the item. The item stack will have the amount of hearts in the NBT data.
      Parameters:
      heartItem - The item to generate the item stack from
      Returns:
      The generated item stack
    • registerItem

      public void registerItem(@NotNull @NotNull LifestealerHeartItem item)
      Registers the item in the item manager. After this method is called, players can get this item from the /lifestealer item give command.

      The LifestealerHeartItem.baseItemStack() doesn't need to have the NBT data for the amount of hearts and the item type. When generating the item stack with generateItem(LifestealerHeartItem), the manager will add the correct NBT data to the item stack.

      Parameters:
      item - The item to register
    • getItem

      @Nullable public @Nullable LifestealerHeartItem getItem(@NotNull @NotNull String typeName)
      Returns the registered item with the given type name. Only use this method if you need this for type safety or getting the amount of hearts without generating the item stack.

      Use generateItem(String) to get the item stack instead.

      Parameters:
      typeName - The type name of the item to search
      Returns:
      The item with the given type name or null if the item does not exist
    • getHearts

      public int getHearts(@NotNull @NotNull org.bukkit.inventory.ItemStack itemStack)
      Gets the amount of hearts an item stack gives. This method will return 0 if the item stack is not a lifestealer heart item.

      Internaly, this method looks up the HEARTS_AMOUNT_KEY in the item meta's persistent data container.

      Parameters:
      itemStack - The item stack to get the hearts from
      Returns:
      The amount of hearts the item stack gives
    • calculateTotalHeartsInInventory

      public int calculateTotalHeartsInInventory(org.bukkit.entity.Player player)
      Calculates the total amount of hearts given by the heart items in the player's inventory. For example, if the player has 3 heart items that give 2 hearts each, this method will return 6.
      Parameters:
      player - The player to get the sum of heart items in the inventory
      Returns:
      The total number of hearts given by the heart items in the player's inventory
    • getItemType

      @Nullable public @Nullable String getItemType(@NotNull @NotNull org.bukkit.inventory.ItemStack itemStack)
      Gets the item type stored in the item stack. This method will return null if the item stack is not a lifestealer heart item.

      Internaly, this method looks up the ITEM_TYPE_KEY in the item meta's persistent data container.

      Parameters:
      itemStack - The item stack to get the type from
      Returns:
      The item type stored in the ItemStack or null if the item stack is not a lifestealer heart item
    • countHeartItems

      public int countHeartItems(@NotNull @NotNull org.bukkit.entity.Player player, @NotNull @NotNull String typeName)
      Counts the heart items with the given type name in the player's inventory. Internally, this method looks up the ITEM_TYPE_KEY in the item meta's persistent data container to check the item type name.
      Parameters:
      player - the player to count the heart items in the inventory
      typeName - the type name of the item to count
      Returns:
      the amount of heart items in the player's inventory
    • takeHeartItems

      public int takeHeartItems(@NotNull @NotNull org.bukkit.entity.Player player, @NotNull @NotNull String typeName, int amount)
      Takes heart items from the player's inventory. Internally, this method looks up the ITEM_TYPE_KEY in the item meta's persistent data container
      Parameters:
      player - the player to take the heart items from
      typeName - the heart item name type to take
      amount - the amount of heart items to take
      Returns:
      the amount of heart items that could not be taken (if the player does not have enough)
    • giveHeartItems

      public int giveHeartItems(@NotNull @NotNull org.bukkit.entity.Player player, @NotNull @NotNull LifestealerHeartItem heartItem, int amount)
      Gives heart items to the player. The method will return the amount of heart items that could not be given, when the player's inventory becomes full.
      Parameters:
      player - the player to give the heart items to
      heartItem - the heart item to give
      amount - the amount of heart items to give
      Returns:
      the amount of heart items that could not be given (if the player's inventory is full)
    • getItemTypeNames

      public List<String> getItemTypeNames()
      Returns:
      An immutable list of all the heart type names registered in the item manager.
    • getHeartItems

      public List<LifestealerHeartItem> getHeartItems()
      Returns:
      An immutable list of all the heart items registered in the item manager.