类 ItemStack

java.lang.Object
org.bukkit.inventory.ItemStack
所有已实现的接口:
Cloneable, ConfigurationSerializable, Translatable

public class ItemStack extends Object implements Cloneable, ConfigurationSerializable, Translatable
代表物品堆.

重要: 物品堆只被设计用于容纳物品. 请不要使用本类来简要描述某种不可获得的物品 (可以用Material.isItem()检测, 不要用 ItemStack存储此方法返回false的物品).

  • 构造器详细资料

    • ItemStack

      protected ItemStack()
    • ItemStack

      public ItemStack(@NotNull @NotNull Material type)
      构造一个堆叠数为1, 无附加数据的物品堆.

      重要: 物品堆只被设计用于容纳物品. 请不要使用本类来简要描述某种不可获得的物品 (可以用Material.isItem()检测, 不要用 ItemStack存储此方法返回false的物品). 原文:Defaults 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.

      参数:
      type - 物品种类
    • ItemStack

      public ItemStack(@NotNull @NotNull Material type, int amount)
      构造指定堆叠数, 无附加数据的物品堆.

      重要: 物品堆只被设计用于容纳物品. 请不要使用本类来简要描述某种不可获得的物品 (可以用Material.isItem()检测, 不要用 ItemStack存储此方法返回false的物品).

      原文:An 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.

      参数:
      type - 物品种类
      amount - 堆叠数
    • ItemStack

      public ItemStack(@NotNull @NotNull Material type, int amount, short damage)
      已过时。
      构造一个具有指定损耗值(耐久度)的物品堆.

      原文:An item stack with the specified damage / durability

      参数:
      type - 物品种类
      amount - 堆叠数
      damage - 损耗值
    • ItemStack

      @Deprecated public ItemStack(@NotNull @NotNull Material type, int amount, short damage, @Nullable @Nullable Byte data)
      已过时。
      该方法使用了意义不明确的data byte对象
      参数:
      type - 物品种类
      amount - 堆叠数
      damage - 损耗值
      data - 数据值或null
    • ItemStack

      public ItemStack(@NotNull @NotNull ItemStack stack) throws IllegalArgumentException
      构造一个指定物品堆的副本.

      原文:Creates a new item stack derived from the specified stack

      参数:
      stack - 要复制的物品堆
      抛出:
      IllegalArgumentException - 如果指定的 stack 为null或返回的 物品元数据不是通过ItemFactory创建的
  • 方法详细资料

    • getType

      @NotNull public @NotNull Material getType()
      获取该物品的种类.

      原文:Gets the type of this item

      返回:
      该物品的种类
    • setType

      public void setType(@NotNull @NotNull Material type)
      设置该物品的种类.

      注:在做这件事的同时你将清除该物品堆上的MaterialData数据.

      重要: 物品堆只被设计用于容纳物品. 请不要使用本类来简要描述某种不可获得的物品 (可以用Material.isItem()检测, 不要用 ItemStack存储此方法返回false的物品).

      原文:Sets the type of this item

      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 - 该物品的种类
    • getAmount

      public int getAmount()
      获取该物品堆的物品堆叠数量.

      原文:Gets the amount of items in this stack

      返回:
      物品堆叠数量
    • setAmount

      public void setAmount(int amount)
      设置该物品堆的物品堆叠数量.

      原文:Sets the amount of items in this stack

      参数:
      amount - 物品堆叠数量
    • getData

      @Nullable public @Nullable MaterialData getData()
      获取该物品堆的 MateralData 数据.

      原文:Gets the MaterialData for this stack of items

      返回:
      物品堆的MaterialData数据
    • setData

      public void setData(@Nullable @Nullable MaterialData data)
      设置该物品堆的 MateralData 数据.

      原文:Sets the MaterialData for this stack of items

      参数:
      data - 物品堆的MaterialData数据
    • setDurability

      @Deprecated public void setDurability(short durability)
      已过时。
      耐久度现在是 ItemMeta 的一部分. 为避免疑虑和误用, 请使用 getItemMeta(), setItemMeta(ItemMeta)Damageable.setDamage(int). 这是因为在调用此方法之前创建的 ItemMeta 的后续变动将覆盖调用此方法设置的物品元数据.
      设置该物品的耐久度.

      原文:Sets the durability of this item

      参数:
      durability - 物品耐久度
    • getDurability

      @Deprecated public short getDurability()
      已过时。
      获取该物品的耐久度.

      原文:Gets the durability of this item

      返回:
      物品耐久度
    • getMaxStackSize

      public int getMaxStackSize()
      获取该物品的最大堆叠数 (若物品未知返回-1).

      原文:Get the maximum stacksize for the material hold in this ItemStack. (Returns -1 if it has no idea)

      返回:
      该物品的最大堆叠数
    • toString

      public String toString()
      覆盖:
      toString 在类中 Object
    • equals

      public boolean equals(Object obj)
      覆盖:
      equals 在类中 Object
    • isSimilar

      public boolean isSimilar(@Nullable @Nullable ItemStack stack)
      该方法与equals方法相同, 但不考虑堆叠数量.

      原文:This method is the same as equals, but does not consider stack size (amount).

      参数:
      stack - 与哪个物品堆作比较
      返回:
      若两者相同返回true (忽略其堆叠数)
    • clone

      @NotNull public @NotNull ItemStack clone()
      覆盖:
      clone 在类中 Object
    • hashCode

      public int hashCode()
      覆盖:
      hashCode 在类中 Object
    • containsEnchantment

      public boolean containsEnchantment(@NotNull @NotNull Enchantment ench)
      检测该物品堆是否包含指定附魔.

      原文:Checks if this ItemStack contains the given Enchantment

      参数:
      ench - 附魔
      返回:
      若该物品含有此附魔返回true
    • getEnchantmentLevel

      public int getEnchantmentLevel(@NotNull @NotNull Enchantment ench)
      获取该物品指定附魔的附魔等级.

      原文:Gets the level of the specified enchantment on this item stack

      参数:
      ench - 附魔
      返回:
      指定附魔的附魔等级, 若附魔不存在/没有附魔则为0
    • getEnchantments

      @NotNull public @NotNull Map<Enchantment,Integer> getEnchantments()
      获取该物品的所有附魔以及对应的附魔等级, 用map表示.

      原文:Gets a map containing all enchantments and their levels on this item.

      返回:
      附魔魔咒
    • addEnchantments

      public void addEnchantments(@NotNull @NotNull Map<Enchantment,Integer> enchantments)
      向物品堆添加附魔.

      该方法实质就是遍历你所给的map, 逐一调用addEnchantment(org.bukkit.enchantments.Enchantment, int).

      原文:Adds 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.

      参数:
      enchantments - 要添加的附魔
      抛出:
      IllegalArgumentException - 若参数enchantments为null
      IllegalArgumentException - 若任何指定的附魔或等级为null. 警告: 某些附魔可能会在此异常抛出前添加到此物品上
    • addEnchantment

      public void addEnchantment(@NotNull @NotNull Enchantment ench, int level)
      向物品堆添加附魔.

      若此物品堆已经含有给定的附魔(无论它们的附魔等级是什么), 将替换已有的附魔.

      原文:Adds the specified Enchantment to this item stack.

      If this item stack already contained the given enchantment (at any level), it will be replaced.

      参数:
      ench - 附魔
      level - 附魔等级
      抛出:
      IllegalArgumentException - 若enchantment为null, 或该附魔不可应用于此物品上
    • addUnsafeEnchantments

      public void addUnsafeEnchantments(@NotNull @NotNull Map<Enchantment,Integer> enchantments)
      以不安全的方式向物品堆添加附魔.

      该方法实质就是遍历你所给的map, 逐一调用addUnsafeEnchantment(org.bukkit.enchantments.Enchantment, int).

      原文:Adds 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.

      参数:
      enchantments - 附魔
    • addUnsafeEnchantment

      public void addUnsafeEnchantment(@NotNull @NotNull Enchantment ench, int level)
      向物品堆添加附魔.

      若此物品堆已经含有给定的附魔(无论它们的附魔等级是什么), 将替换已有的附魔.

      该方法是个不安全操作, 忽略附魔的等级限制以及对此物品的可用性. 请慎重使用.

      原文:Adds the specified 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 - 附魔
      level - 附魔等级
    • removeEnchantment

      public int removeEnchantment(@NotNull @NotNull Enchantment ench)
      移除指定的附魔.

      原文:Removes the specified Enchantment if it exists on this ItemStack

      参数:
      ench - 要移除的附魔
      返回:
      附魔先前的等级, 若附魔不存在为0
    • serialize

      @NotNull public @NotNull Map<String,Object> serialize()
      从接口复制的说明: ConfigurationSerializable
      Creates a Map representation of this class.

      This class must provide a method to restore this class, as defined in the ConfigurationSerializable interface javadocs.

      指定者:
      serialize 在接口中 ConfigurationSerializable
      返回:
      Map containing the current state of this class
    • deserialize

      @NotNull public static @NotNull ItemStack deserialize(@NotNull @NotNull Map<String,Object> args)
      实现配置序列化与反序列化需要的方法.

      原文:Required method for configuration serialization

      参数:
      args - 需要反序列化的map
      返回:
      反序列化后的物品堆
      另请参阅:
    • getItemMeta

      @Nullable public @Nullable ItemMeta getItemMeta()
      获取此物品堆的ItemMeta的副本.

      原文:Get a copy of this ItemStack's ItemMeta.

      返回:
      物品堆元数据副本
    • hasItemMeta

      public boolean hasItemMeta()
      检测该物品堆是否含有任何物品元数据.

      原文:Checks to see if any meta data has been defined.

      返回:
      返回该物品是否被设置了任何附加元数据值
    • setItemMeta

      public boolean setItemMeta(@Nullable @Nullable ItemMeta itemMeta)
      向物品堆设置元数据.

      原文:Set the ItemMeta of this ItemStack.

      参数:
      itemMeta - 新物品元数据,或用null来清除此物品上的元数据
      返回:
      若成功应用物品元数据返回true, 另请参见 ItemFactory.isApplicable(ItemMeta, ItemStack)
      抛出:
      IllegalArgumentException - 物品元数据不是通过ItemFactory创建的
    • getTranslationKey

      @NotNull public @NotNull String getTranslationKey()
      从接口复制的说明: Translatable
      Get the translation key, suitable for use in a translation component.
      指定者:
      getTranslationKey 在接口中 Translatable
      返回:
      the translation key