refactor(core-bukkit): 添加部分文档
This commit is contained in:
@@ -320,30 +320,42 @@ public final class CoreBukkitUtils {
|
||||
return YamlConfiguration.loadConfiguration(file);
|
||||
}
|
||||
|
||||
/**
|
||||
* 将物品序列化成 nbt 字符串
|
||||
*
|
||||
* @param stack 物品实例
|
||||
* @return nbt 字符串
|
||||
*/
|
||||
@NotNull
|
||||
public static String serializeItemStack(@NotNull ItemStack stack) {
|
||||
NBTContainer container = NBTItem.convertItemtoNBT(stack);
|
||||
return container.toString();
|
||||
return NBTItem.convertItemtoNBT(stack).toString();
|
||||
}
|
||||
|
||||
/**
|
||||
* 将 nbt 字符串反序列化为物品
|
||||
*
|
||||
* @param string nbt 字符串
|
||||
* @return 物品实例
|
||||
*/
|
||||
@Nullable
|
||||
public static ItemStack deserializeItemStack(@NotNull String string) {
|
||||
ItemStack stack;
|
||||
try {
|
||||
stack = NBTItem.convertNBTtoItem(new NBTContainer(string));
|
||||
} catch (Exception ignored) {
|
||||
stack = null;
|
||||
}
|
||||
return stack;
|
||||
return NBTItem.convertNBTtoItem(new NBTContainer(string));
|
||||
}
|
||||
|
||||
/**
|
||||
* 将 nbt 字符串反序列化为物品
|
||||
*
|
||||
* @param string nbt 字符串
|
||||
* @param defaultValue 当序列化失败时,返回 defaultValue
|
||||
* @return 物品实例
|
||||
*/
|
||||
@NotNull
|
||||
public static ItemStack deserializeItemStack(@NotNull String string, @NotNull ItemStack defaultValue) {
|
||||
ItemStack stack;
|
||||
try {
|
||||
stack = NBTItem.convertNBTtoItem(new NBTContainer(string));
|
||||
stack = deserializeItemStack(string);
|
||||
} catch (Exception ignored) {
|
||||
stack = null;
|
||||
return defaultValue;
|
||||
}
|
||||
if (stack == null) {
|
||||
return defaultValue;
|
||||
|
Reference in New Issue
Block a user