Class ItemStack
- All Implemented Interfaces:
- Cloneable,- ConfigurationSerializable,- Translatable
 IMPORTANT: An ItemStack is only designed to contain items. Do not
 use this class to encapsulate Materials for which Material.isItem()
 returns false.
- 
Constructor SummaryConstructorsModifierConstructorDescriptionprotectedCreates a new item stack derived from the specified stackDefaults stack size to 1, with no extra data.An item stack with no extra data.Deprecated.Deprecated.this method uses an ambiguous data byte object
- 
Method SummaryModifier and TypeMethodDescriptionvoidaddEnchantment(Enchantment ench, int level) Adds the specifiedEnchantmentto this item stack.voidaddEnchantments(Map<Enchantment, Integer> enchantments) Adds the specified enchantments to this item stack.voidaddUnsafeEnchantment(Enchantment ench, int level) Adds the specifiedEnchantmentto this item stack.voidaddUnsafeEnchantments(Map<Enchantment, Integer> enchantments) Adds the specified enchantments to this item stack in an unsafe manner.clone()booleanChecks if this ItemStack contains the givenEnchantmentstatic ItemStackdeserialize(Map<String, Object> args) Required method for configuration serializationbooleanintGets the amount of items in this stackgetData()Gets the MaterialData for this stack of itemsshortDeprecated.intGets the level of the specified enchantment on this item stackGets a map containing all enchantments and their levels on this item.Get a copy of this ItemStack'sItemMeta.intGet the maximum stack size for this item.Get the translation key, suitable for use in a translation component.getType()Gets the type of this iteminthashCode()booleanChecks to see if any meta data has been defined.booleanThis method is the same as equals, but does not consider stack size (amount).intremoveEnchantment(Enchantment ench) Removes the specifiedEnchantmentif it exists on this ItemStackvoidRemoves all enchantments on this ItemStack.Creates a Map representation of this class.voidsetAmount(int amount) Sets the amount of items in this stackvoidsetData(MaterialData data) Sets the MaterialData for this stack of itemsvoidsetDurability(short durability) Deprecated.durability is now part of ItemMeta.booleansetItemMeta(ItemMeta itemMeta) Set the ItemMeta of this ItemStack.voidSets the type of this itemtoString()
- 
Constructor Details- 
ItemStackprotected ItemStack()
- 
ItemStackDefaults stack size to 1, with no extra data.IMPORTANT: An ItemStack is only designed to contain items. Do not use this class to encapsulate Materials for which Material.isItem()returns false.- Parameters:
- type- item material
 
- 
ItemStackAn item stack with no extra data.IMPORTANT: An ItemStack is only designed to contain items. Do not use this class to encapsulate Materials for which Material.isItem()returns false.- Parameters:
- type- item material
- amount- stack size
 
- 
ItemStackDeprecated.An item stack with the specified damage / durability- Parameters:
- type- item material
- amount- stack size
- damage- durability / damage
 
- 
ItemStack@Deprecated(since="1.4.5") public ItemStack(@NotNull Material type, int amount, short damage, @Nullable Byte data) Deprecated.this method uses an ambiguous data byte object- Parameters:
- type- the type
- amount- the amount in the stack
- damage- the damage value of the item
- data- the data value or null
 
- 
ItemStackCreates a new item stack derived from the specified stack- Parameters:
- stack- the stack to copy
- Throws:
- IllegalArgumentException- if the specified stack is null or returns an item meta not created by the item factory
 
 
- 
- 
Method Details- 
getTypeGets the type of this item- Returns:
- Type of the items in this stack
 
- 
setTypeSets the type of this itemNote that in doing so you will reset the MaterialData for this stack. IMPORTANT: An ItemStack is only designed to contain items. Do not use this class to encapsulate Materials for which Material.isItem()returns false.- Parameters:
- type- New type to set the items in this stack to
 
- 
getAmountpublic int getAmount()Gets the amount of items in this stack- Returns:
- Amount of items in this stack
 
- 
setAmountpublic void setAmount(int amount) Sets the amount of items in this stack- Parameters:
- amount- New amount of items in this stack
 
- 
getDataGets the MaterialData for this stack of items- Returns:
- MaterialData for this item
 
- 
setDataSets the MaterialData for this stack of items- Parameters:
- data- New MaterialData for this item
 
