Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -61,11 +61,12 @@ public void updateSkinSiteProfile(SkinSiteProfile ssp) {

@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;
}

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

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();
}
Expand Down
45 changes: 19 additions & 26 deletions Common/src/main/java/customskinloader/loader/MojangAPILoader.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
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;
Expand Down Expand Up @@ -80,28 +81,30 @@ public String getSessionRoot() {
@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)) {
Expand All @@ -112,13 +115,12 @@ public static GameProfile loadGameProfile(String apiRoot, String username) {
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];
}

/**
Expand All @@ -129,31 +131,22 @@ public static GameProfile loadGameProfile(String apiRoot, String username) {
* @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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
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;
Expand Down Expand Up @@ -53,12 +54,12 @@ public String toJsonUrl(String root, String username) {
@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;
}
Expand All @@ -69,14 +70,7 @@ public String getName() {
}

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;
}
}
3 changes: 0 additions & 3 deletions Common/src/main/java/customskinloader/utils/TextureUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@

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;
Expand Down Expand Up @@ -45,9 +44,7 @@ public enum AuthlibField {
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");

Expand Down