Skip to content

Commit 12f3262

Browse files
committed
Re-use existing name/uuid from old profile when applying new skin
1 parent 5e18125 commit 12f3262

2 files changed

Lines changed: 14 additions & 4 deletions

File tree

spigot/src/main/java/org/geysermc/floodgate/pluginmessage/SpigotSkinApplier.java

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ private void applySkin0(FloodgatePlayer floodgatePlayer, SkinData skinData, bool
8787
}
8888

8989
if (ClassNames.GAME_PROFILE_FIELD != null) {
90-
replaceSkin(player, floodgatePlayer, event.newSkin());
90+
replaceSkin(player, profile, event.newSkin());
9191
} else {
9292
// We're on a version with mutable GameProfiles
9393
replaceSkinOld(profile.getProperties(), event.newSkin());
@@ -102,10 +102,9 @@ private void applySkin0(FloodgatePlayer floodgatePlayer, SkinData skinData, bool
102102
});
103103
}
104104

105-
private void replaceSkin(Player player, FloodgatePlayer floodgatePlayer, SkinData skinData) {
105+
private void replaceSkin(Player player, GameProfile oldProfile, SkinData skinData) {
106106
Property skinProperty = new Property("textures", skinData.value(), skinData.signature());
107-
GameProfile profile = versionSpecificMethods.createGameProfile(floodgatePlayer.getCorrectUniqueId(),
108-
floodgatePlayer.getCorrectUsername(), skinProperty);
107+
GameProfile profile = versionSpecificMethods.createGameProfile(oldProfile, skinProperty);
109108
Object entityHuman = ReflectionUtils.invoke(player, ClassNames.GET_ENTITY_HUMAN_METHOD);
110109
ReflectionUtils.setValue(entityHuman, ClassNames.GAME_PROFILE_FIELD, profile);
111110
}

spigot/src/main/java/org/geysermc/floodgate/util/SpigotVersionSpecificMethods.java

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
import com.mojang.authlib.properties.Property;
3030
import com.mojang.authlib.properties.PropertyMap;
3131
import java.lang.reflect.Constructor;
32+
import java.lang.reflect.Field;
3233
import java.lang.reflect.Method;
3334
import java.util.HashMap;
3435
import java.util.Map;
@@ -51,6 +52,8 @@ public final class SpigotVersionSpecificMethods {
5152
private static final Constructor<GameProfile> RECORD_GAME_PROFILE_CONSTRUCTOR;
5253
private static final Constructor<PropertyMap> IMMUTABLE_PROPERTY_MAP_CONSTRUCTOR;
5354
private static final Method MULTIMAP_FROM_MAP;
55+
private static final Field PROFILE_NAME_FIELD;
56+
private static final Field PROFILE_UUID_FIELD;
5457

5558
static {
5659
GET_SPIGOT = ReflectionUtils.getMethod(Player.class, "spigot");
@@ -69,6 +72,8 @@ public final class SpigotVersionSpecificMethods {
6972
GameProfile.class, true, UUID.class, String.class, PropertyMap.class);
7073
IMMUTABLE_PROPERTY_MAP_CONSTRUCTOR = (Constructor<PropertyMap>)
7174
PropertyMap.class.getConstructors()[0];
75+
PROFILE_NAME_FIELD = ReflectionUtils.getField(GameProfile.class, "name");
76+
PROFILE_UUID_FIELD = ReflectionUtils.getField(GameProfile.class, "id");
7277
// Avoid relocation for this class.
7378
Class<?> multimaps = ReflectionUtils.getClass(String.join(".", "com",
7479
"google", "common", "collect", "Multimaps"));
@@ -81,6 +86,12 @@ public SpigotVersionSpecificMethods(SpigotPlugin plugin) {
8186
this.plugin = plugin;
8287
}
8388

89+
public GameProfile createGameProfile(GameProfile oldProfile, Property textureProperty) {
90+
String name = (String) ReflectionUtils.getValue(oldProfile, PROFILE_NAME_FIELD);
91+
UUID uuid = (UUID) ReflectionUtils.getValue(oldProfile, PROFILE_UUID_FIELD);
92+
return createGameProfile(uuid, name, textureProperty);
93+
}
94+
8495
public GameProfile createGameProfile(UUID uuid, String name, Property texturesProperty) {
8596
if (RECORD_GAME_PROFILE_CONSTRUCTOR != null && IMMUTABLE_PROPERTY_MAP_CONSTRUCTOR != null) {
8697
if (texturesProperty != null) {

0 commit comments

Comments
 (0)