mirror of
https://github.com/PaperMC/Paper.git
synced 2025-01-09 19:49:35 +01:00
SPIGOT-4028: Improve legacy ItemStack conversion
By: md_5 <git@md-5.net>
This commit is contained in:
parent
866302fa60
commit
951b0a443d
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) {
|
public static ItemStack deserialize(Map<String, Object> args) {
|
||||||
int version = (args.containsKey("v")) ? ((Number) args.get("v")).intValue() : -1;
|
int version = (args.containsKey("v")) ? ((Number) args.get("v")).intValue() : -1;
|
||||||
Material type = Material.getMaterial((String) args.get("type"), version < 0);
|
|
||||||
|
|
||||||
short damage = 0;
|
short damage = 0;
|
||||||
int amount = 1;
|
int amount = 1;
|
||||||
|
|
||||||
|
@ -447,6 +445,21 @@ public class ItemStack implements Cloneable, ConfigurationSerializable {
|
||||||
damage = ((Number) args.get("damage")).shortValue();
|
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")) {
|
if (args.containsKey("amount")) {
|
||||||
amount = ((Number) args.get("amount")).intValue();
|
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;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue