Class LifestealerHeartItemManager
java.lang.Object
dev.chicoferreira.lifestealer.item.LifestealerHeartItemManager
-
Nested Class Summary
Nested Classes -
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final org.bukkit.NamespacedKeystatic final org.bukkit.NamespacedKey -
Constructor Summary
ConstructorsConstructorDescriptionLifestealerHeartItemManager(LifestealerHeartItemManager.Settings itemManagerSettings) -
Method Summary
Modifier and TypeMethodDescriptionintcalculateTotalHeartsInInventory(org.bukkit.entity.Player player) Calculates the total amount of hearts given by the heart items in the player's inventory.intcountHeartItems(@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.ItemStackgenerateItem(@NotNull LifestealerHeartItem heartItem) Generates an item stack from aLifestealerHeartItemwith the correct properties from the item.@Nullable org.bukkit.inventory.ItemStackgenerateItem(String heartItemType) Gets aLifestealerHeartItemfrom the item type name and callsgenerateItem(LifestealerHeartItem).intgetHearts(@NotNull org.bukkit.inventory.ItemStack itemStack) Gets the amount of hearts an item stack gives.@Nullable LifestealerHeartItemReturns the registered item with the given type name.@NotNull StringThis method returns the item type name to drop when the player dies.@NotNull LifestealerHeartItemReturns the @LifestealerHeartItemto drop when the player dies.@Nullable StringgetItemType(@NotNull org.bukkit.inventory.ItemStack itemStack) Gets the item type stored in the item stack.intgiveHeartItems(@NotNull org.bukkit.entity.Player player, @NotNull LifestealerHeartItem heartItem, int amount) Gives heart items to the player.voidregisterItem(@NotNull LifestealerHeartItem item) Registers the item in the item manager.inttakeHeartItems(@NotNull org.bukkit.entity.Player player, @NotNull String typeName, int amount) Takes heart items from the player's inventory.voidUpdates 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 @LifestealerHeartItemto drop when the player dies. This method will never return null- Returns:
- The @
LifestealerHeartItemto drop when the player dies
-
generateItem
Gets aLifestealerHeartItemfrom 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 aLifestealerHeartItemwith 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_KEYin 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_KEYin 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_KEYin 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_KEYin 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.
-