Class NbtUtils
-
- All Implemented Interfaces:
public class NbtUtils
-
-
Field Summary
Fields Modifier and Type Field Description public final static Object
registryOps
-
Constructor Summary
Constructors Constructor Description NbtUtils()
-
Method Summary
Modifier and Type Method Description static RefNbtTagCompound
getOrCreateTag(@NonNull() RefNmsItemStack itemStack)
获取物品NBT, 如果物品没有NBT就创建一个空NBT, 设置并返回. static RefNbtTagCompound
coverWith(@NonNull() RefNbtTagCompound baseCompound, @NonNull() RefNbtTagCompound overlayCompound)
使用给定的 RefNbtTagCompound 覆盖当前 RefNbtTagCompound. static boolean
isCraftItemStack(@NonNull() ItemStack itemStack)
检测给定的 ItemStack 实例是否属于 CraftItemStack 子类. static ItemMeta
getItemMeta(@NonNull() ItemStack itemStack)
通过给定的 ItemStack 实例获取 ItemStack. static ItemStack
bukkitCopy(@NonNull() ItemStack itemStack)
仅可用于 org.bukkit.inventory.ItemStack, 不可用于 CraftItemStack. static ItemStack
asCopy(@NonNull() ItemStack itemStack)
获取给定物品的克隆, 返回值有可能为 ItemStack 或 CraftItemStack. static ItemStack
asBukkitCopy(@NonNull() ItemStack itemStack)
将给定的物品转换为 org.bukkit.inventory.ItemStack 形式的克隆. static ItemStack
asCraftCopy(@NonNull() ItemStack itemStack)
将给定的物品转换为 CraftItemStack 形式的克隆. static NbtCompound
readCompressed(File file)
从压缩文件中读取 NbtCompound. static NbtCompound
readCompressed(InputStream stream)
从压缩文件中读取 NbtCompound. static void
writeCompressed(NbtCompound compound, File file)
向压缩文件写入 NbtCompound. static void
writeCompressed(NbtCompound compound, OutputStream stream)
向压缩文件写入 NbtCompound. static NbtCompound
read(File file)
从未压缩文件中读取 NbtCompound. static NbtCompound
read(DataInputStream stream)
从未压缩文件中读取 NbtCompound. static void
write(NbtCompound compound, File file)
向未压缩文件写入 NbtCompound. static void
write(NbtCompound compound, DataOutput output)
向未压缩文件写入 NbtCompound. static NbtCompound
save(@Nullable() ItemStack itemStack)
把物品保存成 NbtCompound. static ItemStack
of(@Nullable() NbtCompound nbt)
根据 NbtCompound 掏一个物品出来. static String
getNameNbtKey()
static String
getLocNameNbtKey()
static String
getDisplayNbtKey()
static String
getLoreNbtKey()
static String
getCustomModelDataNbtKeyOrNull()
static String
getCustomModelDataNbtKeyOrThrow()
static String
getEnchantmentsNbtKey()
static String
getEnchantmentIdNbtKey()
static String
getEnchantmentLvlNbtKey()
static String
getRepairNbtKey()
static String
getAttributesNbtKey()
static String
getAttributesIdentifierNbtKey()
static String
getAttributesNameNbtKey()
static String
getAttributesValueNbtKey()
static String
getAttributesTypeNbtKey()
static String
getAttributesUUIDHighNbtKey()
static String
getAttributesUUIDLowNbtKey()
static String
getAttributesSlotNbtKeyOrNull()
static String
getAttributesSlotNbtKeyOrThrow()
static String
getHideFlagsNbtKey()
static String
getUnbreakableNbtKey()
static String
getDamageNbtKeyOrNull()
static String
getDamageNbtKeyOrThrow()
static String
getBlockDataNbtKeyOrNull()
static String
getBlockDataNbtKeyOrThrow()
static String
getBukkitCustomTagNbtKeyOrNull()
static String
getBukkitCustomTagNbtKeyOrThrow()
static String
getCanDestroyNbtKeyOrNull()
static String
getCanDestroyNbtKeyOrThrow()
static String
getCanPlaceOnNbtKeyOrNull()
static String
getCanPlaceOnNbtKeyOrThrow()
static void
setComponents(@NonNull() ItemStack receiver, @NonNull() ItemStack provider)
static ItemStack
getCraftDelegate(@NonNull() ItemStack itemStack)
static NbtCompound
getDisplayNbt(@NonNull() ItemStack itemStack)
获取展示用NBT. static void
editNameAndLoreAfterV21(@NonNull() ItemStack itemStack, BiFunction<ItemStack, String, ItemPlaceholder.ParseResult> handler)
编辑物品的name和lore, 仅适用于1.21+版本. static ConfigurationSection
saveAfterV21(@Nullable() ItemStack itemStack)
将物品保存为NI可识别的配置文件, 性能较差, 不建议于性能敏感处使用, 仅适用于1.21+版本. -
-
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可识别的配置文件
-
-
-
-