Commits

Thinkofname authored 8e5e4c189bd
SPIGOT-581: Allow for unhandled nbt tags to be serialized to yaml
No tags

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

Modified
40 40 import org.bukkit.craftbukkit.block.CraftSkull;
41 41 import org.bukkit.inventory.meta.BlockStateMeta;
42 42
43 43 @DelegateDeserialization(CraftMetaItem.SerializableMeta.class)
44 44 public class CraftMetaBlockState extends CraftMetaItem implements BlockStateMeta {
45 45
46 46 @ItemMetaKey.Specific(ItemMetaKey.Specific.To.NBT)
47 47 static final ItemMetaKey BLOCK_ENTITY_TAG = new ItemMetaKey("BlockEntityTag");
48 48
49 49 final Material material;
50 - private NBTTagCompound blockEntityTag;
50 + NBTTagCompound blockEntityTag;
51 51
52 52 CraftMetaBlockState(CraftMetaItem meta, Material material) {
53 53 super(meta);
54 54 this.material = material;
55 55
56 56 if (!(meta instanceof CraftMetaBlockState)
57 57 || ((CraftMetaBlockState) meta).material != material
58 58 || material == Material.SIGN
59 59 || material == Material.COMMAND) {
60 60 blockEntityTag = null;
71 71
72 72 if (tag.hasKeyOfType(BLOCK_ENTITY_TAG.NBT, 10)) {
73 73 blockEntityTag = tag.getCompound(BLOCK_ENTITY_TAG.NBT);
74 74 } else {
75 75 blockEntityTag = null;
76 76 }
77 77 }
78 78
79 79 CraftMetaBlockState(Map<String, Object> map) {
80 80 super(map);
81 - material = Material.AIR; // TODO
82 -
83 - blockEntityTag = null;
81 + String matName = SerializableMeta.getString(map, "blockMaterial", true);
82 + Material m = Material.getMaterial(matName);
83 + if (m != null) {
84 + material = m;
85 + } else {
86 + material = Material.AIR;
87 + }
84 88 }
85 89
86 90 @Override
87 91 void applyToItem(NBTTagCompound tag) {
88 92 super.applyToItem(tag);
89 93
90 94 if (blockEntityTag != null) {
91 95 tag.set(BLOCK_ENTITY_TAG.NBT, blockEntityTag);
92 96 }
93 97 }
94 98
95 99 @Override
96 100 ImmutableMap.Builder<String, Object> serialize(ImmutableMap.Builder<String, Object> builder) {
97 101 super.serialize(builder);
102 + builder.put("blockMaterial", material.name());
98 103 return builder;
99 104 }
100 105
101 106 @Override
102 107 int applyHash() {
103 108 final int original;
104 109 int hash = original = super.applyHash();
105 110 if (blockEntityTag != null) {
106 111 hash = 61 * hash + this.blockEntityTag.hashCode();
107 112 }

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

Add shortcut