mirror of
https://github.com/CarmJos/UserPrefix.git
synced 2026-06-05 00:16:20 +08:00
尝试支持旧版本物品的读取
This commit is contained in:
@@ -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,6 +33,9 @@ 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")) {
|
||||||
|
String itemName = args.get("type").toString();
|
||||||
|
Material legacyMaterial = Material.matchMaterial(itemName, true);
|
||||||
|
if (legacyMaterial == null) {
|
||||||
Material material = Material.matchMaterial(args.get("type").toString());
|
Material material = Material.matchMaterial(args.get("type").toString());
|
||||||
if (material == null) {
|
if (material == null) {
|
||||||
throw new IllegalArgumentException("物品 " + args.get("type") + " 不存在");
|
throw new IllegalArgumentException("物品 " + args.get("type") + " 不存在");
|
||||||
@@ -38,6 +43,7 @@ public class ItemStackWrapper implements ConfigurationSerializable {
|
|||||||
args.put("v", Bukkit.getServer().getUnsafe().getDataVersion());
|
args.put("v", Bukkit.getServer().getUnsafe().getDataVersion());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
return ItemStack.deserialize(args);
|
return ItemStack.deserialize(args);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user