2016-02-27 15:22:35 +08:00
|
|
|
package customskinloader.loader;
|
|
|
|
|
|
2016-07-31 22:00:46 +08:00
|
|
|
import java.io.File;
|
|
|
|
|
|
|
|
|
|
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.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 LegacyLoader implements IProfileLoader {
|
|
|
|
|
public static final String USERNAME_REGEX="\\{USERNAME\\}";
|
|
|
|
|
@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
|
|
|
UserProfile profile=new UserProfile();
|
|
|
|
|
if(ssp.skin!=null && !ssp.skin.equals("")){
|
2016-07-31 22:00:46 +08:00
|
|
|
String skin=HttpUtil0.getFakeUrl(ssp.skin.replaceAll(USERNAME_REGEX, username),ssp.userAgent);
|
2016-02-27 15:22:35 +08:00
|
|
|
if(skin!=null&&!skin.equals("")){
|
|
|
|
|
profile.skinUrl=skin;
|
2016-04-03 13:01:06 +08:00
|
|
|
profile.model=(ssp.model==null?"default":ssp.model);
|
2016-02-27 15:22:35 +08:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
if(ssp.cape!=null && !ssp.cape.equals("")){
|
2016-07-31 22:00:46 +08:00
|
|
|
String cape=HttpUtil0.getFakeUrl(ssp.cape.replaceAll(USERNAME_REGEX, username),ssp.userAgent);
|
2016-02-27 15:22:35 +08:00
|
|
|
if(cape!=null&&!cape.equals("")){
|
|
|
|
|
profile.capeUrl=cape;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
if(profile.isEmpty()){
|
|
|
|
|
CustomSkinLoader.logger.info("Both skin and cape not found.");
|
|
|
|
|
return null;
|
|
|
|
|
}else{
|
|
|
|
|
return profile;
|
|
|
|
|
}
|
|
|
|
|
}
|
2016-07-31 22:00:46 +08:00
|
|
|
@Override
|
|
|
|
|
public UserProfile loadLocalProfile(SkinSiteProfile ssp, GameProfile gameProfile) throws Exception {
|
|
|
|
|
String username=gameProfile.getName();
|
|
|
|
|
UserProfile profile=new UserProfile();
|
|
|
|
|
if(ssp.skin!=null && !ssp.skin.equals("")){
|
|
|
|
|
String skin=ssp.skin.replaceAll(USERNAME_REGEX, username);
|
|
|
|
|
if(skin!=null&&!skin.equals("")){
|
|
|
|
|
File skinFile=new File(CustomSkinLoader.DATA_DIR,skin);
|
|
|
|
|
if(skinFile.exists()&&skinFile.isFile()){
|
|
|
|
|
profile.skinUrl=HttpTextureUtil.getLocalLegacyFakeUrl(skin, HttpTextureUtil.getHash(skin, skinFile.length(), skinFile.lastModified()));
|
|
|
|
|
profile.model=(ssp.model==null?"default":ssp.model);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
if(ssp.cape!=null && !ssp.cape.equals("")){
|
|
|
|
|
String cape=ssp.cape.replaceAll(USERNAME_REGEX, username);
|
|
|
|
|
if(cape!=null&&!cape.equals("")){
|
|
|
|
|
File capeFile=new File(CustomSkinLoader.DATA_DIR,cape);
|
|
|
|
|
if(capeFile.exists()&&capeFile.isFile()){
|
|
|
|
|
profile.capeUrl=HttpTextureUtil.getLocalLegacyFakeUrl(cape, HttpTextureUtil.getHash(cape, capeFile.length(), capeFile.lastModified()));
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
if(profile.isEmpty()){
|
|
|
|
|
CustomSkinLoader.logger.info("Both skin and cape not found.");
|
|
|
|
|
return null;
|
|
|
|
|
}else{
|
|
|
|
|
return profile;
|
|
|
|
|
}
|
|
|
|
|
}
|
2016-02-27 15:22:35 +08:00
|
|
|
|
|
|
|
|
}
|