From 11417fa04e965b896bab238b8095d35cf8b881e2 Mon Sep 17 00:00:00 2001 From: KennyTV Date: Fri, 17 Apr 2020 20:47:22 +0200 Subject: [PATCH] Add sanity check for skullowner tag rewrite Fixes #199 --- .../packets/BlockItemPackets1_16.java | 22 +++++++++---------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/core/src/main/java/nl/matsv/viabackwards/protocol/protocol1_15_2to1_16/packets/BlockItemPackets1_16.java b/core/src/main/java/nl/matsv/viabackwards/protocol/protocol1_15_2to1_16/packets/BlockItemPackets1_16.java index 4240e095..2811d234 100644 --- a/core/src/main/java/nl/matsv/viabackwards/protocol/protocol1_15_2to1_16/packets/BlockItemPackets1_16.java +++ b/core/src/main/java/nl/matsv/viabackwards/protocol/protocol1_15_2to1_16/packets/BlockItemPackets1_16.java @@ -157,10 +157,8 @@ public class BlockItemPackets1_16 extends nl.matsv.viabackwards.api.rewriters.It // Target -> target_uuid UUID targetUuid = UUIDIntArrayType.uuidFromIntArray(targetUuidTag.getValue()); blockEntity.put(new StringTag("target_uuid", targetUuid.toString())); - } else if (id.equals("minecraft:skull")) { + } else if (id.equals("minecraft:skull") && blockEntity.get("SkullOwner") instanceof CompoundTag) { CompoundTag skullOwnerTag = blockEntity.remove("SkullOwner"); - if (skullOwnerTag == null) continue; - IntArrayTag ownerUuidTag = skullOwnerTag.remove("Id"); UUID ownerUuid = UUIDIntArrayType.uuidFromIntArray(ownerUuidTag.getValue()); skullOwnerTag.put(new StringTag("Id", ownerUuid.toString())); @@ -218,12 +216,13 @@ public class BlockItemPackets1_16 extends nl.matsv.viabackwards.api.rewriters.It if (item.getIdentifier() == 771 && item.getTag() != null) { CompoundTag tag = item.getTag(); - CompoundTag ownerTag = tag.get("SkullOwner"); - if (ownerTag != null) { - Tag idTag = ownerTag.get("Id"); + Tag ownerTag = tag.get("SkullOwner"); + if (ownerTag instanceof CompoundTag) { + CompoundTag ownerCompundTag = (CompoundTag) ownerTag; + Tag idTag = ownerCompundTag.get("Id"); if (idTag instanceof IntArrayTag) { UUID ownerUuid = UUIDIntArrayType.uuidFromIntArray((int[]) idTag.getValue()); - ownerTag.put(new StringTag("Id", ownerUuid.toString())); + ownerCompundTag.put(new StringTag("Id", ownerUuid.toString())); } } } @@ -239,12 +238,13 @@ public class BlockItemPackets1_16 extends nl.matsv.viabackwards.api.rewriters.It if (identifier == 771 && item.getTag() != null) { CompoundTag tag = item.getTag(); - CompoundTag ownerTag = tag.get("SkullOwner"); - if (ownerTag != null) { - Tag idTag = ownerTag.get("Id"); + Tag ownerTag = tag.get("SkullOwner"); + if (ownerTag instanceof CompoundTag) { + CompoundTag ownerCompundTag = (CompoundTag) ownerTag; + Tag idTag = ownerCompundTag.get("Id"); if (idTag instanceof StringTag) { UUID ownerUuid = UUID.fromString((String) idTag.getValue()); - ownerTag.put(new IntArrayTag("Id", UUIDIntArrayType.uuidToIntArray(ownerUuid))); + ownerCompundTag.put(new IntArrayTag("Id", UUIDIntArrayType.uuidToIntArray(ownerUuid))); } } }