Skip to content

Commit 08033b0

Browse files
authored
Fix an issue where incorrect skins were loaded in multiplayer mode. (#364)
* Fix an issue where incorrect skins were loaded in multiplayer mode. * Restore the mistakenly deleted GAME_PROFILE_ID.
1 parent 4cffdc3 commit 08033b0

4 files changed

Lines changed: 27 additions & 46 deletions

File tree

Common/src/main/java/customskinloader/loader/GameProfileLoader.java

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -61,11 +61,12 @@ public void updateSkinSiteProfile(SkinSiteProfile ssp) {
6161

6262
@Override
6363
public UserProfile loadProfile(SkinSiteProfile ssp, GameProfile gameProfile) throws Exception {
64-
Map<MinecraftProfileTexture.Type, MinecraftProfileTexture> map = getTextures(gameProfile);
64+
Map<MinecraftProfileTexture.Type, MinecraftProfileTexture> map = getTextures(Iterables.getFirst(TextureUtil.AuthlibField.GAME_PROFILE_PROPERTIES.<PropertyMap>get(gameProfile).get("textures"), null));
6565
if (!map.isEmpty()) {
6666
CustomSkinLoader.logger.info("Default profile will be used.");
6767
return ModelManager0.toUserProfile(map);
6868
}
69+
CustomSkinLoader.logger.info("Profile not found.");
6970
return null;
7071
}
7172

@@ -85,11 +86,7 @@ public void init(SkinSiteProfile ssp) {
8586
}
8687

8788
public static final Gson GSON = new GsonBuilder().registerTypeAdapter(UUID.class, new UUIDTypeAdapter()).registerTypeAdapter(PropertyMap.class, new PropertyMap.Serializer()).create();
88-
public static Map<MinecraftProfileTexture.Type, MinecraftProfileTexture> getTextures(GameProfile gameProfile) {
89-
if (gameProfile == null) {
90-
return Maps.newHashMap();
91-
}
92-
Property textureProperty = Iterables.getFirst(TextureUtil.AuthlibField.GAME_PROFILE_PROPERTIES.<PropertyMap>get(gameProfile).get("textures"), null);
89+
public static Map<MinecraftProfileTexture.Type, MinecraftProfileTexture> getTextures(Property textureProperty) {
9390
if (textureProperty == null) {
9491
return Maps.newHashMap();
9592
}

Common/src/main/java/customskinloader/loader/MojangAPILoader.java

Lines changed: 19 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
import java.util.UUID;
77
import java.util.concurrent.ConcurrentHashMap;
88

9+
import com.google.common.collect.Iterables;
910
import com.google.common.collect.Lists;
1011
import com.mojang.authlib.GameProfile;
1112
import com.mojang.authlib.minecraft.MinecraftProfileTexture;
@@ -80,28 +81,30 @@ public String getSessionRoot() {
8081
@Override
8182
public UserProfile loadProfile(SkinSiteProfile ssp, GameProfile gameProfile) {
8283
String username = TextureUtil.AuthlibField.GAME_PROFILE_NAME.get(gameProfile);
83-
GameProfile newGameProfile = loadGameProfileCached(ssp.apiRoot, username);
84-
if (newGameProfile == null) {
84+
MinecraftProfilePropertiesResponse newProfile = loadGameProfileCached(ssp.apiRoot, username);
85+
if (newProfile == null) {
8586
CustomSkinLoader.logger.info("Profile not found.(" + username + "'s profile not found.)");
8687
return null;
8788
}
88-
newGameProfile = fillGameProfile(ssp.sessionRoot, newGameProfile);
89-
Map<MinecraftProfileTexture.Type, MinecraftProfileTexture> map = GameProfileLoader.getTextures(newGameProfile);
90-
if (!map.isEmpty()) {
91-
return ModelManager0.toUserProfile(map);
89+
PropertyMap propertyMap = TextureUtil.AuthlibField.MINECRAFT_PROFILE_PROPERTIES_RESPONSE_PROPERTIES.get(fillProfile(ssp.sessionRoot, newProfile));
90+
if (propertyMap != null) {
91+
Map<MinecraftProfileTexture.Type, MinecraftProfileTexture> map = GameProfileLoader.getTextures(Iterables.getFirst(propertyMap.get("textures"), null));
92+
if (!map.isEmpty()) {
93+
return ModelManager0.toUserProfile(map);
94+
}
9295
}
9396
CustomSkinLoader.logger.info("Profile not found.(" + username + " doesn't have skin/cape.)");
9497
return null;
9598
}
9699

97-
private static final Map<String, GameProfile> gameProfileCache = new ConcurrentHashMap<>();
100+
private static final Map<String, MinecraftProfilePropertiesResponse> gameProfileCache = new ConcurrentHashMap<>();
98101

99-
public static GameProfile loadGameProfileCached(String apiRoot, String username) {
102+
public static MinecraftProfilePropertiesResponse loadGameProfileCached(String apiRoot, String username) {
100103
return gameProfileCache.computeIfAbsent(apiRoot + " " + username, ignored -> loadGameProfile(apiRoot, username));
101104
}
102105

103106
//Username -> UUID
104-
public static GameProfile loadGameProfile(String apiRoot, String username) {
107+
public static MinecraftProfilePropertiesResponse loadGameProfile(String apiRoot, String username) {
105108
//Doc (https://minecraft.wiki/w/Mojang_API#Query_player_UUIDs_in_batch)
106109
HttpRequestUtil.HttpResponce responce = HttpRequestUtil.makeHttpRequest(new HttpRequestUtil.HttpRequest(apiRoot + "profiles/minecraft").setCacheTime(600).setPayload(GameProfileLoader.GSON.toJson(Collections.singletonList(username))));
107110
if (StringUtils.isEmpty(responce.content)) {
@@ -112,13 +115,12 @@ public static GameProfile loadGameProfile(String apiRoot, String username) {
112115
if (profiles.length == 0) {
113116
return null;
114117
}
115-
GameProfile gameProfile = createGameProfile(profiles[0]);
116118

117-
UUID id = TextureUtil.AuthlibField.GAME_PROFILE_ID.get(gameProfile);
119+
UUID id = TextureUtil.AuthlibField.MINECRAFT_PROFILE_PROPERTIES_RESPONSE_ID.get(profiles[0]);
118120
if (id == null) {
119121
return null;
120122
}
121-
return new GameProfile(id, TextureUtil.AuthlibField.GAME_PROFILE_NAME.get(gameProfile));
123+
return profiles[0];
122124
}
123125

124126
/**
@@ -129,31 +131,22 @@ public static GameProfile loadGameProfile(String apiRoot, String username) {
129131
* @return UUID in Mojang API style string. Returns {@code null} if username not found in Mojang API.
130132
*/
131133
public static String getMojangUuidByUsername(String username, boolean standard) {
132-
GameProfile profile = loadGameProfileCached(getMojangApiRoot(), username);
134+
MinecraftProfilePropertiesResponse profile = loadGameProfileCached(getMojangApiRoot(), username);
133135
if (profile == null) {
134136
return null;
135137
}
136-
UUID id = TextureUtil.AuthlibField.GAME_PROFILE_ID.get(profile);
138+
UUID id = TextureUtil.AuthlibField.MINECRAFT_PROFILE_PROPERTIES_RESPONSE_ID.get(profile);
137139
return standard ? id.toString() : TextureUtil.fromUUID(id);
138140
}
139141

140142
//UUID -> Profile
141-
public static GameProfile fillGameProfile(String sessionRoot, GameProfile profile) {
143+
public static MinecraftProfilePropertiesResponse fillProfile(String sessionRoot, MinecraftProfilePropertiesResponse profile) {
142144
//Doc (https://minecraft.wiki/w/Mojang_API#Query_player's_skin_and_cape)
143-
HttpRequestUtil.HttpResponce responce = HttpRequestUtil.makeHttpRequest(new HttpRequestUtil.HttpRequest(sessionRoot + "session/minecraft/profile/" + TextureUtil.fromUUID(TextureUtil.AuthlibField.GAME_PROFILE_ID.get(profile))).setCacheTime(90));
145+
HttpRequestUtil.HttpResponce responce = HttpRequestUtil.makeHttpRequest(new HttpRequestUtil.HttpRequest(sessionRoot + "session/minecraft/profile/" + TextureUtil.fromUUID(TextureUtil.AuthlibField.MINECRAFT_PROFILE_PROPERTIES_RESPONSE_ID.get(profile))).setCacheTime(90));
144146
if (StringUtils.isEmpty(responce.content)) {
145147
return profile;
146148
}
147-
return createGameProfile(GameProfileLoader.GSON.fromJson(responce.content, MinecraftProfilePropertiesResponse.class));
148-
}
149-
150-
public static GameProfile createGameProfile(MinecraftProfilePropertiesResponse response) {
151-
GameProfile profile = new GameProfile(TextureUtil.AuthlibField.MINECRAFT_PROFILE_PROPERTIES_RESPONSE_ID.get(response), TextureUtil.AuthlibField.MINECRAFT_PROFILE_PROPERTIES_RESPONSE_NAME.get(response));
152-
PropertyMap map = TextureUtil.AuthlibField.MINECRAFT_PROFILE_PROPERTIES_RESPONSE_PROPERTIES.get(response);
153-
if (map != null) {
154-
TextureUtil.AuthlibField.PROPERTY_MAP_PROPERTIES.set(TextureUtil.AuthlibField.GAME_PROFILE_PROPERTIES.get(profile), TextureUtil.AuthlibField.PROPERTY_MAP_PROPERTIES.get(map));
155-
}
156-
return profile;
149+
return GameProfileLoader.GSON.fromJson(responce.content, MinecraftProfilePropertiesResponse.class);
157150
}
158151

159152
@Override

Common/src/main/java/customskinloader/loader/jsonapi/MinecraftCapesAPI.java

Lines changed: 5 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
import com.google.common.collect.Lists;
44
import com.google.gson.Gson;
55

6+
import com.google.gson.annotations.SerializedName;
67
import customskinloader.loader.JsonAPILoader;
78
import customskinloader.loader.MojangAPILoader;
89
import customskinloader.plugin.ICustomSkinLoaderPlugin;
@@ -53,12 +54,12 @@ public String toJsonUrl(String root, String username) {
5354
@Override
5455
public UserProfile toUserProfile(String root, String json, boolean local) {
5556
MinecraftCapesApiResponse result = new Gson().fromJson(json, MinecraftCapesApiResponse.class);
56-
if (result.textures == null || result.textures.cape == null) {
57+
if (result.capeUrl == null) {
5758
return null;
5859
}
5960

6061
UserProfile profile = new UserProfile();
61-
profile.capeUrl = TextureUtil.parseBase64Texture(result.textures.cape);
62+
profile.capeUrl = result.capeUrl;
6263

6364
return profile;
6465
}
@@ -69,14 +70,7 @@ public String getName() {
6970
}
7071

7172
public static class MinecraftCapesApiResponse {
72-
public boolean animatedCape;
73-
public boolean capeGlint;
74-
public boolean upsideDown;
75-
public MinecraftCapesApiTexture textures;
76-
77-
public static class MinecraftCapesApiTexture {
78-
public String cape;
79-
public String ears;
80-
}
73+
@SerializedName("cape_url")
74+
public String capeUrl;
8175
}
8276
}

Common/src/main/java/customskinloader/utils/TextureUtil.java

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66

77
import com.mojang.authlib.GameProfile;
88
import com.mojang.authlib.properties.Property;
9-
import com.mojang.authlib.properties.PropertyMap;
109
import com.mojang.authlib.yggdrasil.response.MinecraftProfilePropertiesResponse;
1110
import com.mojang.authlib.yggdrasil.response.MinecraftTexturesPayload;
1211
import customskinloader.CustomSkinLoader;
@@ -45,9 +44,7 @@ public enum AuthlibField {
4544
GAME_PROFILE_NAME(GameProfile.class, "name"),
4645
GAME_PROFILE_PROPERTIES(GameProfile.class, "properties"),
4746
PROPERTY_VALUE(Property.class, "value"),
48-
PROPERTY_MAP_PROPERTIES(PropertyMap.class, "properties"),
4947
MINECRAFT_PROFILE_PROPERTIES_RESPONSE_ID(MinecraftProfilePropertiesResponse.class, "id"),
50-
MINECRAFT_PROFILE_PROPERTIES_RESPONSE_NAME(MinecraftProfilePropertiesResponse.class, "name"),
5148
MINECRAFT_PROFILE_PROPERTIES_RESPONSE_PROPERTIES(MinecraftProfilePropertiesResponse.class, "properties"),
5249
MINECRAFT_TEXTURES_PAYLOAD_TEXTURES(MinecraftTexturesPayload.class, "textures");
5350

0 commit comments

Comments
 (0)