mirror of
https://github.com/CarmJos/UserPrefix.git
synced 2024-09-19 20:15:47 +00:00
尝试支持旧版本物品的读取
This commit is contained in:
parent
99f2b6ff28
commit
734e5f526c
@ -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,6 +33,9 @@ public class ItemStackWrapper implements ConfigurationSerializable {
|
||||
// static define will cause problem, lazy load it
|
||||
if (unsafeAvailable) {
|
||||
if (!args.containsKey("v")) {
|
||||
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") + " 不存在");
|
||||
@ -38,6 +43,7 @@ public class ItemStackWrapper implements ConfigurationSerializable {
|
||||
args.put("v", Bukkit.getServer().getUnsafe().getDataVersion());
|
||||
}
|
||||
}
|
||||
}
|
||||
return ItemStack.deserialize(args);
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user