1
mirror of https://github.com/CarmJos/UserPrefix.git synced 2024-09-19 20:15:47 +00:00

尝试支持旧版本物品的读取

This commit is contained in:
Carm Jos 2022-03-02 04:20:17 +08:00
parent 99f2b6ff28
commit 734e5f526c

View File

@ -12,10 +12,12 @@ public class ItemStackWrapper implements ConfigurationSerializable {
private static boolean unsafeAvailable;
static {
// 用于判断是否支持unsafe
try {
Class.forName("org.bukkit.UnsafeValues");
int dataVersion = Bukkit.getServer().getUnsafe().getDataVersion();
unsafeAvailable = true;
} catch (ClassNotFoundException e) {
} catch (Exception e) {
unsafeAvailable = false;
}
}
@ -31,11 +33,15 @@ public class ItemStackWrapper implements ConfigurationSerializable {
// static define will cause problem, lazy load it
if (unsafeAvailable) {
if (!args.containsKey("v")) {
Material material = Material.matchMaterial(args.get("type").toString());
if (material == null) {
throw new IllegalArgumentException("物品 "+args.get("type")+" 不存在");
String itemName = args.get("type").toString();
Material legacyMaterial = Material.matchMaterial(itemName, true);
if (legacyMaterial == null) {
Material material = Material.matchMaterial(args.get("type").toString());
if (material == null) {
throw new IllegalArgumentException("物品 " + args.get("type") + " 不存在");
}
args.put("v", Bukkit.getServer().getUnsafe().getDataVersion());
}
args.put("v", Bukkit.getServer().getUnsafe().getDataVersion());
}
}
return ItemStack.deserialize(args);