mirror of
https://hub.spigotmc.org/stash/scm/spigot/bukkit.git
synced 2025-09-18 21:45:12 +00:00
SPIGOT-4028: Improve legacy ItemStack conversion
This commit is contained in:
parent
1d21dc022e
commit
0cb7e26846
1 changed files with 15 additions and 7 deletions
|
@ -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;
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue