接口 ItemMeta
- 所有已知子接口:
ArmorMeta
,AxolotlBucketMeta
,BannerMeta
,BlockDataMeta
,BlockStateMeta
,BookMeta
,BundleMeta
,ColorableArmorMeta
,CompassMeta
,CrossbowMeta
,Damageable
,EnchantmentStorageMeta
,FireworkEffectMeta
,FireworkMeta
,KnowledgeBookMeta
,LeatherArmorMeta
,MapMeta
,MusicInstrumentMeta
,OminousBottleMeta
,PotionMeta
,Repairable
,SkullMeta
,SpawnEggMeta
,SuspiciousStewMeta
,TropicalFishBucketMeta
,WritableBookMeta
接口的实现会处理 ItemMeta 的创建和应用. 本类不应由实时环境中的插件实现.
-
方法概要
修饰符和类型方法说明boolean
addAttributeModifier
(@NotNull Attribute attribute, @NotNull AttributeModifier modifier) 添加一个属性和它的修饰符.boolean
addEnchant
(@NotNull Enchantment ench, int level, boolean ignoreLevelRestriction) 为物品添加一个附魔.void
addItemFlags
(@NotNull ItemFlag... itemFlags) 设置物品的 flag, 用来指定客户端渲染物品堆信息时隐藏哪些属性.clone()
Get this ItemMeta as a component-compliant string.Get this ItemMeta as an NBT string.返回所有属性及其修饰符的不可变副本.
如果不存在则返回 null.getAttributeModifiers
(@NotNull Attribute attribute) 返回指定EquipmentSlot
的所有属性及其修饰符的不可变列表.int
获取物品的自定义模型数据.已过时。获取物品的展示名.int
获取物品上指定附魔的等级.Sets the enchantment_glint_override.返回此物品上的附魔的 map 副本.
如果物品没有附魔则返回空 map.getFood()
Gets the food set on this item, or creates an empty food instance.获取当前设置的 itemFlags.Gets the item name that is set.Gets the jukebox playable component set on this item.已过时, 待删除: 此 API 元素将从以后的版本中删除。属性不再存在getLore()
获取物品的 lore.int
Gets the max_stack_size.Gets the item rarity.getTool()
Gets the tool set on this item, or creates an empty tool instance.boolean
检查物品是否存在任何属性修饰符.boolean
检查指定的附魔是否与任何 ItemMeta 里的附魔冲突.boolean
检查物品是否存在自定义模型数据.boolean
检查物品是否有展示名.boolean
hasEnchant
(@NotNull Enchantment ench) 检查物品是否存在指定的附魔.boolean
Gets if an enchantment_glint_override is set.boolean
检查物品是否含有附魔.boolean
hasFood()
Checks if the food is set.boolean
hasItemFlag
(@NotNull ItemFlag flag) 检查物品是否存在指定的 flag.boolean
Checks for existence of an item name.boolean
Checks if the jukebox playable is set.boolean
已过时, 待删除: 此 API 元素将从以后的版本中删除。属性不再存在boolean
hasLore()
检查物品是否存在 lore.boolean
Gets if the max_stack_size is set.boolean
Gets if the rarity is set.boolean
hasTool()
Checks if the tool is set.boolean
Checks if this item is fire_resistant.boolean
Gets if this item has hide_tooltip set.boolean
返回物品的 unbreakable 标签是否为 true.boolean
removeAttributeModifier
(@NotNull Attribute attribute) boolean
removeAttributeModifier
(@NotNull Attribute attribute, @NotNull AttributeModifier modifier) boolean
为指定的EquipmentSlot
移除其所有的属性
和属性修饰符
.
如果给定的EquipmentSlot
为 null, 这将移除所有没有设置EquipmentSlot
的AttributeModifier
.boolean
removeEnchant
(@NotNull Enchantment ench) 移除物品上指定的附魔.void
移除物品上的全部附魔.void
removeItemFlags
(@NotNull ItemFlag... itemFlags) 移除指定的一系列 itemFlags.void
setAttributeModifiers
(@Nullable Multimap<Attribute, AttributeModifier> attributeModifiers) void
设置物品的自定义模型数据.void
setDisplayName
(@Nullable String name) 设置物品的展示名.void
setEnchantmentGlintOverride
(@Nullable Boolean override) Sets the enchantment_glint_override.void
setFireResistant
(boolean fireResistant) Sets if this item is fire_resistant.void
setFood
(@Nullable FoodComponent food) Sets the item food.void
setHideTooltip
(boolean hideTooltip) Sets if this item has hide_tooltip set.void
setItemName
(@Nullable String name) Sets the item name.void
setJukeboxPlayable
(@Nullable JukeboxPlayableComponent jukeboxPlayable) Sets the item tool.void
setLocalizedName
(@Nullable String name) 已过时, 待删除: 此 API 元素将从以后的版本中删除。属性不再存在void
为物品设置 lore.void
Sets the max_stack_size.void
setRarity
(@Nullable ItemRarity rarity) Sets the item rarity.void
setTool
(@Nullable ToolComponent tool) Sets the item tool.void
setUnbreakable
(boolean unbreakable) 设置物品的 unbreakable 标签是否为 true.void
setVersion
(int version) 仅供内部使用!从接口继承的方法 org.bukkit.configuration.serialization.ConfigurationSerializable
serialize
从接口继承的方法 org.bukkit.persistence.PersistentDataHolder
getPersistentDataContainer
-
方法详细资料
-
hasDisplayName
boolean hasDisplayName()检查物品是否有展示名.原文: Checks for existence of a display name.
- 返回:
- 物品是否有展示名
-
getDisplayName
获取物品的展示名.插件应该在调用这个方法之前检查 hasDisplayName() 是否返回
true
.原文: Gets the display name that is set.
Plugins should check that hasDisplayName() returns
true
before calling this method.- 返回:
- 物品的展示名
-
setDisplayName
设置物品的展示名.原文: Sets the display name.
- 参数:
name
- 要设置的物品名
-
hasItemName
boolean hasItemName()Checks for existence of an item name.
Item name differs from display name in that it is cannot be edited by an anvil, is not styled with italics, and does not show labels.- 返回:
- true if this has an item name
-
getItemName
Gets the item name that is set.
Item name differs from display name in that it is cannot be edited by an anvil, is not styled with italics, and does not show labels.Plugins should check that hasItemName() returns
true
before calling this method.- 返回:
- the item name that is set
-
setItemName
Sets the item name.
Item name differs from display name in that it is cannot be edited by an anvil, is not styled with italics, and does not show labels.- 参数:
name
- the name to set
-
hasLocalizedName
已过时, 待删除: 此 API 元素将从以后的版本中删除。属性不再存在检查物品是否有本地化名称.原文: Checks for existence of a localized name.
- 返回:
- 物品是否有本地化名称
-
getLocalizedName
已过时, 待删除: 此 API 元素将从以后的版本中删除。属性不再存在获取为物品设置的本地化展示名.插件应该在调用这个方法之前检查 hasLocalizedName() 是否返回
true
.原文: Gets the localized display name that is set.
Plugins should check that hasLocalizedName() returns
true
before calling this method.- 返回:
- 物品的本地化名称
-
setLocalizedName
已过时, 待删除: 此 API 元素将从以后的版本中删除。属性不再存在设置物品的本地化名称.原文: Sets the localized name.
- 参数:
name
- 要设置的物品名
-
hasLore
boolean hasLore()检查物品是否存在 lore.原文: Checks for existence of lore.
- 返回:
- 物品是否存在 lore
-
getLore
获取物品的 lore.插件应该在调用这个方法之前检查 hasLore() 是否返回
true
.原文: Gets the lore that is set.
Plugins should check if hasLore() returns
true
before calling this method.- 返回:
- 物品的 lore 列表
-
setLore
为物品设置 lore. 当传参为 null 时移除物品的 lore.原文: Sets the lore for this item. Removes lore when given null.
- 参数:
lore
- 要设置的 lore
-
hasCustomModelData
boolean hasCustomModelData()检查物品是否存在自定义模型数据.CustomModelData 是一个整数, 可以将客户端与自定义的物品模型相关联.
原文: Checks for existence of custom model data.
CustomModelData is an integer that may be associated client side with a custom item model.
- 返回:
- 物品是否存在自定义模型数据
-
getCustomModelData
int getCustomModelData()获取物品的自定义模型数据.CustomModelData 是一个整数, 可以将客户端与自定义的物品模型相关联.
插件应该在调用这个方法之前检查 hasCustomModelData() 是否返回
true
.原文: Gets the custom model data that is set.
CustomModelData is an integer that may be associated client side with a custom item model.
Plugins should check that hasCustomModelData() returns
true
before calling this method.- 返回:
- 物品的自定义模型数据
-
setCustomModelData
设置物品的自定义模型数据.CustomModelData 是一个整数, 可以将客户端与自定义的物品模型相关联.
原文: Sets the custom model data.
CustomModelData is an integer that may be associated client side with a custom item model.
- 参数:
data
- 要设置的数据, 传递 null 以清除数据
-
hasEnchants
boolean hasEnchants()检查物品是否含有附魔.原文: Checks for the existence of any enchantments.
- 返回:
- 物品是否含有附魔
-
hasEnchant
检查物品是否存在指定的附魔.原文: Checks for existence of the specified enchantment.
- 参数:
ench
- 要检查的附魔- 返回:
- 如果此附魔存在于此物品上则返回 true
-
getEnchantLevel
获取物品上指定附魔的等级.原文: Checks for the level of the specified enchantment.
- 参数:
ench
- 要检查的附魔- 返回:
- 附魔等级, 0 代表不存在此附魔
-
getEnchants
返回此物品上的附魔的 map 副本.
如果物品没有附魔则返回空 map.原文: Returns a copy the enchantments in this ItemMeta.
Returns an empty map if none.- 返回:
- 物品所有附魔的不可变副本
-
addEnchant
为物品添加一个附魔.原文: Adds the specified enchantment to this item meta.
- 参数:
ench
- 要添加的附魔level
- 附魔等级ignoreLevelRestriction
- 是否忽略附魔的等级限制- 返回:
- 如果物品的 meta 因调用此方法而改变 (就是附魔添加成功的意思) 返回 true, false 反之
-
removeEnchant
移除物品上指定的附魔.原文: Removes the specified enchantment from this item meta.
- 参数:
ench
- 要移除的附魔- 返回:
- 移除附魔成功返回 true, false反之
-
removeEnchantments
void removeEnchantments()移除物品上的全部附魔.原文:Removes all enchantments from this item meta.
-
hasConflictingEnchant
检查指定的附魔是否与任何 ItemMeta 里的附魔冲突.原文: Checks if the specified enchantment conflicts with any enchantments in this ItemMeta.
- 参数:
ench
- 要测试的附魔- 返回:
- 有冲突的附魔返回 true, false 反之
-
addItemFlags
设置物品的 flag, 用来指定客户端渲染物品堆信息时隐藏哪些属性. 本方法会静默忽略双重设置的 itemFlags.原文: Set itemflags which should be ignored when rendering a ItemStack in the Client. This Method does silently ignore double set itemFlags.
- 参数:
itemFlags
- 希望哪些属性不显示出来
-
removeItemFlags
移除指定的一系列 itemFlags. 这将告诉客户端应再次显示被隐藏的属性. 本方法会静默忽略双重设置的 itemFlags.原文: Remove specific set of itemFlags. This tells the Client it should render it again. This Method does silently ignore double removed itemFlags.
- 参数:
itemFlags
- 要移除的属性隐藏标志
-
getItemFlags
获取当前设置的 itemFlags. 返回的集合是不可变的.原文: Get current set itemFlags. The collection returned is unmodifiable.
- 返回:
- 当前设置的 itemFlags 的集合
-
hasItemFlag
检查物品是否存在指定的 flag.原文: Check if the specified flag is present on this item.
- 参数:
flag
- 要检查的 flag- 返回:
- 是否存在指定的 flag
-
isHideTooltip
boolean isHideTooltip()Gets if this item has hide_tooltip set. An item with this set will not show any tooltip whatsoever.- 返回:
- hide_tooltip
-
setHideTooltip
void setHideTooltip(boolean hideTooltip) Sets if this item has hide_tooltip set. An item with this set will not show any tooltip whatsoever.- 参数:
hideTooltip
- new hide_tooltip
-
isUnbreakable
boolean isUnbreakable()返回物品的 unbreakable 标签是否为 true. 一个牢不可破的物品不会丧失耐久度.原文: Return if the unbreakable tag is true. An unbreakable item will not lose durability.
- 返回:
- 物品的 unbreakable 标签是否为 true
-
setUnbreakable
void setUnbreakable(boolean unbreakable) 设置物品的 unbreakable 标签是否为 true. 一个牢不可破的物品不会丧失耐久度.原文: Sets the unbreakable tag. An unbreakable item will not lose durability.
- 参数:
unbreakable
- 要使物品牢不可破则设为 true
-
hasEnchantmentGlintOverride
boolean hasEnchantmentGlintOverride()Gets if an enchantment_glint_override is set.- 返回:
- if an enchantment_glint_override is set
-
getEnchantmentGlintOverride
Sets the enchantment_glint_override. If true, the item will glint, even without enchantments; if false, the item will not glint, even with enchantments. Plugins should checkhasEnchantmentGlintOverride()
before calling this method.- 返回:
- enchantment_glint_override
-
setEnchantmentGlintOverride
Sets the enchantment_glint_override. If true, the item will glint, even without enchantments; if false, the item will not glint, even with enchantments. If null, the override will be cleared.- 参数:
override
- new enchantment_glint_override
-
isFireResistant
boolean isFireResistant()Checks if this item is fire_resistant. If true, it will not burn in fire or lava.- 返回:
- fire_resistant
-
setFireResistant
void setFireResistant(boolean fireResistant) Sets if this item is fire_resistant. If true, it will not burn in fire or lava.- 参数:
fireResistant
- fire_resistant
-
hasMaxStackSize
boolean hasMaxStackSize()Gets if the max_stack_size is set.- 返回:
- if a max_stack_size is set.
-
getMaxStackSize
int getMaxStackSize()Gets the max_stack_size. This is the maximum amount which an item will stack.- 返回:
- max_stack_size
-
setMaxStackSize
Sets the max_stack_size. This is the maximum amount which an item will stack.- 参数:
max
- max_stack_size, between 1 and 99 (inclusive)
-
hasRarity
boolean hasRarity()Gets if the rarity is set.- 返回:
- rarity
-
getRarity
Gets the item rarity. Plugins should checkhasRarity()
before calling this method.- 返回:
- rarity
-
setRarity
Sets the item rarity.- 参数:
rarity
- new rarity
-
hasFood
boolean hasFood()Checks if the food is set.- 返回:
- if a food is set
-
getFood
Gets the food set on this item, or creates an empty food instance.The returned component is a snapshot of its current state and does not reflect a live view of what is on an item. After changing any value on this component, it must be set with
setFood(FoodComponent)
to apply the changes.- 返回:
- food
-
setFood
Sets the item food.- 参数:
food
- new food
-
hasTool
boolean hasTool()Checks if the tool is set.- 返回:
- if a tool is set
-
getTool
Gets the tool set on this item, or creates an empty tool instance.The returned component is a snapshot of its current state and does not reflect a live view of what is on an item. After changing any value on this component, it must be set with
setTool(ToolComponent)
to apply the changes.- 返回:
- tool
-
setTool
Sets the item tool.- 参数:
tool
- new tool
-
hasJukeboxPlayable
boolean hasJukeboxPlayable()Checks if the jukebox playable is set.- 返回:
- if a jukebox playable is set
-
getJukeboxPlayable
Gets the jukebox playable component set on this item.The returned component is a snapshot of its current state and does not reflect a live view of what is on an item. After changing any value on this component, it must be set with
setJukeboxPlayable(org.bukkit.inventory.meta.components.JukeboxComponent)
to apply the changes.- 返回:
- component
-
setJukeboxPlayable
Sets the item tool.- 参数:
jukeboxPlayable
- new component
-
hasAttributeModifiers
boolean hasAttributeModifiers()检查物品是否存在任何属性修饰符.原文: Checks for the existence of any AttributeModifiers.
- 返回:
- 物品存在属性修饰符则返回 true
-
getAttributeModifiers
返回所有属性及其修饰符的不可变副本.
如果不存在则返回 null.原文: Return an immutable copy of all Attributes and their modifiers in this ItemMeta.
Returns null if none exist.- 返回:
- 所有属性及其修饰符的不可变
Multimap
, null 代表不存在修饰符
-
getAttributeModifiers
@NotNull @NotNull Multimap<Attribute,AttributeModifier> getAttributeModifiers(@NotNull @NotNull EquipmentSlot slot) 返回指定EquipmentSlot
的所有属性及其修饰符的不可变列表. 设置了给定EquipmentSlot
的任何AttributeModifier
都将会返回. 这是因为未指定槽位的修饰符可在任意槽位中生效.
如果未给指定槽位设置任何属性, 将返回一个空 map.原文: Return an immutable copy of all
Attribute
s and theirAttributeModifier
s for a givenEquipmentSlot
.
AnyAttributeModifier
that does have have a givenEquipmentSlot
will be returned. This is because AttributeModifiers without a slot are active in any slot.
If there are no attributes set for the given slot, an empty map will be returned.- 参数:
slot
- 要检查的EquipmentSlot
- 返回:
- the immutable
Multimap
with the respective Attributes and modifiers, or an empty map if no attributes are set.
-
getAttributeModifiers
@Nullable @Nullable Collection<AttributeModifier> getAttributeModifiers(@NotNull @NotNull Attribute attribute) - 参数:
attribute
-属性
- 返回:
- 包含所有
修饰符
的不可变集合, 如果指定属性不存在修饰符则返回 null - 抛出:
NullPointerException
- 若 Attribute 为 null
-
addAttributeModifier
boolean addAttributeModifier(@NotNull @NotNull Attribute attribute, @NotNull @NotNull AttributeModifier modifier) 添加一个属性和它的修饰符. 属性修饰符现支持设置EquipmentSlot
. 如果没有设置, 则属性修饰符
将在所有槽位中生效.
拥有相同UUID
的两个AttributeModifier
不可同时存在于同一个属性上.原文: Add an Attribute and it's Modifier. AttributeModifiers can now support
EquipmentSlot
s. If not set, theAttributeModifier
will be active in ALL slots.
TwoAttributeModifier
s that have the sameUUID
cannot exist on the same Attribute.- 参数:
attribute
- 要修改的属性
modifier
- 属性的修饰符
- 返回:
- 如果属性及其修饰符成功添加返回 true
- 抛出:
NullPointerException
- 若 Attribute 为 nullNullPointerException
- 若 AttributeModifier 为 nullIllegalArgumentException
- 若 AttributeModifier 已存在于已设置的某一属性上
-
setAttributeModifiers
void setAttributeModifiers(@Nullable @Nullable Multimap<Attribute, AttributeModifier> attributeModifiers) 设置所有属性
和它们的属性修饰符
. 要移除所有已设置的属性和属性修饰符, 可以指定参数为 null 或空的 Multimap. 若参数既不为 null 也不为空 map, 本方法将筛选出非空的键值对并添加给物品堆.译注: 本方法会清空原有的属性, 添加请用 add 开头的相关方法.
原文: Set all
Attribute
s and theirAttributeModifier
s. To clear all currently set Attributes and AttributeModifiers use null or an empty Multimap. If not null nor empty, this will filter all entries that are not-null and add them to the ItemStack.- 参数:
attributeModifiers
- 包含属性和它们的属性修饰符的新 Multimap
-
removeAttributeModifier
移除与给定属性
有关的所有属性修饰符
. 如果没有移除任何东西将会返回 false.原文: Remove all
AttributeModifier
s associated with the givenAttribute
. This will return false if nothing was removed.- 参数:
attribute
- 要移除的属性- 返回:
- 与此属性有关的所有修饰符均被移除则返回 true, 没有移除任何修饰符则返回 false
- 抛出:
NullPointerException
- 如果 Attribute 为 null
-
removeAttributeModifier
为指定的EquipmentSlot
移除其所有的属性
和属性修饰符
.
如果给定的EquipmentSlot
为 null, 这将移除所有没有设置EquipmentSlot
的AttributeModifier
.原文: Remove all
Attribute
s andAttributeModifier
s for a givenEquipmentSlot
.
If the givenEquipmentSlot
is null, this will remove allAttributeModifier
s that do not have an EquipmentSlot set.- 参数:
slot
- 要操作的EquipmentSlot
- 返回:
- 如果与给定 EquipmentSlot 匹配的所有修饰符被移除则返回true.
-
removeAttributeModifier
boolean removeAttributeModifier(@NotNull @NotNull Attribute attribute, @NotNull @NotNull AttributeModifier modifier) 移除一个指定的属性
和属性修饰符
. 将根据它们的UUID
匹配属性修饰符.原文: Remove a specific
Attribute
andAttributeModifier
. AttributeModifiers are matched according to theirUUID
.- 参数:
attribute
- 要移除的属性
modifier
- 要移除的属性修饰符
- 返回:
- 如果删除了任何属性修饰符
- 抛出:
NullPointerException
- 若 Attribute 为 nullNullPointerException
- 若 AttributeModifier 为 null- 另请参阅:
-
getAsString
Get this ItemMeta as an NBT string. If this ItemMeta does not have any NBT, then"{}"
will be returned.This string should NEVER be relied upon as a serializable value. If serialization is desired, the
ConfigurationSerializable
API should be used instead.- 返回:
- the NBT string
-
getAsComponentString
Get this ItemMeta as a component-compliant string. If this ItemMeta does not contain any components, then"[]"
will be returned.The result of this method should yield a string representing the components altered by this ItemMeta instance. When passed to
ItemFactory.createItemStack(String)
with a prepended item type, it will create an ItemStack that has an ItemMeta matching this ItemMeta instance exactly. Note that this method returns ONLY the components and cannot be passed to createItemStack() alone. An example may look something like this:ItemStack itemStack = // ... an item stack obtained from somewhere ItemMeta itemMeta = itemStack.getItemMeta(); String components = itemMeta.getAsComponentString(); // example: "[minecraft:damage=53]" String itemTypeKey = itemStack.getType().getKey().toString(); // example: "minecraft:diamond_sword" String itemAsString = itemTypeKey + components; // results in: "minecraft:diamond_sword[minecraft:damage=53]" ItemStack recreatedItemStack = Bukkit.getItemFactory().createItemStack(itemAsString); assert itemStack.isSimilar(recreatedItemStack); // Should be true*
*Components not represented or explicitly overridden by this ItemMeta instance will not be included in the resulting string and therefore may result in ItemStacks that do not match exactly. For example, if
setDisplayName(String)
is not set, then the custom name component will not be included. Or if this ItemMeta is a PotionMeta, it will not include any components related to lodestone compasses, banners, or books, etc., only components modifiable by a PotionMeta instance.This string should NEVER be relied upon as a serializable value. If serialization is desired, the
ConfigurationSerializable
API should be used instead.- 返回:
- the component-compliant string
-
getCustomTagContainer
已过时。该 API 已被PersistentDataHolder
API 取代. 请使用PersistentDataHolder.getPersistentDataContainer()
.返回一个公共的自定义标签容器, 其能够在物品上存储标签. 那些标签及其所有内容都会被发送到客户端, 因此客户端能够读取它们. 这将导致玩家可以看到物品上有 NBT 标签的提醒. 一旦客户端处于创造模式, 这些标签也可被客户端修改.原文: Returns a public custom tag container capable of storing tags on the item. Those tags will be sent to the client with all of their content, so the client is capable of reading them. This will result in the player seeing a NBT Tag notification on the item. These tags can also be modified by the client once in creative mode
- 返回:
- 自定义的标签容器
-
setVersion
仅供内部使用! (插件)请勿在任何情况下使用!原文: Internal use only! Do not use under any circumstances!
- 参数:
version
- meta的版本
-
clone
-
PersistentDataHolder
API 取代.