Commits

blablubbabc authored and md_5 committed 65247583f8c
SPIGOT-7857: Improve ItemMeta block data deserialization

(cherry picked from commit 8ee6fd1b8db9896590aa321d0199453de1fc35db)
No tags

src/main/java/org/bukkit/craftbukkit/inventory/CraftMetaItem.java

Modified
492 492
493 493 Integer customModelData = SerializableMeta.getObject(Integer.class, map, CUSTOM_MODEL_DATA.BUKKIT, true);
494 494 if (customModelData != null) {
495 495 setCustomModelData(customModelData);
496 496 }
497 497
498 498 Object blockData = SerializableMeta.getObject(Object.class, map, BLOCK_DATA.BUKKIT, true);
499 499 if (blockData != null) {
500 500 Map<String, String> mapBlockData = new HashMap<>();
501 501
502 - NBTTagCompound nbtBlockData = (NBTTagCompound) CraftNBTTagConfigSerializer.deserialize(blockData);
503 - for (String key : nbtBlockData.getAllKeys()) {
504 - mapBlockData.put(key, nbtBlockData.getString(key));
502 + if (blockData instanceof Map) {
503 + for (Entry<?, ?> entry : ((Map<?, ?>) blockData).entrySet()) {
504 + mapBlockData.put(entry.getKey().toString(), entry.getValue().toString());
505 + }
506 + } else {
507 + // Legacy pre 1.20.5:
508 + NBTTagCompound nbtBlockData = (NBTTagCompound) CraftNBTTagConfigSerializer.deserialize(blockData);
509 + for (String key : nbtBlockData.getAllKeys()) {
510 + mapBlockData.put(key, nbtBlockData.getString(key));
511 + }
505 512 }
506 513
507 514 this.blockData = mapBlockData;
508 515 }
509 516
510 517 enchantments = buildEnchantments(map, ENCHANTMENTS);
511 518 attributeModifiers = buildModifiers(map, ATTRIBUTES);
512 519
513 520 Integer repairCost = SerializableMeta.getObject(Integer.class, map, REPAIR.BUKKIT, true);
514 521 if (repairCost != null) {

Everything looks good. We'll let you know here if there's anything you should know about.

Add shortcut