2016-02-27 15:22:35 +08:00
|
|
|
package customskinloader.loader;
|
|
|
|
|
|
2016-07-31 22:00:46 +08:00
|
|
|
import java.io.File;
|
|
|
|
|
import java.io.FileInputStream;
|
2016-02-27 18:37:37 +08:00
|
|
|
import java.util.Map;
|
2016-02-27 15:22:35 +08:00
|
|
|
import java.util.Set;
|
|
|
|
|
|
2016-07-31 22:00:46 +08:00
|
|
|
import org.apache.commons.io.IOUtils;
|
|
|
|
|
|
2016-02-27 15:22:35 +08:00
|
|
|
import com.google.gson.Gson;
|
2016-07-31 22:00:46 +08:00
|
|
|
import com.mojang.authlib.GameProfile;
|
2016-02-27 15:22:35 +08:00
|
|
|
|
|
|
|
|
import customskinloader.CustomSkinLoader;
|
|
|
|
|
import customskinloader.config.SkinSiteProfile;
|
2016-07-31 22:00:46 +08:00
|
|
|
import customskinloader.profile.ModelManager0;
|
|
|
|
|
import customskinloader.profile.UserProfile;
|
|
|
|
|
import customskinloader.utils.HttpTextureUtil;
|
2016-02-27 16:37:05 +08:00
|
|
|
import customskinloader.utils.HttpUtil0;
|
2016-02-27 15:22:35 +08:00
|
|
|
|
|
|
|
|
public class CustomSkinAPILoader implements IProfileLoader {
|
|
|
|
|
public static final String TEXTURES="textures/";
|
|
|
|
|
@Override
|
2016-07-31 22:00:46 +08:00
|
|
|
public UserProfile loadProfile(SkinSiteProfile ssp, GameProfile gameProfile) throws Exception {
|
|
|
|
|
String username=gameProfile.getName();
|
2016-02-27 15:22:35 +08:00
|
|
|
if(ssp.root==null||ssp.root.equals("")){
|
2016-07-31 22:00:46 +08:00
|
|
|
CustomSkinLoader.logger.info("Root not defined.");
|
2016-02-27 15:22:35 +08:00
|
|
|
return null;
|
|
|
|
|
}
|
2016-07-04 14:10:44 +08:00
|
|
|
String json=HttpUtil0.readHttp(ssp.root+username+".json",ssp.userAgent);
|
2016-02-27 15:22:35 +08:00
|
|
|
if(json==null||json.equals("")){
|
|
|
|
|
CustomSkinLoader.logger.info("Profile not found.");
|
|
|
|
|
return null;
|
|
|
|
|
}
|
2016-07-31 22:00:46 +08:00
|
|
|
UserProfile p=toUserProfile(ssp.root,json,false);
|
|
|
|
|
if(p.isEmpty()){
|
|
|
|
|
CustomSkinLoader.logger.info("Both skin and cape not found.");
|
|
|
|
|
return null;
|
|
|
|
|
}else{
|
|
|
|
|
return p;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private class CustomSkinAPI{
|
|
|
|
|
public String username;
|
|
|
|
|
public Map<String,String> skins;
|
|
|
|
|
public String skin;
|
|
|
|
|
public String cape;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public UserProfile loadLocalProfile(SkinSiteProfile ssp, GameProfile gameProfile) throws Exception {
|
|
|
|
|
String username=gameProfile.getName();
|
|
|
|
|
if(ssp.root==null||ssp.root.equals("")){
|
|
|
|
|
CustomSkinLoader.logger.info("Root not defined.");
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
File jsonFile=new File(CustomSkinLoader.DATA_DIR,ssp.root+username+".json");
|
|
|
|
|
if(!jsonFile.exists()){
|
|
|
|
|
CustomSkinLoader.logger.info("Profile File not found.");
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
String json=IOUtils.toString(new FileInputStream(jsonFile));
|
|
|
|
|
if(json==null||json.equals("")){
|
|
|
|
|
CustomSkinLoader.logger.info("Profile not found.");
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
UserProfile p=toUserProfile(ssp.root,json,true);
|
|
|
|
|
if(p.isEmpty()){
|
|
|
|
|
CustomSkinLoader.logger.info("Both skin and cape not found.");
|
|
|
|
|
return null;
|
|
|
|
|
}else{
|
|
|
|
|
return p;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private UserProfile toUserProfile(String root,String json,boolean local){
|
|
|
|
|
CustomSkinAPI profile=CustomSkinLoader.GSON.fromJson(json, CustomSkinAPI.class);
|
2016-02-27 15:22:35 +08:00
|
|
|
UserProfile p=new UserProfile();
|
|
|
|
|
if(profile.skins!=null && !profile.skins.isEmpty()){
|
|
|
|
|
Set<String> keys=profile.skins.keySet();
|
|
|
|
|
for(String s:keys){
|
2016-03-13 00:17:11 +08:00
|
|
|
//System.out.println(s+" "+ModelManager0.checkModel(s));
|
|
|
|
|
if(ModelManager0.checkModel(s)){
|
|
|
|
|
if(profile.skins.get(s)==null||profile.skins.get(s).equals(""))
|
|
|
|
|
continue;
|
2016-07-31 22:00:46 +08:00
|
|
|
p.skinUrl=root+TEXTURES+profile.skins.get(s);
|
2016-02-27 15:22:35 +08:00
|
|
|
p.model=s;
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
if(p.skinUrl==null){
|
2016-07-31 22:00:46 +08:00
|
|
|
p.skinUrl=root+TEXTURES+profile.skins.get(keys.toArray()[0]);
|
2016-02-27 15:22:35 +08:00
|
|
|
p.model="default";
|
|
|
|
|
}
|
|
|
|
|
}else if(profile.skin!=null && !profile.skin.equals("")){
|
2016-07-31 22:00:46 +08:00
|
|
|
p.skinUrl=root+TEXTURES+profile.skin;
|
|
|
|
|
if(local)
|
|
|
|
|
p.skinUrl=HttpTextureUtil.getLocalFakeUrl(p.skinUrl);
|
2016-02-27 15:22:35 +08:00
|
|
|
}
|
|
|
|
|
if(profile.cape!=null && !profile.cape.equals("")){
|
2016-07-31 22:00:46 +08:00
|
|
|
p.capeUrl=root+TEXTURES+profile.cape;
|
|
|
|
|
if(local)
|
|
|
|
|
p.capeUrl=HttpTextureUtil.getLocalFakeUrl(p.capeUrl);
|
2016-02-27 15:22:35 +08:00
|
|
|
}
|
2016-07-31 22:00:46 +08:00
|
|
|
return p;
|
2016-02-27 15:22:35 +08:00
|
|
|
}
|
|
|
|
|
}
|