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