summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authormd_5 <git@md-5.net>2018-07-18 14:00:44 +1000
committermd_5 <git@md-5.net>2018-07-18 14:00:44 +1000
commit0cb7e26846080d82de6e2d09083f8ae54b401c70 (patch)
tree10edf6ead2b956cd8ffeb403c69add5229b19e64
parent1d21dc022e7e6905ef64f54b165e7559dfa40ade (diff)
downloadbukkit-0cb7e26846080d82de6e2d09083f8ae54b401c70.tar
bukkit-0cb7e26846080d82de6e2d09083f8ae54b401c70.tar.gz
bukkit-0cb7e26846080d82de6e2d09083f8ae54b401c70.tar.lz
bukkit-0cb7e26846080d82de6e2d09083f8ae54b401c70.tar.xz
bukkit-0cb7e26846080d82de6e2d09083f8ae54b401c70.zip
SPIGOT-4028: Improve legacy ItemStack conversion
-rw-r--r--src/main/java/org/bukkit/inventory/ItemStack.java22
1 files changed, 15 insertions, 7 deletions
diff --git a/src/main/java/org/bukkit/inventory/ItemStack.java b/src/main/java/org/bukkit/inventory/ItemStack.java
index 6324044d..73f79b22 100644
--- a/src/main/java/org/bukkit/inventory/ItemStack.java
+++ b/src/main/java/org/bukkit/inventory/ItemStack.java
@@ -438,8 +438,6 @@ public class ItemStack implements Cloneable, ConfigurationSerializable {
*/
public static ItemStack deserialize(Map<String, Object> args) {
int version = (args.containsKey("v")) ? ((Number) args.get("v")).intValue() : -1;
- Material type = Material.getMaterial((String) args.get("type"), version < 0);
-
short damage = 0;
int amount = 1;
@@ -447,6 +445,21 @@ public class ItemStack implements Cloneable, ConfigurationSerializable {
damage = ((Number) args.get("damage")).shortValue();
}
+ Material type;
+ if (version < 0) {
+ type = Material.getMaterial(Material.LEGACY_PREFIX + (String) args.get("type"));
+
+ byte dataVal = (type.getMaxDurability() == 0) ? (byte) damage : 0; // Actually durable items get a 0 passed into conversion
+ type = Bukkit.getUnsafe().fromLegacy(new MaterialData(type, dataVal));
+
+ // We've converted now so the data val isn't a thing and can be reset
+ if (dataVal != 0) {
+ damage = 0;
+ }
+ } else {
+ type = Material.getMaterial((String) args.get("type"));
+ }
+
if (args.containsKey("amount")) {
amount = ((Number) args.get("amount")).intValue();
}
@@ -474,11 +487,6 @@ public class ItemStack implements Cloneable, ConfigurationSerializable {
}
}
- // Set damage again incase meta overwrote it
- if (args.containsKey("damage")) {
- result.setDurability(damage);
- }
-
return result;
}