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