diff --git a/proxy/src/main/java/com/velocitypowered/proxy/connection/registry/DimensionRegistry.java b/proxy/src/main/java/com/velocitypowered/proxy/connection/registry/DimensionRegistry.java index 9e5f1af62..4122d09e3 100644 --- a/proxy/src/main/java/com/velocitypowered/proxy/connection/registry/DimensionRegistry.java +++ b/proxy/src/main/java/com/velocitypowered/proxy/connection/registry/DimensionRegistry.java @@ -93,7 +93,7 @@ public final class DimensionRegistry { * Decodes a CompoundTag storing a dimension registry. * @param toParse CompoundTag containing a dimension registry */ - public static Set fromGameData(CompoundTag toParse) { + public static ImmutableSet fromGameData(CompoundTag toParse) { Preconditions.checkNotNull(toParse, "CompoundTag cannot be null"); Preconditions.checkArgument(toParse.contains("dimension", TagType.LIST), "CompoundTag does not contain a dimension list"); diff --git a/proxy/src/main/java/com/velocitypowered/proxy/protocol/packet/JoinGame.java b/proxy/src/main/java/com/velocitypowered/proxy/protocol/packet/JoinGame.java index 3e1bfe5a6..d000320ac 100644 --- a/proxy/src/main/java/com/velocitypowered/proxy/protocol/packet/JoinGame.java +++ b/proxy/src/main/java/com/velocitypowered/proxy/protocol/packet/JoinGame.java @@ -1,7 +1,9 @@ package com.velocitypowered.proxy.protocol.packet; +import com.google.common.collect.ImmutableSet; import com.velocitypowered.api.network.ProtocolVersion; import com.velocitypowered.proxy.connection.MinecraftSessionHandler; +import com.velocitypowered.proxy.connection.registry.DimensionData; import com.velocitypowered.proxy.connection.registry.DimensionInfo; import com.velocitypowered.proxy.connection.registry.DimensionRegistry; import com.velocitypowered.proxy.protocol.*; @@ -134,8 +136,9 @@ public class JoinGame implements MinecraftPacket { String dimensionIdentifier = null; String levelName = null; if (version.compareTo(ProtocolVersion.MINECRAFT_1_16) >= 0) { - String levelNames[] = ProtocolUtils.readStringArray(buf); - this.dimensionRegistry = DimensionRegistry.fromGameData(ProtocolUtils.readCompoundTag(buf), levelNames); + ImmutableSet levelNames = ImmutableSet.copyOf(ProtocolUtils.readStringArray(buf)); + ImmutableSet readData = DimensionRegistry.fromGameData(ProtocolUtils.readCompoundTag(buf)); + this.dimensionRegistry = new DimensionRegistry(readData, levelNames); dimensionIdentifier = ProtocolUtils.readString(buf); levelName = ProtocolUtils.readString(buf); } else if (version.compareTo(ProtocolVersion.MINECRAFT_1_9_1) >= 0) { @@ -174,7 +177,8 @@ public class JoinGame implements MinecraftPacket { buf.writeInt(entityId); buf.writeByte(gamemode); if (version.compareTo(ProtocolVersion.MINECRAFT_1_16) >= 0) { - ProtocolUtils.writeStringArray(buf, dimensionRegistry.getLevelNames()); + ProtocolUtils.writeStringArray(buf, dimensionRegistry.getLevelNames().toArray( + new String[dimensionRegistry.getLevelNames().size()])); ProtocolUtils.writeCompoundTag(buf, dimensionRegistry.encodeRegistry()); ProtocolUtils.writeString(buf, dimensionInfo.getRegistryIdentifier()); ProtocolUtils.writeString(buf, dimensionInfo.getLevelName());