diff --git a/api/src/main/java/com/viaversion/viaversion/api/type/types/minecraft/NBTType.java b/api/src/main/java/com/viaversion/viaversion/api/type/types/minecraft/NBTType.java index e4d632533..a281d953d 100644 --- a/api/src/main/java/com/viaversion/viaversion/api/type/types/minecraft/NBTType.java +++ b/api/src/main/java/com/viaversion/viaversion/api/type/types/minecraft/NBTType.java @@ -28,9 +28,8 @@ import com.viaversion.viaversion.api.type.Type; import io.netty.buffer.ByteBuf; import io.netty.buffer.ByteBufInputStream; import io.netty.buffer.ByteBufOutputStream; -import org.checkerframework.checker.nullness.qual.Nullable; - import java.io.IOException; +import org.checkerframework.checker.nullness.qual.Nullable; public class NBTType extends Type { @@ -42,37 +41,31 @@ public class NBTType extends Type { } @Override - public CompoundTag read(ByteBuf buffer) throws Exception { + public CompoundTag read(final ByteBuf buffer) throws Exception { return read(buffer, true); } @Override - public void write(ByteBuf buffer, CompoundTag object) throws Exception { + public void write(final ByteBuf buffer, final CompoundTag object) throws Exception { write(buffer, object, ""); } public static CompoundTag read(final ByteBuf buffer, final boolean readName) throws Exception { - final int readerIndex = buffer.readerIndex(); - final byte b = buffer.readByte(); - if (b == 0) { + final byte id = buffer.readByte(); + if (id == 0) { return null; } - - buffer.readerIndex(readerIndex); - - final ByteBufInputStream in = new ByteBufInputStream(buffer); - final int id = in.readByte(); if (id != CompoundTag.ID) { throw new IOException(String.format("Expected root tag to be a CompoundTag, was %s", id)); } if (readName) { - in.skipBytes(in.readUnsignedShort()); + buffer.skipBytes(buffer.readUnsignedShort()); } final TagLimiter tagLimiter = TagLimiter.create(MAX_NBT_BYTES, MAX_NESTING_LEVEL); final CompoundTag tag = new CompoundTag(); - tag.read(in, tagLimiter); + tag.read(new ByteBufInputStream(buffer), tagLimiter); return tag; } diff --git a/common/src/main/java/com/viaversion/viaversion/protocols/protocol1_20_2to1_20/Protocol1_20_2To1_20.java b/common/src/main/java/com/viaversion/viaversion/protocols/protocol1_20_2to1_20/Protocol1_20_2To1_20.java index 3641af07b..406396b48 100644 --- a/common/src/main/java/com/viaversion/viaversion/protocols/protocol1_20_2to1_20/Protocol1_20_2To1_20.java +++ b/common/src/main/java/com/viaversion/viaversion/protocols/protocol1_20_2to1_20/Protocol1_20_2To1_20.java @@ -49,9 +49,8 @@ import com.viaversion.viaversion.protocols.protocol1_20_2to1_20.storage.Configur import com.viaversion.viaversion.protocols.protocol1_20_2to1_20.storage.ConfigurationState.BridgePhase; import com.viaversion.viaversion.protocols.protocol1_20_2to1_20.storage.LastResourcePack; import com.viaversion.viaversion.rewriter.SoundRewriter; -import org.checkerframework.checker.nullness.qual.Nullable; - import java.util.UUID; +import org.checkerframework.checker.nullness.qual.Nullable; public final class Protocol1_20_2To1_20 extends AbstractProtocol { @@ -120,6 +119,9 @@ public final class Protocol1_20_2To1_20 extends AbstractProtocol { wrapper.cancel(); + // Overwrite the state set in the base protocol to what the server actually keeps sending + wrapper.user().getProtocolInfo().setServerState(State.PLAY); + final ConfigurationState configurationState = wrapper.user().get(ConfigurationState.class); configurationState.setBridgePhase(BridgePhase.CONFIGURATION); configurationState.sendQueuedPackets(wrapper.user()); @@ -198,7 +200,6 @@ public final class Protocol1_20_2To1_20 extends AbstractProtocol