mirror of
https://github.com/xfl03/MCCustomSkinLoader.git
synced 2026-11-18 17:19:15 +00:00
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.
This commit is contained in:
1 parent
4cffdc3eb6
commit
08033b0502
4 files changed
+27
-46
No files matched your search
@@ -61,11 +61,12 @@ public class GameProfileLoader implements ICustomSkinLoaderPlugin, ProfileLoader
|
||||
|
||||
@Override
|
||||
public UserProfile loadProfile(SkinSiteProfile ssp, GameProfile gameProfile) throws Exception {
|
||||
Map<MinecraftProfileTexture.Type, MinecraftProfileTexture> map = getTextures(gameProfile);
|
||||
Map<MinecraftProfileTexture.Type, MinecraftProfileTexture> map = getTextures(Iterables.getFirst(TextureUtil.AuthlibField.GAME_PROFILE_PROPERTIES.<PropertyMap>get(gameProfile).get("textures"), null));
|
||||
if (!map.isEmpty()) {
|
||||
CustomSkinLoader.logger.info("Default profile will be used.");
|
||||
return ModelManager0.toUserProfile(map);
|
||||
}
|
||||
CustomSkinLoader.logger.info("Profile not found.");
|
||||
return null;
|
||||
}
|
||||
|
||||
@@ -85,11 +86,7 @@ public class GameProfileLoader implements ICustomSkinLoaderPlugin, ProfileLoader
|
||||
}
|
||||
|
||||
public static final Gson GSON = new GsonBuilder().registerTypeAdapter(UUID.class, new UUIDTypeAdapter()).registerTypeAdapter(PropertyMap.class, new PropertyMap.Serializer()).create();
|
||||
public static Map<MinecraftProfileTexture.Type, MinecraftProfileTexture> getTextures(GameProfile gameProfile) {
|
||||
if (gameProfile == null) {
|
||||
return Maps.newHashMap();
|
||||
}
|
||||
Property textureProperty = Iterables.getFirst(TextureUtil.AuthlibField.GAME_PROFILE_PROPERTIES.<PropertyMap>get(gameProfile).get("textures"), null);
|
||||
public static Map<MinecraftProfileTexture.Type, MinecraftProfileTexture> getTextures(Property textureProperty) {
|
||||
if (textureProperty == null) {
|
||||
return Maps.newHashMap();
|
||||
}
|
||||
|
||||
@@ -6,6 +6,7 @@ import java.util.Map;
|
||||
import java.util.UUID;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
|
||||
import com.google.common.collect.Iterables;
|
||||
import com.google.common.collect.Lists;
|
||||
import com.mojang.authlib.GameProfile;
|
||||
import com.mojang.authlib.minecraft.MinecraftProfileTexture;
|
||||
@@ -80,28 +81,30 @@ public class MojangAPILoader implements ICustomSkinLoaderPlugin, ProfileLoader.I
|
||||
@Override
|
||||
public UserProfile loadProfile(SkinSiteProfile ssp, GameProfile gameProfile) {
|
||||
String username = TextureUtil.AuthlibField.GAME_PROFILE_NAME.get(gameProfile);
|
||||
GameProfile newGameProfile = loadGameProfileCached(ssp.apiRoot, username);
|
||||
if (newGameProfile == null) {
|
||||
MinecraftProfilePropertiesResponse newProfile = loadGameProfileCached(ssp.apiRoot, username);
|
||||
if (newProfile == null) {
|
||||
CustomSkinLoader.logger.info("Profile not found.(" + username + "'s profile not found.)");
|
||||
return null;
|
||||
}
|
||||
newGameProfile = fillGameProfile(ssp.sessionRoot, newGameProfile);
|
||||
Map<MinecraftProfileTexture.Type, MinecraftProfileTexture> map = GameProfileLoader.getTextures(newGameProfile);
|
||||
if (!map.isEmpty()) {
|
||||
return ModelManager0.toUserProfile(map);
|
||||
PropertyMap propertyMap = TextureUtil.AuthlibField.MINECRAFT_PROFILE_PROPERTIES_RESPONSE_PROPERTIES.get(fillProfile(ssp.sessionRoot, newProfile));
|
||||
if (propertyMap != null) {
|
||||
Map<MinecraftProfileTexture.Type, MinecraftProfileTexture> map = GameProfileLoader.getTextures(Iterables.getFirst(propertyMap.get("textures"), null));
|
||||
if (!map.isEmpty()) {
|
||||
return ModelManager0.toUserProfile(map);
|
||||
}
|
||||
}
|
||||
CustomSkinLoader.logger.info("Profile not found.(" + username + " doesn't have skin/cape.)");
|
||||
return null;
|
||||
}
|
||||
|
||||
private static final Map<String, GameProfile> gameProfileCache = new ConcurrentHashMap<>();
|
||||
private static final Map<String, MinecraftProfilePropertiesResponse> gameProfileCache = new ConcurrentHashMap<>();
|
||||
|
||||
public static GameProfile loadGameProfileCached(String apiRoot, String username) {
|
||||
public static MinecraftProfilePropertiesResponse loadGameProfileCached(String apiRoot, String username) {
|
||||
return gameProfileCache.computeIfAbsent(apiRoot + " " + username, ignored -> loadGameProfile(apiRoot, username));
|
||||
}
|
||||
|
||||
//Username -> UUID
|
||||
public static GameProfile loadGameProfile(String apiRoot, String username) {
|
||||
public static MinecraftProfilePropertiesResponse loadGameProfile(String apiRoot, String username) {
|
||||
//Doc (https://minecraft.wiki/w/Mojang_API#Query_player_UUIDs_in_batch)
|
||||
HttpRequestUtil.HttpResponce responce = HttpRequestUtil.makeHttpRequest(new HttpRequestUtil.HttpRequest(apiRoot + "profiles/minecraft").setCacheTime(600).setPayload(GameProfileLoader.GSON.toJson(Collections.singletonList(username))));
|
||||
if (StringUtils.isEmpty(responce.content)) {
|
||||
@@ -112,13 +115,12 @@ public class MojangAPILoader implements ICustomSkinLoaderPlugin, ProfileLoader.I
|
||||
if (profiles.length == 0) {
|
||||
return null;
|
||||
}
|
||||
GameProfile gameProfile = createGameProfile(profiles[0]);
|
||||
|
||||
UUID id = TextureUtil.AuthlibField.GAME_PROFILE_ID.get(gameProfile);
|
||||
UUID id = TextureUtil.AuthlibField.MINECRAFT_PROFILE_PROPERTIES_RESPONSE_ID.get(profiles[0]);
|
||||
if (id == null) {
|
||||
return null;
|
||||
}
|
||||
return new GameProfile(id, TextureUtil.AuthlibField.GAME_PROFILE_NAME.get(gameProfile));
|
||||
return profiles[0];
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -129,31 +131,22 @@ public class MojangAPILoader implements ICustomSkinLoaderPlugin, ProfileLoader.I
|
||||
* @return UUID in Mojang API style string. Returns {@code null} if username not found in Mojang API.
|
||||
*/
|
||||
public static String getMojangUuidByUsername(String username, boolean standard) {
|
||||
GameProfile profile = loadGameProfileCached(getMojangApiRoot(), username);
|
||||
MinecraftProfilePropertiesResponse profile = loadGameProfileCached(getMojangApiRoot(), username);
|
||||
if (profile == null) {
|
||||
return null;
|
||||
}
|
||||
UUID id = TextureUtil.AuthlibField.GAME_PROFILE_ID.get(profile);
|
||||
UUID id = TextureUtil.AuthlibField.MINECRAFT_PROFILE_PROPERTIES_RESPONSE_ID.get(profile);
|
||||
return standard ? id.toString() : TextureUtil.fromUUID(id);
|
||||
}
|
||||
|
||||
//UUID -> Profile
|
||||
public static GameProfile fillGameProfile(String sessionRoot, GameProfile profile) {
|
||||
public static MinecraftProfilePropertiesResponse fillProfile(String sessionRoot, MinecraftProfilePropertiesResponse profile) {
|
||||
//Doc (https://minecraft.wiki/w/Mojang_API#Query_player's_skin_and_cape)
|
||||
HttpRequestUtil.HttpResponce responce = HttpRequestUtil.makeHttpRequest(new HttpRequestUtil.HttpRequest(sessionRoot + "session/minecraft/profile/" + TextureUtil.fromUUID(TextureUtil.AuthlibField.GAME_PROFILE_ID.get(profile))).setCacheTime(90));
|
||||
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));
|
||||
if (StringUtils.isEmpty(responce.content)) {
|
||||
return profile;
|
||||
}
|
||||
return createGameProfile(GameProfileLoader.GSON.fromJson(responce.content, MinecraftProfilePropertiesResponse.class));
|
||||
}
|
||||
|
||||
public static GameProfile createGameProfile(MinecraftProfilePropertiesResponse response) {
|
||||
GameProfile profile = new GameProfile(TextureUtil.AuthlibField.MINECRAFT_PROFILE_PROPERTIES_RESPONSE_ID.get(response), TextureUtil.AuthlibField.MINECRAFT_PROFILE_PROPERTIES_RESPONSE_NAME.get(response));
|
||||
PropertyMap map = TextureUtil.AuthlibField.MINECRAFT_PROFILE_PROPERTIES_RESPONSE_PROPERTIES.get(response);
|
||||
if (map != null) {
|
||||
TextureUtil.AuthlibField.PROPERTY_MAP_PROPERTIES.set(TextureUtil.AuthlibField.GAME_PROFILE_PROPERTIES.get(profile), TextureUtil.AuthlibField.PROPERTY_MAP_PROPERTIES.get(map));
|
||||
}
|
||||
return profile;
|
||||
return GameProfileLoader.GSON.fromJson(responce.content, MinecraftProfilePropertiesResponse.class);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -3,6 +3,7 @@ package customskinloader.loader.jsonapi;
|
||||
import com.google.common.collect.Lists;
|
||||
import com.google.gson.Gson;
|
||||
|
||||
import com.google.gson.annotations.SerializedName;
|
||||
import customskinloader.loader.JsonAPILoader;
|
||||
import customskinloader.loader.MojangAPILoader;
|
||||
import customskinloader.plugin.ICustomSkinLoaderPlugin;
|
||||
@@ -53,12 +54,12 @@ public class MinecraftCapesAPI implements JsonAPILoader.IJsonAPI {
|
||||
@Override
|
||||
public UserProfile toUserProfile(String root, String json, boolean local) {
|
||||
MinecraftCapesApiResponse result = new Gson().fromJson(json, MinecraftCapesApiResponse.class);
|
||||
if (result.textures == null || result.textures.cape == null) {
|
||||
if (result.capeUrl == null) {
|
||||
return null;
|
||||
}
|
||||
|
||||
UserProfile profile = new UserProfile();
|
||||
profile.capeUrl = TextureUtil.parseBase64Texture(result.textures.cape);
|
||||
profile.capeUrl = result.capeUrl;
|
||||
|
||||
return profile;
|
||||
}
|
||||
@@ -69,14 +70,7 @@ public class MinecraftCapesAPI implements JsonAPILoader.IJsonAPI {
|
||||
}
|
||||
|
||||
public static class MinecraftCapesApiResponse {
|
||||
public boolean animatedCape;
|
||||
public boolean capeGlint;
|
||||
public boolean upsideDown;
|
||||
public MinecraftCapesApiTexture textures;
|
||||
|
||||
public static class MinecraftCapesApiTexture {
|
||||
public String cape;
|
||||
public String ears;
|
||||
}
|
||||
@SerializedName("cape_url")
|
||||
public String capeUrl;
|
||||
}
|
||||
}
|
||||
@@ -6,7 +6,6 @@ import java.util.UUID;
|
||||
|
||||
import com.mojang.authlib.GameProfile;
|
||||
import com.mojang.authlib.properties.Property;
|
||||
import com.mojang.authlib.properties.PropertyMap;
|
||||
import com.mojang.authlib.yggdrasil.response.MinecraftProfilePropertiesResponse;
|
||||
import com.mojang.authlib.yggdrasil.response.MinecraftTexturesPayload;
|
||||
import customskinloader.CustomSkinLoader;
|
||||
@@ -45,9 +44,7 @@ public class TextureUtil {
|
||||
GAME_PROFILE_NAME(GameProfile.class, "name"),
|
||||
GAME_PROFILE_PROPERTIES(GameProfile.class, "properties"),
|
||||
PROPERTY_VALUE(Property.class, "value"),
|
||||
PROPERTY_MAP_PROPERTIES(PropertyMap.class, "properties"),
|
||||
MINECRAFT_PROFILE_PROPERTIES_RESPONSE_ID(MinecraftProfilePropertiesResponse.class, "id"),
|
||||
MINECRAFT_PROFILE_PROPERTIES_RESPONSE_NAME(MinecraftProfilePropertiesResponse.class, "name"),
|
||||
MINECRAFT_PROFILE_PROPERTIES_RESPONSE_PROPERTIES(MinecraftProfilePropertiesResponse.class, "properties"),
|
||||
MINECRAFT_TEXTURES_PAYLOAD_TEXTURES(MinecraftTexturesPayload.class, "textures");
|
||||
|
||||
|
||||
Reference in new issue
Block a user