diff --git a/Common/customskinloader/loader/MojangAPILoader.java b/Common/customskinloader/loader/MojangAPILoader.java index 70eaceb..4a1c63e 100644 --- a/Common/customskinloader/loader/MojangAPILoader.java +++ b/Common/customskinloader/loader/MojangAPILoader.java @@ -1,8 +1,13 @@ package customskinloader.loader; +import java.util.HashMap; import java.util.Map; import java.util.UUID; +import org.apache.commons.codec.Charsets; +import org.apache.commons.codec.binary.Base64; + +import com.google.common.collect.Iterables; import com.google.gson.Gson; import com.google.gson.GsonBuilder; import com.google.gson.JsonSyntaxException; @@ -10,6 +15,8 @@ import com.mojang.authlib.GameProfile; import com.mojang.authlib.minecraft.MinecraftProfileTexture; import com.mojang.authlib.minecraft.MinecraftProfileTexture.Type; import com.mojang.authlib.minecraft.MinecraftSessionService; +import com.mojang.authlib.properties.Property; +import com.mojang.authlib.yggdrasil.response.MinecraftTexturesPayload; import com.mojang.util.UUIDTypeAdapter; import customskinloader.CustomSkinLoader; @@ -30,7 +37,7 @@ public class MojangAPILoader implements ProfileLoader.IProfileLoader { CustomSkinLoader.logger.warning("Session Service Not Exist."); return null; } - Map map=defaultSessionService.getTextures(gameProfile, false); + Map map=getTextures(gameProfile); if(!map.isEmpty()){ CustomSkinLoader.logger.info("Default profile will be used."); return ModelManager0.toUserProfile(map); @@ -42,7 +49,7 @@ public class MojangAPILoader implements ProfileLoader.IProfileLoader { return null; } defaultSessionService.fillProfileProperties(newGameProfile, false); - map=defaultSessionService.getTextures(newGameProfile, false); + map=getTextures(newGameProfile); if(!map.isEmpty()){ gameProfile.getProperties().putAll(newGameProfile.getProperties()); return ModelManager0.toUserProfile(map); @@ -50,17 +57,33 @@ public class MojangAPILoader implements ProfileLoader.IProfileLoader { CustomSkinLoader.logger.info("Profile not found.("+username+" doesn't have skin/cape.)"); return null; } - public static GameProfile loadGameProfile(String username) throws JsonSyntaxException{ + + public static GameProfile loadGameProfile(String username) throws Exception{ //Doc (http://wiki.vg/Mojang_API#Username_-.3E_UUID_at_time) String json0=HttpUtil0.readHttp("https://api.mojang.com/users/profiles/minecraft/"+username,null); if(json0==null||json0.equals("")) return null; - Gson gson = new GsonBuilder().registerTypeAdapter(UUID.class, new UUIDTypeAdapter()).create(); + Gson gson=new GsonBuilder().registerTypeAdapter(UUID.class, new UUIDTypeAdapter()).create(); GameProfile gameProfile=gson.fromJson(json0, GameProfile.class); if(gameProfile.getId()==null) return null; return new GameProfile(gameProfile.getId(),gameProfile.getName()); } + public static Map getTextures(GameProfile gameProfile) throws Exception{ + Property textureProperty=(Property)Iterables.getFirst(gameProfile.getProperties().get("textures"), null); + if (textureProperty==null) + return new HashMap(); + String value=textureProperty.getValue(); + if(value==null||value.equals("")) + return new HashMap(); + String json=new String(Base64.decodeBase64(value),Charsets.UTF_8); + Gson gson=new GsonBuilder().registerTypeAdapter(UUID.class,new UUIDTypeAdapter()).create(); + MinecraftTexturesPayload result=(MinecraftTexturesPayload)gson.fromJson(json,MinecraftTexturesPayload.class); + if (result==null||result.getTextures()==null) + return new HashMap(); + return result.getTextures(); + } + @Override public boolean compare(SkinSiteProfile ssp0, SkinSiteProfile ssp1) { return true; diff --git a/Common/customskinloader/utils/HttpUtil0.java b/Common/customskinloader/utils/HttpUtil0.java index ac33eb1..d8f4bee 100644 --- a/Common/customskinloader/utils/HttpUtil0.java +++ b/Common/customskinloader/utils/HttpUtil0.java @@ -19,7 +19,7 @@ public class HttpUtil0 { public static String readHttp(String url,String userAgent){ HttpURLConnection c=null; try { - CustomSkinLoader.logger.info("Try to read '"+url+(userAgent==null?" without user agent.":"' with user agent '"+userAgent+"'.")); + CustomSkinLoader.logger.info("Try to read '"+url+(userAgent==null?"' without user agent.":"' with user agent '"+userAgent+"'.")); c=createConnection(url,userAgent); int res = c.getResponseCode()/100; if (res==4||res==5||c.getResponseCode()==HttpURLConnection.HTTP_NO_CONTENT) { diff --git a/build.properties b/build.properties index 1ca0cb4..d87946c 100644 --- a/build.properties +++ b/build.properties @@ -3,4 +3,4 @@ group=customskinloader version=14.4 dev_version= #RELEASE: snapshot_version= -snapshot_version=20160828-1 \ No newline at end of file +snapshot_version= \ No newline at end of file