Package valorless.valorlessutils.items
Class ItemUtils
java.lang.Object
valorless.valorlessutils.items.ItemUtils
Utility class for interacting with
ItemMeta
fields introduced in Minecraft 1.20.5+.
These helper methods allow for easy access to new item metadata, such as:
- Item name (internal vs. display name)
- Item rarity
- Custom max stack size
- Item model (resource key)
Note: These methods rely on APIs only available in 1.20.5 and above. Always check the server version before calling these methods to avoid errors on older servers.
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic String
GetCustomName
(org.bukkit.inventory.ItemStack item) Gets the custom display name.static org.bukkit.NamespacedKey
GetItemModel
(org.bukkit.inventory.ItemStack item) Gets the namespaced key of the item's model.static String
GetItemName
(org.bukkit.inventory.ItemStack item) Gets the internal item name.static Integer
GetMaxStackSize
(org.bukkit.inventory.ItemStack item) Gets the maximum stack size defined on the item.static String
GetRarity
(org.bukkit.inventory.ItemStack item) Gets the rarity of the item as a string.static Boolean
HasCustomName
(org.bukkit.inventory.ItemStack item) Checks if the item has a custom display name.static Boolean
HasItemName
(org.bukkit.inventory.ItemStack item) Checks if the item has an internal item name.static Boolean
HasMaxStackSize
(org.bukkit.inventory.ItemStack item) Checks if the item has a custom max stack size.static Boolean
HasRarity
(org.bukkit.inventory.ItemStack item) Checks if the item has a rarity value.static void
SetCustomName
(org.bukkit.inventory.ItemStack item, String name) Sets the custom display name.static void
SetItemModel
(org.bukkit.inventory.ItemStack item, String value) Sets the item model using a string in the format "namespace:key".static void
SetItemModel
(org.bukkit.inventory.ItemStack item, org.bukkit.NamespacedKey value) Sets the item model using aNamespacedKey
.static void
SetItemName
(org.bukkit.inventory.ItemStack item, String name) Sets the internal item name.static void
SetMaxStackSize
(org.bukkit.inventory.ItemStack item, Integer value) Sets a custom maximum stack size for the item.static void
Sets the rarity of the item.
-
Constructor Details
-
ItemUtils
public ItemUtils()
-
-
Method Details
-
HasItemName
Checks if the item has an internal item name.- Parameters:
item
- TheItemStack
to check- Returns:
- True if the item has an internal name, false otherwise
-
GetItemName
Gets the internal item name.- Parameters:
item
- TheItemStack
to get the name from- Returns:
- The item name string
-
SetItemName
Sets the internal item name.- Parameters:
item
- TheItemStack
to modifyname
- The name to set
-
HasCustomName
Checks if the item has a custom display name.- Parameters:
item
- TheItemStack
to check- Returns:
- True if the item has a display name, false otherwise
-
GetCustomName
Gets the custom display name.- Parameters:
item
- TheItemStack
to get the display name from- Returns:
- The display name string
-
SetCustomName
Sets the custom display name.- Parameters:
item
- TheItemStack
to modifyname
- The display name to set
-
HasRarity
Checks if the item has a rarity value.- Parameters:
item
- TheItemStack
to check- Returns:
- True if the item has a rarity, false otherwise
-
GetRarity
Gets the rarity of the item as a string.- Parameters:
item
- TheItemStack
to get rarity from- Returns:
- The rarity as a string (e.g., "COMMON", "RARE", "EPIC")
-
SetRarity
Sets the rarity of the item.- Parameters:
item
- TheItemStack
to modifyrarity
- The rarity as a string (must matchItemRarity
name)
-
HasMaxStackSize
Checks if the item has a custom max stack size.- Parameters:
item
- TheItemStack
to check- Returns:
- True if a custom max stack size is set, false otherwise
-
GetMaxStackSize
Gets the maximum stack size defined on the item.- Parameters:
item
- TheItemStack
to get the value from- Returns:
- The maximum stack size
-
SetMaxStackSize
Sets a custom maximum stack size for the item.- Parameters:
item
- TheItemStack
to modifyvalue
- The maximum stack size value
-
GetItemModel
public static org.bukkit.NamespacedKey GetItemModel(org.bukkit.inventory.ItemStack item) Gets the namespaced key of the item's model.- Parameters:
item
- TheItemStack
to query- Returns:
- The
NamespacedKey
representing the item model
-
SetItemModel
public static void SetItemModel(org.bukkit.inventory.ItemStack item, org.bukkit.NamespacedKey value) Sets the item model using aNamespacedKey
.- Parameters:
item
- TheItemStack
to modifyvalue
- TheNamespacedKey
of the model
-
SetItemModel
Sets the item model using a string in the format "namespace:key".- Parameters:
item
- TheItemStack
to modifyvalue
- The string representing the model key
-