接口 ItemMeta
- 所有已知子接口:
ArmorMeta,AxolotlBucketMeta,BannerMeta,BlockDataMeta,BlockStateMeta,BookMeta,BundleMeta,ColorableArmorMeta,CompassMeta,CrossbowMeta,Damageable,EnchantmentStorageMeta,FireworkEffectMeta,FireworkMeta,KnowledgeBookMeta,LeatherArmorMeta,MapMeta,MusicInstrumentMeta,OminousBottleMeta,PotionMeta,Repairable,ShieldMeta,SkullMeta,SpawnEggMeta,SuspiciousStewMeta,TropicalFishBucketMeta,WritableBookMeta
接口的实现会处理 ItemMeta 的创建和应用. 本类不应由实时环境中的插件实现.
-
方法概要
修饰符和类型方法说明booleanaddAttributeModifier(@NotNull Attribute attribute, @NotNull AttributeModifier modifier) 添加一个属性和它的修饰符.booleanaddEnchant(@NotNull Enchantment ench, int level, boolean ignoreLevelRestriction) 为物品添加一个附魔.voidaddItemFlags(@NotNull ItemFlag... itemFlags) 设置物品的 flag, 用来指定客户端渲染物品堆信息时隐藏哪些属性.clone()将此 ItemMeta 转换为组件兼容的字符串.将此 ItemMeta 转换为 NBT 字符串.返回所有属性及其修饰符的不可变副本.
如果不存在则返回 null.getAttributeModifiers(@NotNull Attribute attribute) 返回指定EquipmentSlot的所有属性及其修饰符的不可变列表.获取此物品上设置的格挡攻击组件, 或创建一个空的格挡攻击组件实例.获取当物品损坏时播放的音效.获取此物品上设置的消耗品组件, 或创建一个空的消耗品实例.int已过时。获取此物品上设置的自定义模型数据组件, 或创建一个空的自定义模型数据实例.已过时。该 API 已被PersistentDataHolderAPI 取代.获取当此物品以实体形式存在时, 其对何种伤害类型具有抗性.获取物品的展示名.int获取可附魔性组件.int获取物品上指定附魔的等级.获取附魔光效覆盖。返回此物品上的附魔的 map 副本.
如果物品没有附魔则返回空 map.获取此物品上设置的可装备组件, 或创建一个空的可装备实例.getFood()获取此物品上设置的食物组件, 或创建一个空的食物实例.获取当前设置的 itemFlags.获取自定义的物品模型.获取已设置的物品名称。获取此物品上设置的唱片机可播放组件.已过时, 待删除: 此 API 元素将从以后的版本中删除。属性不再存在getLore()获取物品的 lore.int获取最大堆叠数量.获取物品的稀有度.getTool()获取此物品上设置的工具组件, 或创建一个空的工具实例.获取自定义的工具提示样式.获取此物品上设置的使用冷却组件, 或创建一个空的使用冷却实例.获取当此物品被使用后, 其将转换为何种物品.获取此物品上设置的武器组件, 或创建一个空的武器实例.boolean检查物品是否存在任何属性修饰符.boolean检查是否设置了格挡攻击组件.boolean获取是否设置了损坏音效.boolean检查指定的附魔是否与任何 ItemMeta 里的附魔冲突.boolean检查是否设置了消耗品组件.boolean已过时。more complex custom model data can be specified withhasCustomModelDataComponent().boolean检查是否设置了自定义模型数据组件.boolean获取此物品是否对特定类型的伤害有抗性.boolean检查物品是否有展示名.booleanhasEnchant(@NotNull Enchantment ench) 检查物品是否存在指定的附魔.boolean获取是否设置了可附魔性组件.boolean获取是否设置了附魔光效覆盖.boolean检查物品是否含有附魔.boolean检查是否设置了可装备组件.booleanhasFood()检查是否设置了食物组件.booleanhasItemFlag(@NotNull ItemFlag flag) 检查物品是否存在指定的 flag.boolean获取此物品是否拥有自定义的物品模型.boolean检查是否存在物品名称。boolean检查是否设置了唱片机可播放组件.boolean已过时, 待删除: 此 API 元素将从以后的版本中删除。属性不再存在booleanhasLore()检查物品是否存在 lore.boolean获取是否设置了最大堆叠数量.boolean获取是否设置了稀有度.booleanhasTool()检查是否设置了工具组件.boolean获取此物品是否拥有自定义的工具提示样式.boolean检查是否设置了使用冷却.boolean检查是否设置了使用后残留物.boolean检查是否设置了武器组件.boolean已过时。booleanisGlider()检查此物品是否为滑翔装备.boolean获取此物品是否设置了隐藏工具提示.boolean返回物品的 unbreakable 标签是否为 true.booleanremoveAttributeModifier(@NotNull Attribute attribute) booleanremoveAttributeModifier(@NotNull Attribute attribute, @NotNull AttributeModifier modifier) boolean为指定的EquipmentSlot移除其所有的属性和属性修饰符.
如果给定的EquipmentSlot为 null, 这将移除所有没有设置EquipmentSlot的AttributeModifier.booleanremoveEnchant(@NotNull Enchantment ench) 移除物品上指定的附魔.void移除物品上的全部附魔.voidremoveItemFlags(@NotNull ItemFlag... itemFlags) 移除指定的一系列 itemFlags.voidsetAttributeModifiers(@Nullable Multimap<Attribute, AttributeModifier> attributeModifiers) voidsetBlocksAttacks(@Nullable BlocksAttacksComponent blocksAttacks) 设置物品的格挡攻击组件.voidsetBreakSound(@Nullable Sound sound) 设置当物品损坏时播放的音效.voidsetConsumable(@Nullable ConsumableComponent consumable) 设置物品的消耗品组件.void已过时。more complex custom model data can be specified withsetCustomModelDataComponent(org.bukkit.inventory.meta.components.CustomModelDataComponent).voidsetCustomModelDataComponent(@Nullable CustomModelDataComponent customModelData) 设置自定义模型数据组件.void设置当此物品以实体形式存在时, 其对何种伤害类型具有抗性.voidsetDisplayName(@Nullable String name) 设置物品的展示名.voidsetEnchantable(@Nullable Integer enchantable) 设置可附魔性组件.voidsetEnchantmentGlintOverride(@Nullable Boolean override) 设置附魔光效覆盖。voidsetEquippable(@Nullable EquippableComponent equippable) 设置物品的可装备组件.voidsetFireResistant(boolean fireResistant) voidsetFood(@Nullable FoodComponent food) 设置物品的食物组件.voidsetGlider(boolean glider) 设置此物品是否为滑翔装备.voidsetHideTooltip(boolean hideTooltip) 设置此物品是否启用隐藏工具提示.voidsetItemModel(@Nullable NamespacedKey itemModel) 设置自定义的物品模型.voidsetItemName(@Nullable String name) 设置物品名称。voidsetJukeboxPlayable(@Nullable JukeboxPlayableComponent jukeboxPlayable) 设置物品的唱片机可播放组件.voidsetLocalizedName(@Nullable String name) 已过时, 待删除: 此 API 元素将从以后的版本中删除。属性不再存在void为物品设置 lore.void设置最大堆叠数量.voidsetRarity(@Nullable ItemRarity rarity) 设置物品的稀有度.voidsetTool(@Nullable ToolComponent tool) 设置物品的工具组件.voidsetTooltipStyle(@Nullable NamespacedKey tooltipStyle) 设置自定义工具提示样式。voidsetUnbreakable(boolean unbreakable) 设置物品的 unbreakable 标签是否为 true.voidsetUseCooldown(@Nullable UseCooldownComponent cooldown) 设置物品的使用冷却组件.voidsetUseRemainder(@Nullable ItemStack remainder) 设置当此物品被使用后, 其将转换为何种物品.voidsetVersion(int version) 仅供内部使用!voidsetWeapon(@Nullable WeaponComponent weapon) 设置物品的武器组件.从接口继承的方法 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
truebefore 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
-
getItemName
获取已设置的物品名称。
物品名称与显示名称的区别在于:它无法通过铁砧编辑、不会以斜体样式显示,且不展示标签文本。插件在调用此方法前应确保 hasItemName() 返回
true。原文: 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
truebefore calling this method.- 返回:
- 已设置的物品名称
-
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- 要设置的名称
-
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
truebefore 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
truebefore calling this method.- 返回:
- 物品的 lore 列表
-
setLore
为物品设置 lore. 当传参为 null 时移除物品的 lore.原文: Sets the lore for this item. Removes lore when given null.
- 参数:
lore- 要设置的 lore
-
hasCustomModelData
已过时。more complex custom model data can be specified withhasCustomModelDataComponent(). Integers from the old custom model data are equivalent to a single float in theCustomModelDataComponent.getFloats()list.检查物品是否存在自定义模型数据.CustomModelData 是一个整数, 可以将客户端与自定义的物品模型相关联.
原文: Checks for existence of custom model data.
CustomModelData is an integer that may be associated client side with a custom item model.
- 返回:
- 物品是否存在自定义模型数据
-
getCustomModelData
已过时。more complex custom model data can be specified withgetCustomModelDataComponent(). Integers from the old custom model data are equivalent to a single float in theCustomModelDataComponent.getFloats()list.获取物品的自定义模型数据.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
truebefore calling this method.- 返回:
- 物品的自定义模型数据
-
getCustomModelDataComponent
获取此物品上设置的自定义模型数据组件, 或创建一个空的自定义模型数据实例.返回的组件是其当前状态的快照, 不反映物品上数据的实时视图. 更改此组件上的任何值后, 必须使用
setCustomModelDataComponent(CustomModelDataComponent)来应用更改.原文: Gets the custom model data set on this item, or creates an empty custom model data 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
setCustomModelDataComponent(CustomModelDataComponent)to apply the changes.- 返回:
- 自定义模型数据组件
-
setCustomModelData
已过时。more complex custom model data can be specified withsetCustomModelDataComponent(org.bukkit.inventory.meta.components.CustomModelDataComponent). Integers from the old custom model data are equivalent to a single float in theCustomModelDataComponent.setFloats(java.util.List)list.设置物品的自定义模型数据.CustomModelData 是一个整数, 可以将客户端与自定义的物品模型相关联.
原文: Sets the custom model data.
CustomModelData is an integer that may be associated client side with a custom item model.
- 参数:
data- 要设置的数据, 传递 null 以清除数据
-
hasCustomModelDataComponent
boolean hasCustomModelDataComponent()检查是否设置了自定义模型数据组件.原文: Checks if the custom model data component is set.
- 返回:
- 如果设置了自定义模型数据组件则返回 true
-
setCustomModelDataComponent
设置自定义模型数据组件.原文: Sets the custom model data component.
- 参数:
customModelData- 新的自定义模型数据组件
-
hasEnchantable
boolean hasEnchantable()获取是否设置了可附魔性组件.原文: Gets if the enchantable component is set.
- 返回:
- 如果设置了可附魔性组件则返回 true
-
getEnchantable
int getEnchantable()获取可附魔性组件. 数值越高, 允许的附魔等级也越高.原文: Gets the enchantable component. Higher values allow higher enchantments.
- 返回:
- 可附魔性等级
-
setEnchantable
设置可附魔性组件. 数值越高, 允许的附魔等级也越高.原文: Sets the enchantable. Higher values allow higher enchantments.
- 参数:
enchantable- 可附魔性等级
-
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.
- 返回:
- 是否隐藏工具提示
-
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- 是否隐藏工具提示
-
hasTooltipStyle
boolean hasTooltipStyle()获取此物品是否拥有自定义的工具提示样式.原文: Gets if this item has a custom tooltip style.
- 返回:
- 如果设置了工具提示样式则返回 true
-
getTooltipStyle
获取自定义的工具提示样式.原文: Gets the custom tooltip style.
- 返回:
- 工具提示样式对应的命名空间键, 如果未设置则返回 null
-
setTooltipStyle
设置自定义工具提示样式。- 参数:
tooltipStyle- 新的样式原文: Sets the custom tooltip style.
-
hasItemModel
boolean hasItemModel()获取此物品是否拥有自定义的物品模型.原文: Gets if this item has a custom item model.
- 返回:
- 如果设置了自定义物品模型则返回 true
-
getItemModel
获取自定义的物品模型.原文: Gets the custom item model.
- 返回:
- 物品模型对应的命名空间键, 如果未设置则返回 null
-
setItemModel
设置自定义的物品模型.原文: Sets the custom item model.
- 参数:
itemModel- 新的物品模型对应的命名空间键
-
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.
- 返回:
- 如果设置了附魔光效覆盖则返回 true
-
getEnchantmentGlintOverride
获取附魔光效覆盖。若为true,物品将始终显示光效(即使无附魔); 若为false,物品将始终不显示光效(即使有附魔)。 插件在调用此方法前应检查hasEnchantmentGlintOverride()。原文: 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 check
hasEnchantmentGlintOverride()before calling this method.- 返回:
- 新的附魔光效覆盖值
-
setEnchantmentGlintOverride
设置附魔光效覆盖。若为true,物品将始终显示光效(即使无附魔); 若为false,物品将始终不显示光效(即使有附魔);若为null,则清除覆盖设置。原文: 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- 新的附魔光效覆盖值
-
isGlider
boolean isGlider()检查此物品是否为滑翔装备. 如果是, 当玩家装备此物品时将被允许滑翔.原文: Checks if this item is a glider. If true, this item will allow players to glide when it is equipped.
- 返回:
- 此物品是否为滑翔装备
-
setGlider
void setGlider(boolean glider) 设置此物品是否为滑翔装备. 如果是, 当玩家装备此物品时将被允许滑翔.原文: Sets if this item is a glider. If true, this item will allow players to glide when it is equipped.
- 参数:
glider- 是否设置为滑翔装备
-
isFireResistant
已过时。检查此物品是否耐火. 如果为 true, 它将在火或熔岩中不会燃烧.原文: Checks if this item is fire_resistant. If true, it will not burn in fire or lava.
- 返回:
- 此物品是否耐火
-
setFireResistant
设置此物品是否耐火. 如果为 true, 它将在火或熔岩中不会燃烧.原文: Sets if this item is fire_resistant. If true, it will not burn in fire or lava.
- 参数:
fireResistant- 是否设置为耐火
-
hasDamageResistant
boolean hasDamageResistant()获取此物品是否对特定类型的伤害有抗性.原文: Gets if this item is resistant to certain types of damage.
- 返回:
- 如果设置了伤害抗性则返回 true
-
getDamageResistant
获取当此物品以实体形式存在时, 其对何种伤害类型具有抗性.插件在调用此方法前应检查
hasDamageResistant()是否返回 true.原文: Gets the type of damage this item will be resistant to when in entity form.
Plugins should check
hasDamageResistant()before calling this method.- 返回:
- 伤害类型标签, 如果未设置则返回 null
-
setDamageResistant
设置当此物品以实体形式存在时, 其对何种伤害类型具有抗性.原文: Sets the type of damage this item will be resistant to when in entity form.
- 参数:
tag- 伤害类型标签, 设置为 null 以清除
-
hasMaxStackSize
boolean hasMaxStackSize()获取是否设置了最大堆叠数量.原文: Gets if the max_stack_size is set.
- 返回:
- 如果设置了最大堆叠数量则返回 true
-
getMaxStackSize
int getMaxStackSize()获取最大堆叠数量. 这是物品可以堆叠的最大数量.原文: Gets the max_stack_size. This is the maximum amount which an item will stack.
- 返回:
- 最大堆叠数量
-
setMaxStackSize
设置最大堆叠数量. 这是物品可以堆叠的最大数量.原文: Sets the max_stack_size. This is the maximum amount which an item will stack.
- 参数:
max- 最大堆叠数量, 必须在 1 到 99 之间(包含边界)
-
hasRarity
boolean hasRarity()获取是否设置了稀有度.原文: Gets if the rarity is set.
- 返回:
- 如果设置了稀有度则返回 true
-
getRarity
获取物品的稀有度.插件在调用此方法前应检查
hasRarity()是否返回 true.原文: Gets the item rarity.
Plugins should check
hasRarity()before calling this method.- 返回:
- 物品稀有度
-
setRarity
设置物品的稀有度.原文: Sets the item rarity.
- 参数:
rarity- 新的物品稀有度
-
hasUseRemainder
boolean hasUseRemainder()检查是否设置了使用后残留物.原文: Checks if the use remainder is set.
- 返回:
- 如果设置了使用后残留物则返回 true
-
getUseRemainder
获取当此物品被使用后, 其将转换为何种物品.返回的组件是其当前状态的快照, 不反映物品上数据的实时视图. 更改此组件上的任何值后, 必须使用
setUseRemainder(ItemStack)来应用更改.原文: Gets the item which this item will convert to when used.
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
setUseRemainder(ItemStack)to apply the changes.- 返回:
- 使用后生成的物品堆栈, 如果未设置则返回 null
-
setUseRemainder
设置当此物品被使用后, 其将转换为何种物品.原文: Sets the item which this item will convert to when used.
- 参数:
remainder- 新的使用后生成的物品堆栈
-
hasUseCooldown
boolean hasUseCooldown()检查是否设置了使用冷却.原文: Checks if the use cooldown is set.
- 返回:
- 如果设置了使用冷却则返回 true
-
getUseCooldown
获取此物品上设置的使用冷却组件, 或创建一个空的使用冷却实例.返回的组件是其当前状态的快照, 不反映物品上数据的实时视图. 更改此组件上的任何值后, 必须使用
setUseCooldown(UseCooldownComponent)来应用更改.原文: Gets the use cooldown set on this item, or creates an empty cooldown 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
setUseCooldown(UseCooldownComponent)to apply the changes.- 返回:
- 使用冷却组件
-
setUseCooldown
设置物品的使用冷却组件.原文: Sets the item use cooldown.
- 参数:
cooldown- 新的使用冷却组件
-
hasFood
boolean hasFood()检查是否设置了食物组件.原文: Checks if the food is set.
- 返回:
- 如果设置了食物组件则返回 true
-
getFood
获取此物品上设置的食物组件, 或创建一个空的食物实例.返回的组件是其当前状态的快照, 不反映物品上数据的实时视图. 更改此组件上的任何值后, 必须使用
setFood(FoodComponent)来应用更改.原文: 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.- 返回:
- 食物组件
-
setFood
设置物品的食物组件.原文: Sets the item food.
- 参数:
food- 新的食物组件
-
hasConsumable
boolean hasConsumable()检查是否设置了消耗品组件.原文: Checks if the consumable is set.
- 返回:
- 如果设置了消耗品组件则返回 true
-
getConsumable
获取此物品上设置的消耗品组件, 或创建一个空的消耗品实例.返回的组件是其当前状态的快照, 不反映物品上数据的实时视图. 更改此组件上的任何值后, 必须使用
setConsumable(ConsumableComponent)来应用更改.原文: Gets the consumable set on this item, or creates an empty consumable 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
setConsumable(ConsumableComponent)to apply the changes.- 返回:
- 消耗品组件
-
setConsumable
设置物品的消耗品组件.原文: Sets the item consumable.
- 参数:
consumable- 新的消耗品组件
-
hasTool
boolean hasTool()检查是否设置了工具组件.原文: Checks if the tool is set.
- 返回:
- 如果设置了工具组件则返回 true
-
getTool
获取此物品上设置的工具组件, 或创建一个空的工具实例.返回的组件是其当前状态的快照, 不反映物品上数据的实时视图. 更改此组件上的任何值后, 必须使用
setTool(ToolComponent)来应用更改.原文: 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.- 返回:
- 工具组件
-
setTool
设置物品的工具组件.原文: Sets the item tool.
- 参数:
tool- 新的工具组件
-
hasWeapon
boolean hasWeapon()检查是否设置了武器组件.原文: Checks if the weapon is set.
- 返回:
- 如果设置了武器组件则返回 true
-
getWeapon
获取此物品上设置的武器组件, 或创建一个空的武器实例.返回的组件是其当前状态的快照, 不反映物品上数据的实时视图. 更改此组件上的任何值后, 必须使用
setWeapon(WeaponComponent)来应用更改.原文: Gets the weapon set on this item, or creates an empty weapon 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
setWeapon(WeaponComponent)to apply the changes.- 返回:
- 武器组件
-
setWeapon
设置物品的武器组件.原文: Sets the item weapon.
- 参数:
weapon- 新的武器组件
-
hasBlocksAttacks
boolean hasBlocksAttacks()检查是否设置了格挡攻击组件.原文: Checks if the
BlocksAttacksComponentis set.- 返回:
- 如果设置了格挡攻击组件则返回 true
-
getBlocksAttacks
获取此物品上设置的格挡攻击组件, 或创建一个空的格挡攻击组件实例.返回的组件是其当前状态的快照, 不反映物品上数据的实时视图. 更改此组件上的任何值后, 必须使用
setBlocksAttacks(BlocksAttacksComponent)来应用更改.原文: Gets the
BlocksAttacksComponentset on this item, or creates an emptyBlocksAttacksComponentinstance.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
setBlocksAttacks(BlocksAttacksComponent)to apply the changes.- 返回:
- 格挡攻击组件
-
setBlocksAttacks
设置物品的格挡攻击组件.原文: Sets the item
BlocksAttacksComponent.- 参数:
blocksAttacks- 新的格挡攻击组件
-
hasEquippable
boolean hasEquippable()检查是否设置了可装备组件.原文: Checks if the equippable is set.
- 返回:
- 如果设置了可装备组件则返回 true
-
getEquippable
获取此物品上设置的可装备组件, 或创建一个空的可装备实例.返回的组件是其当前状态的快照, 不反映物品上数据的实时视图. 更改此组件上的任何值后, 必须使用
setEquippable(EquippableComponent)来应用更改.原文: Gets the equippable set on this item, or creates an empty equippable 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
setEquippable(EquippableComponent)to apply the changes.- 返回:
- 可装备组件
-
setEquippable
设置物品的可装备组件.原文: Sets the equippable tool.
- 参数:
equippable- 新的可装备组件
-
hasJukeboxPlayable
boolean hasJukeboxPlayable()检查是否设置了唱片机可播放组件.原文: Checks if the jukebox playable is set.
- 返回:
- 如果设置了唱片机可播放组件则返回 true
-
getJukeboxPlayable
获取此物品上设置的唱片机可播放组件.返回的组件是其当前状态的快照, 不反映物品上数据的实时视图. 更改此组件上的任何值后, 必须使用
setJukeboxPlayable(org.bukkit.inventory.meta.components.JukeboxComponent)来应用更改.原文: 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.- 返回:
- 唱片机可播放组件, 如果未设置则返回 null
-
setJukeboxPlayable
设置物品的唱片机可播放组件.原文: Sets the item tool.
- 参数:
jukeboxPlayable- 新的唱片机可播放组件
-
hasBreakSound
boolean hasBreakSound()获取是否设置了损坏音效.原文: Gets if the break sound is set.
- 返回:
- 如果设置了损坏音效则返回 true
-
getBreakSound
获取当物品损坏时播放的音效.插件在调用此方法前应检查
hasBreakSound()是否返回 true.原文: Gets the sound to play when the item is broken.
Plugins should check
hasBreakSound()before calling this method.- 返回:
- 损坏时播放的音效, 如果未设置则返回 null
-
setBreakSound
设置当物品损坏时播放的音效.原文: Sets the sound to play when the item is broken.
- 参数:
sound- 损坏时播放的音效
-
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
Attributes and theirAttributeModifiers for a givenEquipmentSlot.
AnyAttributeModifierthat does have have a givenEquipmentSlotwill 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
Multimapwith 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
EquipmentSlots. If not set, theAttributeModifierwill be active in ALL slots.
TwoAttributeModifiers that have the sameUUIDcannot 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
Attributes and theirAttributeModifiers. 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
AttributeModifiers 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
Attributes andAttributeModifiers for a givenEquipmentSlot.
If the givenEquipmentSlotis null, this will remove allAttributeModifiers 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
AttributeandAttributeModifier. AttributeModifiers are matched according to theirUUID.- 参数:
attribute- 要移除的属性modifier- 要移除的属性修饰符- 返回:
- 如果删除了任何属性修饰符
- 抛出:
NullPointerException- 若 Attribute 为 nullNullPointerException- 若 AttributeModifier 为 null- 另请参阅:
-
getAsString
将此 ItemMeta 转换为 NBT 字符串. 如果此 ItemMeta 没有任何 NBT 数据, 则返回"{}".译注: NBT (Named Binary Tag) 是 Minecraft 中用于存储数据的一种格式.
此字符串绝不应被视为可序列化的值. 如果需要序列化, 则应使用
ConfigurationSerializableAPI.原文: 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
ConfigurationSerializableAPI should be used instead.- 返回:
- NBT 字符串
-
getAsComponentString
将此 ItemMeta 转换为组件兼容的字符串. 如果此 ItemMeta 不包含任何组件, 则返回"[]".此方法的结果应生成一个代表由此 ItemMeta 实例修改的组件的字符串. 当与前置的物品类型一起传递给
ItemFactory.createItemStack(String)时, 它将创建一个拥有与此 ItemMeta 实例完全匹配的 ItemMeta 的 ItemStack. 请注意, 此方法仅返回组件部分, 不能单独传递给 createItemStack(). 示例如下:ItemStack itemStack = // ... 从某处获取的物品堆栈 ItemMeta itemMeta = itemStack.getItemMeta(); String components = itemMeta.getAsComponentString(); // 示例: "[minecraft:damage=53]" String itemTypeKey = itemStack.getType().getKey().toString(); // 示例: "minecraft:diamond_sword" String itemAsString = itemTypeKey + components; // 结果: "minecraft:diamond_sword[minecraft:damage=53]" ItemStack recreatedItemStack = Bukkit.getItemFactory().createItemStack(itemAsString); assert itemStack.isSimilar(recreatedItemStack); // 应为 true*
*未被此 ItemMeta 实例表示或显式覆盖的组件将不会包含在结果字符串中, 因此可能导致 ItemStack 不完全匹配. 例如, 如果未设置
setDisplayName(String), 则自定义名称组件将不会被包含. 或者, 如果此 ItemMeta 是 PotionMeta, 它将不包含与磁石指针、旗帜或书等相关的任何组件, 仅包含可通过 PotionMeta 实例修改的组件.此字符串绝不应被视为可序列化的值. 如果需要序列化, 则应使用
ConfigurationSerializableAPI.原文: 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
ConfigurationSerializableAPI should be used instead.- 返回:
- 组件兼容的字符串
-
getCustomTagContainer
已过时。该 API 已被PersistentDataHolderAPI 取代. 请使用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
-
getCustomModelDataComponent().