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 StringGetCustomName(org.bukkit.inventory.ItemStack item) Gets the custom display name.static org.bukkit.NamespacedKeyGetItemModel(org.bukkit.inventory.ItemStack item) Gets the namespaced key of the item's model.static StringGetItemName(org.bukkit.inventory.ItemStack item) Gets the internal item name.static IntegerGetMaxStackSize(org.bukkit.inventory.ItemStack item) Gets the maximum stack size defined on the item.static StringGetRarity(org.bukkit.inventory.ItemStack item) Gets the rarity of the item as a string.static BooleanHasCustomName(org.bukkit.inventory.ItemStack item) Checks if the item has a custom display name.static BooleanHasItemName(org.bukkit.inventory.ItemStack item) Checks if the item has an internal item name.static BooleanHasMaxStackSize(org.bukkit.inventory.ItemStack item) Checks if the item has a custom max stack size.static BooleanHasRarity(org.bukkit.inventory.ItemStack item) Checks if the item has a rarity value.static voidSetCustomName(org.bukkit.inventory.ItemStack item, String name) Sets the custom display name.static voidSetItemModel(org.bukkit.inventory.ItemStack item, String value) Sets the item model using a string in the format "namespace:key".static voidSetItemModel(org.bukkit.inventory.ItemStack item, org.bukkit.NamespacedKey value) Sets the item model using aNamespacedKey.static voidSetItemName(org.bukkit.inventory.ItemStack item, String name) Sets the internal item name.static voidSetMaxStackSize(org.bukkit.inventory.ItemStack item, Integer value) Sets a custom maximum stack size for the item.static voidSets the rarity of the item.
-
Constructor Details
-
ItemUtils
public ItemUtils()
-
-
Method Details
-
HasItemName
Checks if the item has an internal item name.- Parameters:
item- TheItemStackto check- Returns:
- True if the item has an internal name, false otherwise
-
GetItemName
Gets the internal item name.- Parameters:
item- TheItemStackto get the name from- Returns:
- The item name string
-
SetItemName
Sets the internal item name.- Parameters:
item- TheItemStackto modifyname- The name to set
-
HasCustomName
Checks if the item has a custom display name.- Parameters:
item- TheItemStackto check- Returns:
- True if the item has a display name, false otherwise
-
GetCustomName
Gets the custom display name.- Parameters:
item- TheItemStackto get the display name from- Returns:
- The display name string
-
SetCustomName
Sets the custom display name.- Parameters:
item- TheItemStackto modifyname- The display name to set
-
HasRarity
Checks if the item has a rarity value.- Parameters:
item- TheItemStackto check- Returns:
- True if the item has a rarity, false otherwise
-
GetRarity
Gets the rarity of the item as a string.- Parameters:
item- TheItemStackto get rarity from- Returns:
- The rarity as a string (e.g., "COMMON", "RARE", "EPIC")
-
SetRarity
Sets the rarity of the item.- Parameters:
item- TheItemStackto modifyrarity- The rarity as a string (must matchItemRarityname)
-
HasMaxStackSize
Checks if the item has a custom max stack size.- Parameters:
item- TheItemStackto 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- TheItemStackto get the value from- Returns:
- The maximum stack size
-
SetMaxStackSize
Sets a custom maximum stack size for the item.- Parameters:
item- TheItemStackto 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- TheItemStackto query- Returns:
- The
NamespacedKeyrepresenting 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- TheItemStackto modifyvalue- TheNamespacedKeyof the model
-
SetItemModel
Sets the item model using a string in the format "namespace:key".- Parameters:
item- TheItemStackto modifyvalue- The string representing the model key
-