Revision 14

Local skin supported
Local profile cache supported
Better profile cache
Swifter official profile loading
Better skull loading
Fix legacy loading bug
Fix bug while using ClassTransformer
This commit is contained in:
xfl03 committed 2016-07-31 22:00:46 +08:00
1 parent b34a5b3343
commit 5c12463c94
30 files changed
+766 -751

No files matched your search

@@ -1,78 +1,68 @@
package customskinloader.loader;
import java.util.Map;
import java.util.Set;
import org.apache.commons.codec.binary.Base64;
import java.util.UUID;
import com.google.gson.Gson;
import com.google.gson.GsonBuilder;
import com.google.gson.JsonSyntaxException;
import com.mojang.authlib.GameProfile;
import com.mojang.authlib.minecraft.MinecraftProfileTexture;
import com.mojang.authlib.minecraft.MinecraftProfileTexture.Type;
import com.mojang.authlib.properties.Property;
import com.mojang.authlib.minecraft.MinecraftSessionService;
import com.mojang.util.UUIDTypeAdapter;
import customskinloader.CustomSkinLoader;
import customskinloader.ModelManager0;
import customskinloader.UserProfile;
import customskinloader.config.SkinSiteProfile;
import customskinloader.profile.ModelManager0;
import customskinloader.profile.UserProfile;
import customskinloader.utils.HttpUtil0;
import net.minecraft.client.Minecraft;
public class MojangAPILoader implements IProfileLoader {
public static MinecraftSessionService defaultSessionService=null;
@Override
public UserProfile loadProfile(SkinSiteProfile ssp, String username) throws Exception {
//Get UUID Begin (http://wiki.vg/Mojang_API#Username_-.3E_UUID_at_time)
String json0=HttpUtil0.readHttp("https://api.mojang.com/users/profiles/minecraft/"+username,ssp.userAgent);
if(json0==null||json0.equals("")){
CustomSkinLoader.logger.info("Profile not found.("+username+"'s UUID not found.)");
public UserProfile loadProfile(SkinSiteProfile ssp, GameProfile gameProfile) throws Exception {
if(defaultSessionService==null){
CustomSkinLoader.logger.warning("Session Service Not Exist.");
return null;
}
Gson gson=new Gson();
UUIDProfile uuidProfile=gson.fromJson(json0, UUIDProfile.class);
if(uuidProfile.id==null||uuidProfile.id.equals("")){
CustomSkinLoader.logger.info("Profile not found.("+username+"'s UUID is empty.)");
Map<MinecraftProfileTexture.Type,MinecraftProfileTexture> map=defaultSessionService.getTextures(gameProfile, false);
if(!map.isEmpty()){
CustomSkinLoader.logger.info("Default profile will be used.");
return ModelManager0.toUserProfile(map);
}
String username=gameProfile.getName();
GameProfile newGameProfile=loadGameProfile(username);
if(newGameProfile==null){
CustomSkinLoader.logger.info("Profile not found.("+username+"'s profile not found.)");
return null;
}
//Get UUID End
//Get Profile Begin (http://wiki.vg/Mojang_API#UUID_-.3E_Profile_.2B_Skin.2FCape)
String json1=HttpUtil0.readHttp("https://sessionserver.mojang.com/session/minecraft/profile/"+uuidProfile.id,ssp.userAgent);
if(json1==null||json1.equals("")){
CustomSkinLoader.logger.info("Profile not found.("+username+"'s Profile is empty.)");
return null;
defaultSessionService.fillProfileProperties(newGameProfile, false);
map=defaultSessionService.getTextures(newGameProfile, false);
if(!map.isEmpty()){
gameProfile.getProperties().putAll(newGameProfile.getProperties());
return ModelManager0.toUserProfile(map);
}
UserProfile0 profile= gson.fromJson(json1, UserProfile0.class);
//Get Profile End
//Get Texture Begin
Property p=profile.properties.length>=1?profile.properties[0]:null;
if(p==null){
CustomSkinLoader.logger.info("Profile not found.("+username+"'s Profile doesn't have property for texture.)");
CustomSkinLoader.logger.info("Profile not found.("+username+" doesn't have skin/cape.)");
return null;
}
public static GameProfile loadGameProfile(String username) throws JsonSyntaxException{
//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;
}
String texture=p.getValue();
if(texture==null||texture.equals("")){
CustomSkinLoader.logger.info("Profile not found.("+username+"'s texture not found.)");
Gson gson = new GsonBuilder().registerTypeAdapter(UUID.class, new UUIDTypeAdapter()).create();
GameProfile gameProfile=gson.fromJson(json0, GameProfile.class);
if(gameProfile.getId()==null)
return null;
}
String json2=new String(Base64.decodeBase64(texture));
UserTexture texture1=gson.fromJson(json2, UserTexture.class);
if(texture1.textures==null||texture1.textures.isEmpty()){
CustomSkinLoader.logger.info("Profile not found.("+username+" doesn't have skin/cape.)");
return null;
}
//Get Texture End
return ModelManager0.toUserProfile(texture1.textures);
return new GameProfile(gameProfile.getId(),gameProfile.getName());
}
private class UUIDProfile{
public String id;
public String name;
}
private class UserProfile0{
public String id;
public String name;
public Property[] properties;
}
private class UserTexture{
public Map<Type,MinecraftProfileTexture> textures;
@Override
public UserProfile loadLocalProfile(SkinSiteProfile ssp, GameProfile gameProfile) throws Exception {
CustomSkinLoader.logger.warning("Local Skin couldn't load by MojangAPI.");
return loadProfile(ssp,gameProfile);
}
}