Commits

Bjarne Koll authored and md_5 committed f0661c3514a
#1230: Move unstructured PDC NBT serialisation to SNBT

The initial implementation of the CraftNBTTagConfigSerialiser attempted to represent the entire NBT tree in yaml. While the tree structure itself is nicely represented, the values and their respective types become increasingly difficult to properly store in the context of snakeyml/yml in general. This is mainly due to the fact that nbt offers a lot of different types compared to yaml, specifically the primitive arrays and different floating point values are troublesome as they require parsing via mojang parsers due to their custom format. To build a future proof system for unstructured nbt in spigot yml, this commit moves the entire serialisation fully into SNBT, producing a single string as output rather than a full yml tree. SNBT remains easily readable and editable for server owners, which was one of the main criteria during the initial implementation of the serialiser (preventing the use of bas64ed gzipped nbt bytes), while also completely using mojangs parsing, eliminating any need for custom parsing logic in spigot. Additionally, a string allows for very straight forward handling of legacy data by simply parsing strings as SNBT and maps/yml trees as legacy content, depending on what type snakeyml produces after parsing the yml content, removing the need for a versioning schema.
No tags

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

Modified
527 527 for (String key : keys) {
528 528 if (!getHandledTags().contains(key)) {
529 529 unhandledTags.put(key, internalTag.get(key));
530 530 }
531 531 }
532 532 } catch (IOException ex) {
533 533 Logger.getLogger(CraftMetaItem.class.getName()).log(Level.SEVERE, null, ex);
534 534 }
535 535 }
536 536
537 - Map nbtMap = SerializableMeta.getObject(Map.class, map, BUKKIT_CUSTOM_TAG.BUKKIT, true);
537 + Object nbtMap = SerializableMeta.getObject(Object.class, map, BUKKIT_CUSTOM_TAG.BUKKIT, true); // We read both legacy maps and potential modern snbt strings here
538 538 if (nbtMap != null) {
539 539 this.persistentDataContainer.putAll((NBTTagCompound) CraftNBTTagConfigSerializer.deserialize(nbtMap));
540 540 }
541 541 }
542 542
543 543 void deserializeInternal(NBTTagCompound tag, Object context) {
544 544 // SPIGOT-4576: Need to migrate from internal to proper data
545 545 if (tag.contains(ATTRIBUTES.NBT, CraftMagicNumbers.NBT.TAG_LIST)) {
546 546 this.attributeModifiers = buildModifiers(tag, ATTRIBUTES);
547 547 }

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

Add shortcut