Skip to content

Commit 359ef25

Browse files
authored
Fixed modern forwarding support (#4234)
* fix: Fixed modern forwarding support * fix: Fixed another immutability issue
1 parent a18ae55 commit 359ef25

File tree

2 files changed

+16
-8
lines changed

2 files changed

+16
-8
lines changed

src/main/java/org/spongepowered/common/ipforward/velocity/VelocityForwardingInfo.java

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -24,9 +24,11 @@
2424
*/
2525
package org.spongepowered.common.ipforward.velocity;
2626

27+
import com.google.common.collect.ImmutableMultimap;
2728
import com.google.common.net.InetAddresses;
2829
import com.mojang.authlib.GameProfile;
2930
import com.mojang.authlib.properties.Property;
31+
import com.mojang.authlib.properties.PropertyMap;
3032
import io.netty.buffer.ByteBuf;
3133
import net.kyori.adventure.text.Component;
3234
import net.minecraft.network.Connection;
@@ -135,18 +137,20 @@ public static InetAddress readAddress(final ChannelBuf buf) {
135137
}
136138

137139
public static GameProfile createProfile(final ChannelBuf buf) {
138-
final GameProfile profile = new GameProfile(buf.readUniqueId(), ((FriendlyByteBuf) buf).readUtf(16)); // TODO: ChannelBuf length-limited strings
139-
VelocityForwardingInfo.readProperties(buf, profile);
140-
return profile;
140+
// TODO: ChannelBuf length-limited strings
141+
return new GameProfile(buf.readUniqueId(), ((FriendlyByteBuf) buf).readUtf(16), VelocityForwardingInfo.readProperties(buf));
141142
}
142143

143-
private static void readProperties(final ChannelBuf buf, final GameProfile profile) {
144+
private static PropertyMap readProperties(final ChannelBuf buf) {
145+
final ImmutableMultimap.Builder<String, Property> propertiesBuilder = ImmutableMultimap.builder();
144146
final int properties = buf.readVarInt();
145147
for (int i1 = 0; i1 < properties; i1++) {
146148
final String name = buf.readString();
147149
final String value = buf.readString();
148150
final String signature = buf.readBoolean() ? buf.readString() : null;
149-
profile.properties().put(name, new Property(name, value, signature));
151+
propertiesBuilder.put(name, new Property(name, value, signature));
150152
}
153+
final ImmutableMultimap<String, Property> propertiesMap = propertiesBuilder.build();
154+
return new PropertyMap(propertiesMap);
151155
}
152156
}

src/main/java/org/spongepowered/common/profile/SpongeGameProfile.java

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,11 @@
2525
package org.spongepowered.common.profile;
2626

2727
import com.google.common.collect.ImmutableList;
28+
import com.google.common.collect.ImmutableMultimap;
2829
import com.google.gson.Gson;
2930
import com.google.gson.JsonObject;
31+
import com.mojang.authlib.properties.Property;
32+
import com.mojang.authlib.properties.PropertyMap;
3033
import net.minecraft.server.players.NameAndId;
3134
import org.checkerframework.checker.nullness.qual.NonNull;
3235
import org.checkerframework.checker.nullness.qual.Nullable;
@@ -148,11 +151,12 @@ public SpongeGameProfile(final UUID uniqueId, final @Nullable String name, final
148151
public com.mojang.authlib.GameProfile toMcProfile() {
149152
final UUID uniqueId = this.uniqueId;
150153
final String name = (this.name == null) ? "" : this.name;
151-
final com.mojang.authlib.GameProfile mcProfile = new com.mojang.authlib.GameProfile(uniqueId, name);
154+
final ImmutableMultimap.Builder<String, Property> propertyBuilder = ImmutableMultimap.builder();
152155
for (final SpongeProfileProperty property : this.properties) {
153-
mcProfile.properties().put(property.name(), property.asProperty());
156+
propertyBuilder.put(property.name(), property.asProperty());
154157
}
155-
return mcProfile;
158+
final PropertyMap propertyMap = new PropertyMap(propertyBuilder.build());
159+
return new com.mojang.authlib.GameProfile(uniqueId, name, propertyMap);
156160
}
157161

158162
@Override

0 commit comments

Comments
 (0)