2016-02-27 15:22:35 +08:00
|
|
|
package customskinloader.loader;
|
|
|
|
|
|
2016-02-27 18:37:37 +08:00
|
|
|
import java.util.Map;
|
2016-02-27 15:22:35 +08:00
|
|
|
import java.util.Set;
|
|
|
|
|
|
|
|
|
|
import com.google.gson.Gson;
|
|
|
|
|
|
|
|
|
|
import customskinloader.CustomSkinLoader;
|
2016-03-13 00:17:11 +08:00
|
|
|
import customskinloader.ModelManager0;
|
2016-02-27 15:22:35 +08:00
|
|
|
import customskinloader.UserProfile;
|
|
|
|
|
import customskinloader.config.SkinSiteProfile;
|
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
|
|
|
|
|
public UserProfile loadProfile(SkinSiteProfile ssp, String username) throws Exception {
|
|
|
|
|
if(ssp.root==null||ssp.root.equals("")){
|
|
|
|
|
CustomSkinLoader.logger.info("Root not denined.");
|
|
|
|
|
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;
|
|
|
|
|
}
|
|
|
|
|
CustomSkinAPI profile=new Gson().fromJson(json, CustomSkinAPI.class);
|
|
|
|
|
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-02-27 15:22:35 +08:00
|
|
|
p.skinUrl=ssp.root+TEXTURES+profile.skins.get(s);
|
|
|
|
|
p.model=s;
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
if(p.skinUrl==null){
|
|
|
|
|
p.skinUrl=ssp.root+TEXTURES+profile.skins.get(keys.toArray()[0]);
|
|
|
|
|
p.model="default";
|
|
|
|
|
}
|
|
|
|
|
}else if(profile.skin!=null && !profile.skin.equals("")){
|
|
|
|
|
p.skinUrl=ssp.root+TEXTURES+profile.skin;
|
|
|
|
|
}
|
|
|
|
|
if(profile.cape!=null && !profile.cape.equals("")){
|
|
|
|
|
p.capeUrl=ssp.root+TEXTURES+profile.cape;
|
|
|
|
|
}
|
|
|
|
|
if(p.isEmpty()){
|
|
|
|
|
CustomSkinLoader.logger.info("Both skin and cape not found.");
|
|
|
|
|
return null;
|
|
|
|
|
}else{
|
|
|
|
|
return p;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private class CustomSkinAPI{
|
|
|
|
|
public String username;
|
2016-02-27 18:37:37 +08:00
|
|
|
public Map<String,String> skins;
|
2016-02-27 15:22:35 +08:00
|
|
|
public String skin;
|
|
|
|
|
public String cape;
|
|
|
|
|
}
|
|
|
|
|
}
|