mirror of
https://github.com/PaperMC/Paper.git
synced 2025-01-07 16:57:42 +01:00
SPIGOT-4028: Improve legacy ItemStack conversion
By: md_5 <git@md-5.net>
This commit is contained in:
parent
866302fa60
commit
951b0a443d
@ -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…
Reference in New Issue
Block a user