public class ItemStack extends Object implements Cloneable, ConfigurationSerializable, net.kyori.adventure.text.event.HoverEventSource<net.kyori.adventure.text.event.HoverEvent.ShowItem>
IMPORTANT: An ItemStack is only designed to contain items. Do not
use this class to encapsulate Materials for which Material.isItem()
returns false.
Modifier | Constructor and Description |
---|---|
protected |
ItemStack() |
|
ItemStack(@NotNull ItemStack stack)
Creates a new item stack derived from the specified stack
|
|
ItemStack(@NotNull Material type)
Defaults stack size to 1, with no extra data.
|
|
ItemStack(@NotNull Material type,
int amount)
An item stack with no extra data.
|
|
ItemStack(@NotNull Material type,
int amount,
short damage)
Deprecated.
|
|
ItemStack(@NotNull Material type,
int amount,
short damage,
@Nullable Byte data)
Deprecated.
this method uses an ambiguous data byte object
|
Modifier and Type | Method and Description |
---|---|
@NotNull ItemStack |
add()
Adds 1 to this itemstack.
|
@NotNull ItemStack |
add(int qty)
Adds quantity to this itemstack.
|
void |
addEnchantment(@NotNull Enchantment ench,
int level)
Adds the specified
Enchantment to this item stack. |
void |
addEnchantments(@NotNull Map<Enchantment,Integer> enchantments)
Adds the specified enchantments to this item stack.
|
void |
addItemFlags(ItemFlag... itemFlags)
Set itemflags which should be ignored when rendering a ItemStack in the Client.
|
void |
addUnsafeEnchantment(@NotNull Enchantment ench,
int level)
Adds the specified
Enchantment to this item stack. |
void |
addUnsafeEnchantments(@NotNull Map<Enchantment,Integer> enchantments)
Adds the specified enchantments to this item stack in an unsafe manner.
|
net.kyori.adventure.text.event.HoverEvent<net.kyori.adventure.text.event.HoverEvent.ShowItem> |
asHoverEvent(UnaryOperator<net.kyori.adventure.text.event.HoverEvent.ShowItem> op) |
@NotNull ItemStack |
asOne()
Clones the itemstack and returns it a single quantity.
|
@NotNull ItemStack |
asQuantity(int qty)
Clones the itemstack and returns it as the specified quantity
|
boolean |
canRepair(@NotNull ItemStack toBeRepaired)
Checks if this itemstack can repair another.
|
@NotNull ItemStack |
clone() |
boolean |
containsEnchantment(@NotNull Enchantment ench)
Checks if this ItemStack contains the given
Enchantment |
static @NotNull ItemStack |
deserialize(@NotNull Map<String,Object> args)
Required method for configuration serialization
|
static @NotNull ItemStack |
deserializeBytes(@NotNull byte[] bytes)
Deserializes this itemstack from raw NBT bytes.
|
net.kyori.adventure.text.Component |
displayName()
Get the formatted display name of the
ItemStack . |
@NotNull ItemStack |
ensureServerConversions()
Minecart updates are converting simple item stacks into more complex NBT oriented Item Stacks.
|
boolean |
equals(Object obj) |
int |
getAmount()
Gets the amount of items in this stack
|
@Nullable MaterialData |
getData()
Gets the MaterialData for this stack of items
|
short |
getDurability()
Deprecated.
|
int |
getEnchantmentLevel(@NotNull Enchantment ench)
Gets the level of the specified enchantment on this item stack
|
@NotNull Map<Enchantment,Integer> |
getEnchantments()
Gets a map containing all enchantments and their levels on this item.
|
@Nullable String |
getI18NDisplayName()
Gets the Display name as seen in the Client.
|
@NotNull Set<ItemFlag> |
getItemFlags()
Get current set itemFlags.
|
ItemMeta |
getItemMeta()
Get a copy of this ItemStack's
ItemMeta . |
@Nullable List<String> |
getLore()
Deprecated.
in favor of
lore() |
int |
getMaxItemUseDuration() |
int |
getMaxStackSize()
Get the maximum stacksize for the material hold in this ItemStack.
|
ItemRarity |
getRarity()
Gets the item rarity of the itemstack.
|
@NotNull String |
getTranslationKey()
Gets the translation key for this itemstack.
|
@NotNull Material |
getType()
Gets the type of this item
|
int |
hashCode() |
boolean |
hasItemFlag(@NotNull ItemFlag flag)
Check if the specified flag is present on this item.
|
boolean |
hasItemMeta()
Checks to see if any meta data has been defined.
|
boolean |
isRepairableBy(@NotNull ItemStack repairMaterial)
Checks if an itemstack can repair this itemstack.
|
boolean |
isSimilar(@Nullable ItemStack stack)
This method is the same as equals, but does not consider stack size
(amount).
|
@Nullable List<net.kyori.adventure.text.Component> |
lore()
If the item has lore, returns it, else it will return null
|
void |
lore(@Nullable List<net.kyori.adventure.text.Component> lore)
Sets the lore for this item.
|
int |
removeEnchantment(@NotNull Enchantment ench)
Removes the specified
Enchantment if it exists on this
ItemStack |
void |
removeItemFlags(ItemFlag... itemFlags)
Remove specific set of itemFlags.
|
@NotNull Map<String,Object> |
serialize()
Creates a Map representation of this class.
|
@NotNull byte[] |
serializeAsBytes()
Serializes this itemstack to raw bytes in NBT.
|
void |
setAmount(int amount)
Sets the amount of items in this stack
|
void |
setData(@Nullable MaterialData data)
Sets the MaterialData for this stack of items
|
void |
setDurability(short durability)
Deprecated.
durability is now part of ItemMeta. To avoid confusion and
misuse,
getItemMeta() , setItemMeta(ItemMeta) and
Damageable.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. |
boolean |
setItemMeta(@Nullable ItemMeta itemMeta)
Set the ItemMeta of this ItemStack.
|
void |
setLore(@Nullable List<String> lore)
Deprecated.
in favour of
lore(List) |
void |
setType(@NotNull Material type)
Sets the type of this item
|
@NotNull ItemStack |
subtract()
Subtracts 1 to this itemstack.
|
@NotNull ItemStack |
subtract(int qty)
Subtracts quantity to this itemstack.
|
String |
toString() |
protected ItemStack()
public ItemStack(@NotNull @NotNull Material type)
IMPORTANT: An ItemStack is only designed to contain
items. Do not use this class to encapsulate Materials for which
Material.isItem()
returns false.
type
- item materialpublic ItemStack(@NotNull @NotNull Material type, int amount)
IMPORTANT: An ItemStack is only designed to contain
items. Do not use this class to encapsulate Materials for which
Material.isItem()
returns false.
type
- item materialamount
- stack sizepublic ItemStack(@NotNull @NotNull Material type, int amount, short damage)
setDurability(short)
type
- item materialamount
- stack sizedamage
- durability / damage@Deprecated public ItemStack(@NotNull @NotNull Material type, int amount, short damage, @Nullable @Nullable Byte data)
type
- the typeamount
- the amount in the stackdamage
- the damage value of the itemdata
- the data value or nullpublic ItemStack(@NotNull @NotNull ItemStack stack) throws IllegalArgumentException
stack
- the stack to copyIllegalArgumentException
- if the specified stack is null or
returns an item meta not created by the item factory@NotNull public @NotNull Material getType()
public void setType(@NotNull @NotNull Material type)
Note 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.
type
- New type to set the items in this stack topublic int getAmount()
public void setAmount(int amount)
amount
- New amount of items in this stack@Nullable public @Nullable MaterialData getData()
public void setData(@Nullable @Nullable MaterialData data)
data
- New MaterialData for this item@Deprecated public void setDurability(short durability)
getItemMeta()
, setItemMeta(ItemMeta)
and
Damageable.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.durability
- Durability of this item@Deprecated public short getDurability()
setDurability(short)
public int getMaxStackSize()
public boolean isSimilar(@Nullable @Nullable ItemStack stack)
stack
- the item stack to compare topublic boolean containsEnchantment(@NotNull @NotNull Enchantment ench)
Enchantment
ench
- Enchantment to testpublic int getEnchantmentLevel(@NotNull @NotNull Enchantment ench)
ench
- Enchantment to check@NotNull public @NotNull Map<Enchantment,Integer> getEnchantments()
public void addEnchantments(@NotNull @NotNull Map<Enchantment,Integer> enchantments)
This method is the same as calling addEnchantment(org.bukkit.enchantments.Enchantment, int)
for each
element of the map.
enchantments
- Enchantments to addIllegalArgumentException
- if the specified enchantments is nullIllegalArgumentException
- if any specific enchantment or level
is null. Warning: Some enchantments may be added before this
exception is thrown.public void addEnchantment(@NotNull @NotNull Enchantment ench, int level)
Enchantment
to this item stack.
If this item stack already contained the given enchantment (at any level), it will be replaced.
ench
- Enchantment to addlevel
- Level of the enchantmentIllegalArgumentException
- if enchantment null, or enchantment is
not applicablepublic void addUnsafeEnchantments(@NotNull @NotNull Map<Enchantment,Integer> enchantments)
This method is the same as calling addUnsafeEnchantment(org.bukkit.enchantments.Enchantment, int)
for
each element of the map.
enchantments
- Enchantments to addpublic void addUnsafeEnchantment(@NotNull @NotNull Enchantment ench, int level)
Enchantment
to 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.
ench
- Enchantment to addlevel
- Level of the enchantmentpublic int removeEnchantment(@NotNull @NotNull Enchantment ench)
Enchantment
if it exists on this
ItemStackench
- Enchantment to remove@NotNull public @NotNull Map<String,Object> serialize()
ConfigurationSerializable
This class must provide a method to restore this class, as defined in
the ConfigurationSerializable
interface javadocs.
serialize
in interface ConfigurationSerializable
@NotNull public static @NotNull ItemStack deserialize(@NotNull @NotNull Map<String,Object> args)
args
- map to deserializeConfigurationSerializable
public ItemMeta getItemMeta()
ItemMeta
.public boolean hasItemMeta()
public boolean setItemMeta(@Nullable @Nullable ItemMeta itemMeta)
itemMeta
- new ItemMeta, or null to indicate meta data be cleared.ItemFactory.isApplicable(ItemMeta, ItemStack)
IllegalArgumentException
- if the item meta was not created by
the ItemFactory
@NotNull public net.kyori.adventure.text.event.HoverEvent<net.kyori.adventure.text.event.HoverEvent.ShowItem> asHoverEvent(@NotNull UnaryOperator<net.kyori.adventure.text.event.HoverEvent.ShowItem> op)
asHoverEvent
in interface net.kyori.adventure.text.event.HoverEventSource<net.kyori.adventure.text.event.HoverEvent.ShowItem>
@NotNull public net.kyori.adventure.text.Component displayName()
ItemStack
.ItemStack
@NotNull public @NotNull ItemStack ensureServerConversions()
@NotNull public static @NotNull ItemStack deserializeBytes(@NotNull @NotNull byte[] bytes)
serializeAsBytes()
API returned.bytes
- bytes representing an item in NBT@NotNull public @NotNull byte[] serializeAsBytes()
@Nullable public @Nullable String getI18NDisplayName()
public int getMaxItemUseDuration()
@NotNull public @NotNull ItemStack asOne()
@NotNull public @NotNull ItemStack asQuantity(int qty)
qty
- The quantity of the cloned item@NotNull public @NotNull ItemStack add()
@NotNull public @NotNull ItemStack add(int qty)
qty
- The amount to add@NotNull public @NotNull ItemStack subtract()
@NotNull public @NotNull ItemStack subtract(int qty)
qty
- The amount to add@Deprecated @Nullable public @Nullable List<String> getLore()
lore()
@Nullable public @Nullable List<net.kyori.adventure.text.Component> lore()
@Deprecated public void setLore(@Nullable @Nullable List<String> lore)
lore(List)
lore
- the lore that will be setpublic void lore(@Nullable @Nullable List<net.kyori.adventure.text.Component> lore)
lore
- the lore that will be setpublic void addItemFlags(@NotNull ItemFlag... itemFlags)
itemFlags
- The hideflags which shouldn't be renderedpublic void removeItemFlags(@NotNull ItemFlag... itemFlags)
itemFlags
- Hideflags which should be removed@NotNull public @NotNull Set<ItemFlag> getItemFlags()
public boolean hasItemFlag(@NotNull @NotNull ItemFlag flag)
flag
- the flag to check@NotNull public @NotNull String getTranslationKey()
@NotNull public ItemRarity getRarity()
public boolean isRepairableBy(@NotNull @NotNull ItemStack repairMaterial)
this
or repairMaterial
's type is not an item (Material.isItem()
).repairMaterial
- the repair materialpublic boolean canRepair(@NotNull @NotNull ItemStack toBeRepaired)
this
or toBeRepaired
's type is not an item (Material.isItem()
).toBeRepaired
- the itemstack to be repairedCopyright © 2021. All rights reserved.