接口 ItemMeta
- 所有已知子接口:
ArmorMeta
,AxolotlBucketMeta
,BannerMeta
,BlockDataMeta
,BlockStateMeta
,BookMeta
,BundleMeta
,ColorableArmorMeta
,CompassMeta
,CrossbowMeta
,Damageable
,EnchantmentStorageMeta
,FireworkEffectMeta
,FireworkMeta
,KnowledgeBookMeta
,LeatherArmorMeta
,MapMeta
,MusicInstrumentMeta
,PotionMeta
,Repairable
,SkullMeta
,SpawnEggMeta
,SuspiciousStewMeta
,TropicalFishBucketMeta
接口的实现会处理 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 an NBT string.返回所有属性及其修饰符的不可变副本.
如果不存在则返回 null.getAttributeModifiers
(@NotNull Attribute attribute) 返回指定EquipmentSlot
的所有属性及其修饰符的不可变列表.int
获取物品的自定义模型数据.已过时。获取物品的展示名.int
获取物品上指定附魔的等级.返回此物品上的附魔的 map 副本.
如果物品没有附魔则返回空 map.获取当前设置的 itemFlags.获取为物品设置的本地化展示名.getLore()
获取物品的 lore.boolean
检查物品是否存在任何属性修饰符.boolean
检查指定的附魔是否与任何 ItemMeta 里的附魔冲突.boolean
检查物品是否存在自定义模型数据.boolean
检查物品是否有展示名.boolean
hasEnchant
(@NotNull Enchantment ench) 检查物品是否存在指定的附魔.boolean
检查物品是否含有附魔.boolean
hasItemFlag
(@NotNull ItemFlag flag) 检查物品是否存在指定的 flag.boolean
检查物品是否有本地化名称.boolean
hasLore()
检查物品是否存在 lore.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
removeItemFlags
(@NotNull ItemFlag... itemFlags) 移除指定的一系列 itemFlags.void
setAttributeModifiers
(@Nullable Multimap<Attribute, AttributeModifier> attributeModifiers) void
设置物品的自定义模型数据.void
setDisplayName
(@Nullable String name) 设置物品的展示名.void
setLocalizedName
(@Nullable String name) 设置物品的本地化名称.void
为物品设置 lore.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
- 要设置的物品名
-
hasLocalizedName
boolean hasLocalizedName()检查物品是否有本地化名称.原文: Checks for existence of a localized name.
- 返回:
- 物品是否有本地化名称
-
getLocalizedName
获取为物品设置的本地化展示名.插件应该在调用这个方法之前检查 hasLocalizedName() 是否返回
true
.原文: Gets the localized display name that is set.
Plugins should check that hasLocalizedName() returns
true
before calling this method.- 返回:
- 物品的本地化名称
-
setLocalizedName
设置物品的本地化名称.原文: 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反之
-
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
-
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
-
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.This string should not be relied upon as a serializable value. If serialization is desired, the
ConfigurationSerializable
API should be used instead.- 返回:
- the NBT 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 取代.