- 
setDurabilityDeprecated.durability is now part of ItemMeta. To avoid confusion and misuse,getItemMeta(),setItemMeta(ItemMeta)andDamageable.setDamage(int)should be used instead. This is because any call to this method will be overwritten by subsequent setting of ItemMeta which was created before this call.Sets the durability of this item- Parameters:
- durability- Durability of this item
 
- 
getDurabilityDeprecated.Gets the durability of this item- Returns:
- Durability of this item
 
- 
getMaxStackSizepublic int getMaxStackSize()Get the maximum stack size for this item. If this item has a max stack size component (ItemMeta.hasMaxStackSize()), the value of that component will be returned. Otherwise, this item's Material'sdefault maximum stack sizewill be returned instead.- Returns:
- The maximum you can stack this item to.
 
- 
toString
- 
equals
- 
isSimilarThis method is the same as equals, but does not consider stack size (amount).- Parameters:
- stack- the item stack to compare to
- Returns:
- true if the two stacks are equal, ignoring the amount
 
- 
clone
- 
hashCodepublic int hashCode()
- 
containsEnchantmentChecks if this ItemStack contains the givenEnchantment- Parameters:
- ench- Enchantment to test
- Returns:
- True if this has the given enchantment
 
- 
getEnchantmentLevelGets the level of the specified enchantment on this item stack- Parameters:
- ench- Enchantment to check
- Returns:
- Level of the enchantment, or 0
 
- 
getEnchantmentsGets a map containing all enchantments and their levels on this item.- Returns:
- Map of enchantments.
 
- 
addEnchantmentsAdds the specified enchantments to this item stack.This method is the same as calling addEnchantment(org.bukkit.enchantments.Enchantment, int)for each element of the map.- Parameters:
- enchantments- Enchantments to add
- Throws:
- IllegalArgumentException- if the specified enchantments is null
- IllegalArgumentException- if any specific enchantment or level is null. Warning: Some enchantments may be added before this exception is thrown.
 
- 
addEnchantmentAdds the specifiedEnchantmentto this item stack.If this item stack already contained the given enchantment (at any level), it will be replaced. - Parameters:
- ench- Enchantment to add
- level- Level of the enchantment
- Throws:
- IllegalArgumentException- if enchantment null, or enchantment is not applicable
 
- 
addUnsafeEnchantmentsAdds the specified enchantments to this item stack in an unsafe manner.This method is the same as calling addUnsafeEnchantment(org.bukkit.enchantments.Enchantment, int)for each element of the map.- Parameters:
- enchantments- Enchantments to add
 
- 
addUnsafeEnchantmentAdds the specifiedEnchantmentto this item stack.If this item stack already contained the given enchantment (at any level), it will be replaced. This method is unsafe and will ignore level restrictions or item type. Use at your own discretion. - Parameters:
- ench- Enchantment to add
- level- Level of the enchantment
 
- 
removeEnchantmentRemoves the specifiedEnchantmentif it exists on this ItemStack- Parameters:
- ench- Enchantment to remove
- Returns:
- Previous level, or 0
 
- 
removeEnchantmentspublic void removeEnchantments()Removes all enchantments on this ItemStack.
- 
serializeDescription copied from interface:ConfigurationSerializableCreates a Map representation of this class.This class must provide a method to restore this class, as defined in the ConfigurationSerializableinterface javadocs.- Specified by:
- serializein interface- ConfigurationSerializable
- Returns:
- Map containing the current state of this class
 
- 
deserializeRequired method for configuration serialization- Parameters:
- args- map to deserialize
- Returns:
- deserialized item stack
- See Also:
 
- 
getItemMetaGet a copy of this ItemStack'sItemMeta.- Returns:
- a copy of the current ItemStack's ItemData
 
- 
hasItemMetapublic boolean hasItemMeta()Checks to see if any meta data has been defined.- Returns:
- Returns true if some meta data has been set for this item
 
- 
setItemMetaSet the ItemMeta of this ItemStack.- Parameters:
- itemMeta- new ItemMeta, or null to indicate meta data be cleared.
- Returns:
- True if successfully applied ItemMeta, see ItemFactory.isApplicable(ItemMeta, ItemStack)
- Throws:
- IllegalArgumentException- if the item meta was not created by the- ItemFactory
 
- 
getTranslationKeyDescription copied from interface:TranslatableGet the translation key, suitable for use in a translation component.- Specified by:
- getTranslationKeyin interface- Translatable
- Returns:
- the translation key
 
 
- 
setDurability(short)