Add safety checks to skullowner conversion

This commit is contained in:
KennyTV 2020-04-17 21:02:51 +02:00
parent 0f90efa05f
commit c956f23def
No known key found for this signature in database
GPG Key ID: 6BE3B555EBC5982B
2 changed files with 22 additions and 14 deletions

View File

@ -3,6 +3,7 @@ package us.myles.ViaVersion.protocols.protocol1_16to1_15_2.packets;
import com.github.steveice10.opennbt.tag.builtin.CompoundTag;
import com.github.steveice10.opennbt.tag.builtin.IntArrayTag;
import com.github.steveice10.opennbt.tag.builtin.StringTag;
import com.github.steveice10.opennbt.tag.builtin.Tag;
import us.myles.ViaVersion.api.Via;
import us.myles.ViaVersion.api.minecraft.item.Item;
import us.myles.ViaVersion.api.protocol.Protocol;
@ -140,10 +141,14 @@ public class InventoryPackets {
if (item.getIdentifier() == 771 && item.getTag() != null) {
CompoundTag tag = item.getTag();
CompoundTag ownerTag = tag.get("SkullOwner");
if (ownerTag != null) {
UUID id = UUID.fromString(((StringTag) ownerTag.get("Id")).getValue());
ownerTag.put(new IntArrayTag("Id", UUIDIntArrayType.uuidToIntArray(id)));
Tag ownerTag = tag.get("SkullOwner");
if (ownerTag instanceof CompoundTag) {
CompoundTag ownerCompundTag = (CompoundTag) ownerTag;
Tag idTag = ownerCompundTag.get("Id");
if (idTag instanceof StringTag) {
UUID id = UUID.fromString((String) idTag.getValue());
ownerCompundTag.put(new IntArrayTag("Id", UUIDIntArrayType.uuidToIntArray(id)));
}
}
}
@ -157,10 +162,14 @@ public class InventoryPackets {
if (item.getIdentifier() == 771 && item.getTag() != null) {
CompoundTag tag = item.getTag();
CompoundTag ownerTag = tag.get("SkullOwner");
if (ownerTag != null && ownerTag.contains("Id")) {
UUID id = UUIDIntArrayType.uuidFromIntArray(((IntArrayTag) ownerTag.get("Id")).getValue());
ownerTag.put(new StringTag("Id", id.toString()));
Tag ownerTag = tag.get("SkullOwner");
if (ownerTag instanceof CompoundTag) {
CompoundTag ownerCompundTag = (CompoundTag) ownerTag;
Tag idTag = ownerCompundTag.get("Id");
if (idTag instanceof IntArrayTag) {
UUID id = UUIDIntArrayType.uuidFromIntArray((int[]) idTag.getValue());
ownerCompundTag.put(new StringTag("Id", id.toString()));
}
}
}
}

View File

@ -61,17 +61,16 @@ public class WorldPackets {
StringTag targetUuidTag = blockEntity.remove("target_uuid");
if (targetUuidTag == null) continue;
// target_uuid -> Target
UUID targetUuid = UUID.fromString(targetUuidTag.getValue());
blockEntity.put(new IntArrayTag("Target", UUIDIntArrayType.uuidToIntArray(targetUuid)));
} else if (id.equals("minecraft:skull")) {
} else if (id.equals("minecraft:skull") && blockEntity.get("Owner") instanceof CompoundTag) {
CompoundTag ownerTag = blockEntity.remove("Owner");
if (ownerTag == null) continue;
StringTag ownerUuidTag = ownerTag.remove("Id");
UUID ownerUuid = UUID.fromString(ownerUuidTag.getValue());
ownerTag.put(new IntArrayTag("Id", UUIDIntArrayType.uuidToIntArray(ownerUuid)));
if (ownerUuidTag != null) {
UUID ownerUuid = UUID.fromString(ownerUuidTag.getValue());
ownerTag.put(new IntArrayTag("Id", UUIDIntArrayType.uuidToIntArray(ownerUuid)));
}
// Owner -> SkullOwner
CompoundTag skullOwnerTag = new CompoundTag("SkullOwner");