66import java .util .UUID ;
77import java .util .concurrent .ConcurrentHashMap ;
88
9+ import com .google .common .collect .Iterables ;
910import com .google .common .collect .Lists ;
1011import com .mojang .authlib .GameProfile ;
1112import 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
0 commit comments