Class NbtUtils
-
- All Implemented Interfaces:
public class NbtUtils
-
-
Field Summary
Fields Modifier and Type Field Description public final static ObjectregistryOps
-
Constructor Summary
Constructors Constructor Description NbtUtils()
-
Method Summary
Modifier and Type Method Description static RefNbtTagCompoundgetOrCreateTag(@NonNull() RefNmsItemStack itemStack)获取物品NBT, 如果物品没有NBT就创建一个空NBT, 设置并返回. static RefNbtTagCompoundcoverWith(@NonNull() RefNbtTagCompound baseCompound, @NonNull() RefNbtTagCompound overlayCompound)使用给定的 RefNbtTagCompound 覆盖当前 RefNbtTagCompound. static booleanisCraftItemStack(@NonNull() ItemStack itemStack)检测给定的 ItemStack 实例是否属于 CraftItemStack 子类. static ItemMetagetItemMeta(@NonNull() ItemStack itemStack)通过给定的 ItemStack 实例获取 ItemStack. static ItemStackbukkitCopy(@NonNull() ItemStack itemStack)仅可用于 org.bukkit.inventory.ItemStack, 不可用于 CraftItemStack. static ItemStackasCopy(@NonNull() ItemStack itemStack)获取给定物品的克隆, 返回值有可能为 ItemStack 或 CraftItemStack. static ItemStackasBukkitCopy(@NonNull() ItemStack itemStack)将给定的物品转换为 org.bukkit.inventory.ItemStack 形式的克隆. static ItemStackasCraftCopy(@NonNull() ItemStack itemStack)将给定的物品转换为 CraftItemStack 形式的克隆. static NbtCompoundreadCompressed(File file)从压缩文件中读取 NbtCompound. static NbtCompoundreadCompressed(InputStream stream)从压缩文件中读取 NbtCompound. static voidwriteCompressed(NbtCompound compound, File file)向压缩文件写入 NbtCompound. static voidwriteCompressed(NbtCompound compound, OutputStream stream)向压缩文件写入 NbtCompound. static NbtCompoundread(File file)从未压缩文件中读取 NbtCompound. static NbtCompoundread(DataInputStream stream)从未压缩文件中读取 NbtCompound. static voidwrite(NbtCompound compound, File file)向未压缩文件写入 NbtCompound. static voidwrite(NbtCompound compound, DataOutput output)向未压缩文件写入 NbtCompound. static NbtCompoundsave(@Nullable() ItemStack itemStack)把物品保存成 NbtCompound. static ItemStackof(@Nullable() NbtCompound nbt)根据 NbtCompound 掏一个物品出来. static StringgetNameNbtKey()static StringgetLocNameNbtKey()static StringgetDisplayNbtKey()static StringgetLoreNbtKey()static StringgetCustomModelDataNbtKeyOrNull()static StringgetCustomModelDataNbtKeyOrThrow()static StringgetEnchantmentsNbtKey()static StringgetEnchantmentIdNbtKey()static StringgetEnchantmentLvlNbtKey()static StringgetRepairNbtKey()static StringgetAttributesNbtKey()static StringgetAttributesIdentifierNbtKey()static StringgetAttributesNameNbtKey()static StringgetAttributesValueNbtKey()static StringgetAttributesTypeNbtKey()static StringgetAttributesUUIDHighNbtKey()static StringgetAttributesUUIDLowNbtKey()static StringgetAttributesSlotNbtKeyOrNull()static StringgetAttributesSlotNbtKeyOrThrow()static StringgetHideFlagsNbtKey()static StringgetUnbreakableNbtKey()static StringgetDamageNbtKeyOrNull()static StringgetDamageNbtKeyOrThrow()static StringgetBlockDataNbtKeyOrNull()static StringgetBlockDataNbtKeyOrThrow()static StringgetBukkitCustomTagNbtKeyOrNull()static StringgetBukkitCustomTagNbtKeyOrThrow()static StringgetCanDestroyNbtKeyOrNull()static StringgetCanDestroyNbtKeyOrThrow()static StringgetCanPlaceOnNbtKeyOrNull()static StringgetCanPlaceOnNbtKeyOrThrow()static voidsetComponents(@NonNull() ItemStack receiver, @NonNull() ItemStack provider)static ItemStackgetCraftDelegate(@NonNull() ItemStack itemStack)static NbtCompoundgetDisplayNbt(@NonNull() ItemStack itemStack)获取展示用NBT. static voideditNameAndLoreAfterV21(@NonNull() ItemStack itemStack, BiFunction<ItemStack, String, ItemPlaceholder.ParseResult> handler)编辑物品的name和lore, 仅适用于1.21+版本. static ConfigurationSectionsaveAfterV21(@Nullable() ItemStack itemStack)将物品保存为NI可识别的配置文件, 性能较差, 不建议于性能敏感处使用, 仅适用于1.21+版本. static booleanisSimilar(@Nullable() ItemStack itemStack1, @Nullable() ItemStack itemStack2)比较两物品是否相似(除数量外完全一致), 在 1.12.2 到 1.20.4 版本中的某些情况下相较于 ItemStack#isSimilar 方法具有更好的性能表现. -
-
Method Detail
-
getOrCreateTag
@NonNull() static RefNbtTagCompound getOrCreateTag(@NonNull() RefNmsItemStack itemStack)
获取物品NBT, 如果物品没有NBT就创建一个空NBT, 设置并返回.
- Parameters:
itemStack- 待获取NBT的物品.- Returns:
物品NBT.
-
coverWith
@NonNull() static RefNbtTagCompound coverWith(@NonNull() RefNbtTagCompound baseCompound, @NonNull() RefNbtTagCompound overlayCompound)
使用给定的 RefNbtTagCompound 覆盖当前 RefNbtTagCompound.
- Parameters:
baseCompound- 被覆盖的基础 RefNbtTagCompound.overlayCompound- 用于提供覆盖值的 RefNbtTagCompound.- Returns:
baseCompound.
-
isCraftItemStack
static boolean isCraftItemStack(@NonNull() ItemStack itemStack)
检测给定的 ItemStack 实例是否属于 CraftItemStack 子类.
- Parameters:
itemStack- 待检测物品.- Returns:
检测结果.
-
getItemMeta
@Nullable() static ItemMeta getItemMeta(@NonNull() ItemStack itemStack)
通过给定的 ItemStack 实例获取 ItemStack. org.bukkit.inventory.ItemStack 将返回 ItemMeta 原本. org.bukkit.craftbukkit.xxx.inventory.CraftItemStack 将返回 ItemMeta 副本. 1.21+无论什么都返回副本.
- Parameters:
itemStack- 待获取物品.- Returns:
ItemMeta.
-
bukkitCopy
@NonNull() static ItemStack bukkitCopy(@NonNull() ItemStack itemStack)
仅可用于 org.bukkit.inventory.ItemStack, 不可用于 CraftItemStack. 获取给定物品的克隆, 返回值为 ItemStack. 修复了 org.bukkit.inventory.ItemStack#clone 在克隆 CraftMetaItem 时对 unhandledTags 浅复制的问题.
- Parameters:
itemStack- 待操作物品.- Returns:
物品克隆.
-
asCopy
@NonNull() static ItemStack asCopy(@NonNull() ItemStack itemStack)
获取给定物品的克隆, 返回值有可能为 ItemStack 或 CraftItemStack. 修复了 org.bukkit.inventory.ItemStack#clone 在克隆 CraftMetaItem 时对 unhandledTags 浅复制的问题.
- Parameters:
itemStack- 待操作物品.- Returns:
物品克隆.
-
asBukkitCopy
@NonNull() static ItemStack asBukkitCopy(@NonNull() ItemStack itemStack)
将给定的物品转换为 org.bukkit.inventory.ItemStack 形式的克隆. 给定物品可能属于 ItemStack, 也可能属于 ItemStack 在 OBC 的子类 CraftItemStack.
- Parameters:
itemStack- 待操作物品.- Returns:
org.bukkit.inventory.ItemStack 形式的物品克隆.
-
asCraftCopy
@NonNull() static ItemStack asCraftCopy(@NonNull() ItemStack itemStack)
将给定的物品转换为 CraftItemStack 形式的克隆. 给定物品可能属于 ItemStack, 也可能属于 ItemStack 在 OBC 的子类 CraftItemStack.
- Parameters:
itemStack- 待操作物品.- Returns:
CraftItemStack 形式的物品克隆.
-
readCompressed
static NbtCompound readCompressed(File file)
从压缩文件中读取 NbtCompound.
-
readCompressed
static NbtCompound readCompressed(InputStream stream)
从压缩文件中读取 NbtCompound.
-
writeCompressed
static void writeCompressed(NbtCompound compound, File file)
向压缩文件写入 NbtCompound.
-
writeCompressed
static void writeCompressed(NbtCompound compound, OutputStream stream)
向压缩文件写入 NbtCompound.
-
read
static NbtCompound read(File file)
从未压缩文件中读取 NbtCompound.
-
read
static NbtCompound read(DataInputStream stream)
从未压缩文件中读取 NbtCompound.
-
write
static void write(NbtCompound compound, File file)
向未压缩文件写入 NbtCompound.
-
write
static void write(NbtCompound compound, DataOutput output)
向未压缩文件写入 NbtCompound.
-
save
@NonNull() static NbtCompound save(@Nullable() ItemStack itemStack)
把物品保存成 NbtCompound.
-
of
@NonNull() static ItemStack of(@Nullable() NbtCompound nbt)
根据 NbtCompound 掏一个物品出来.
-
getNameNbtKey
@NonNull() static String getNameNbtKey()
-
getLocNameNbtKey
@NonNull() static String getLocNameNbtKey()
-
getDisplayNbtKey
@NonNull() static String getDisplayNbtKey()
-
getLoreNbtKey
@NonNull() static String getLoreNbtKey()
-
getCustomModelDataNbtKeyOrNull
@Nullable() static String getCustomModelDataNbtKeyOrNull()
-
getCustomModelDataNbtKeyOrThrow
@NonNull() static String getCustomModelDataNbtKeyOrThrow()
-
getEnchantmentsNbtKey
@NonNull() static String getEnchantmentsNbtKey()
-
getEnchantmentIdNbtKey
@NonNull() static String getEnchantmentIdNbtKey()
-
getEnchantmentLvlNbtKey
@NonNull() static String getEnchantmentLvlNbtKey()
-
getRepairNbtKey
@NonNull() static String getRepairNbtKey()
-
getAttributesNbtKey
@NonNull() static String getAttributesNbtKey()
-
getAttributesIdentifierNbtKey
@NonNull() static String getAttributesIdentifierNbtKey()
-
getAttributesNameNbtKey
@NonNull() static String getAttributesNameNbtKey()
-
getAttributesValueNbtKey
@NonNull() static String getAttributesValueNbtKey()
-
getAttributesTypeNbtKey
@NonNull() static String getAttributesTypeNbtKey()
-
getAttributesUUIDHighNbtKey
@NonNull() static String getAttributesUUIDHighNbtKey()
-
getAttributesUUIDLowNbtKey
@NonNull() static String getAttributesUUIDLowNbtKey()
-
getAttributesSlotNbtKeyOrNull
@Nullable() static String getAttributesSlotNbtKeyOrNull()
-
getAttributesSlotNbtKeyOrThrow
@NonNull() static String getAttributesSlotNbtKeyOrThrow()
-
getHideFlagsNbtKey
@NonNull() static String getHideFlagsNbtKey()
-
getUnbreakableNbtKey
@NonNull() static String getUnbreakableNbtKey()
-
getDamageNbtKeyOrNull
@Nullable() static String getDamageNbtKeyOrNull()
-
getDamageNbtKeyOrThrow
@NonNull() static String getDamageNbtKeyOrThrow()
-
getBlockDataNbtKeyOrNull
@Nullable() static String getBlockDataNbtKeyOrNull()
-
getBlockDataNbtKeyOrThrow
@NonNull() static String getBlockDataNbtKeyOrThrow()
-
getBukkitCustomTagNbtKeyOrNull
@Nullable() static String getBukkitCustomTagNbtKeyOrNull()
-
getBukkitCustomTagNbtKeyOrThrow
@NonNull() static String getBukkitCustomTagNbtKeyOrThrow()
-
getCanDestroyNbtKeyOrNull
@Nullable() static String getCanDestroyNbtKeyOrNull()
-
getCanDestroyNbtKeyOrThrow
@NonNull() static String getCanDestroyNbtKeyOrThrow()
-
getCanPlaceOnNbtKeyOrNull
@Nullable() static String getCanPlaceOnNbtKeyOrNull()
-
getCanPlaceOnNbtKeyOrThrow
@NonNull() static String getCanPlaceOnNbtKeyOrThrow()
-
setComponents
static void setComponents(@NonNull() ItemStack receiver, @NonNull() ItemStack provider)
-
getCraftDelegate
@Nullable() static ItemStack getCraftDelegate(@NonNull() ItemStack itemStack)
-
getDisplayNbt
@NonNull() static NbtCompound getDisplayNbt(@NonNull() ItemStack itemStack)
获取展示用NBT.
- Parameters:
itemStack- 待获取物品.- Returns:
展示用NBT
-
editNameAndLoreAfterV21
static void editNameAndLoreAfterV21(@NonNull() ItemStack itemStack, BiFunction<ItemStack, String, ItemPlaceholder.ParseResult> handler)
编辑物品的name和lore, 仅适用于1.21+版本.
- Parameters:
itemStack- 待操作物品.handler- 文本处理器.
-
saveAfterV21
@Nullable() static ConfigurationSection saveAfterV21(@Nullable() ItemStack itemStack)
将物品保存为NI可识别的配置文件, 性能较差, 不建议于性能敏感处使用, 仅适用于1.21+版本.
- Parameters:
itemStack- 待转换物品.- Returns:
NI可识别的配置文件
-
isSimilar
static boolean isSimilar(@Nullable() ItemStack itemStack1, @Nullable() ItemStack itemStack2)
比较两物品是否相似(除数量外完全一致), 在 1.12.2 到 1.20.4 版本中的某些情况下相较于 ItemStack#isSimilar 方法具有更好的性能表现.
- Parameters:
itemStack1- 物品1.itemStack2- 物品2.- Returns:
两物品是否相似
-
-
-
-