Class LifestealerHeartItemManager
java.lang.Object
dev.chicoferreira.lifestealer.item.LifestealerHeartItemManager
-
Nested Class Summary
Nested Classes -
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final org.bukkit.NamespacedKey
static final org.bukkit.NamespacedKey
-
Constructor Summary
ConstructorsConstructorDescriptionLifestealerHeartItemManager
(LifestealerHeartItemManager.Settings itemManagerSettings) -
Method Summary
Modifier and TypeMethodDescriptionint
calculateTotalHeartsInInventory
(org.bukkit.entity.Player player) Calculates the total amount of hearts given by the heart items in the player's inventory.int
countHeartItems
(@NotNull org.bukkit.entity.Player player, @NotNull String typeName) Counts the heart items with the given type name in the player's inventory.@NotNull org.bukkit.inventory.ItemStack
generateItem
(@NotNull LifestealerHeartItem heartItem) Generates an item stack from aLifestealerHeartItem
with the correct properties from the item.@Nullable org.bukkit.inventory.ItemStack
generateItem
(String heartItemType) Gets aLifestealerHeartItem
from the item type name and callsgenerateItem(LifestealerHeartItem)
.int
getHearts
(@NotNull org.bukkit.inventory.ItemStack itemStack) Gets the amount of hearts an item stack gives.@Nullable LifestealerHeartItem
Returns the registered item with the given type name.@NotNull String
This method returns the item type name to drop when the player dies.@NotNull LifestealerHeartItem
Returns the @LifestealerHeartItem
to drop when the player dies.@Nullable String
getItemType
(@NotNull org.bukkit.inventory.ItemStack itemStack) Gets the item type stored in the item stack.int
giveHeartItems
(@NotNull org.bukkit.entity.Player player, @NotNull LifestealerHeartItem heartItem, int amount) Gives heart items to the player.void
registerItem
(@NotNull LifestealerHeartItem item) Registers the item in the item manager.int
takeHeartItems
(@NotNull org.bukkit.entity.Player player, @NotNull String typeName, int amount) Takes heart items from the player's inventory.void
Updates this item manager with new settings.
-
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
-
LifestealerHeartItemManager
-
-
Method Details
-
updateSettings
Updates this item manager with new settings. Used when the configuration is reloaded.- Parameters:
settings
- the new settings
-
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
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
Gets aLifestealerHeartItem
from the item type name and callsgenerateItem(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 aLifestealerHeartItem
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
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 withgenerateItem(LifestealerHeartItem)
, the manager will add the correct NBT data to the item stack.- Parameters:
item
- The item to register
-
getItem
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 theITEM_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 inventorytypeName
- 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 theITEM_TYPE_KEY
in the item meta's persistent data container- Parameters:
player
- the player to take the heart items fromtypeName
- the heart item name type to takeamount
- 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 toheartItem
- the heart item to giveamount
- 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
- Returns:
- An immutable list of all the heart type names registered in the item manager.
-
getHeartItems
- Returns:
- An immutable list of all the heart items registered in the item manager.
-