diff --git a/Common/customskinloader/CustomSkinLoader.java b/Common/customskinloader/CustomSkinLoader.java index 4eb973c..980ad14 100644 --- a/Common/customskinloader/CustomSkinLoader.java +++ b/Common/customskinloader/CustomSkinLoader.java @@ -32,10 +32,10 @@ import customskinloader.utils.MinecraftUtil; /** * Custom skin loader mod for Minecraft. * @author (C) Jeremy Lam [JLChnToZ] 2013 & Alexander Xia [xfl03] 2014-2016 - * @version 14.1 (2016.7.31) + * @version 14.2 (2016.8.5) */ public class CustomSkinLoader { - public static final String CustomSkinLoader_VERSION="14.1"; + public static final String CustomSkinLoader_VERSION="14.2"; public static final File DATA_DIR=new File(MinecraftUtil.getMinecraftDataDir0(),"CustomSkinLoader"), LOG_FILE=new File(DATA_DIR,"CustomSkinLoader.log"), CONFIG_FILE=new File(DATA_DIR,"CustomSkinLoader.json"); @@ -101,10 +101,7 @@ public class CustomSkinLoader { } UserProfile profile=null; try{ - if(ssp.local==null||ssp.local==false) - profile=loader.loadProfile(ssp, gameProfile); - else - profile=loader.loadLocalProfile(ssp, gameProfile); + profile=loader.loadProfile(ssp, gameProfile,(ssp.local==null?false:ssp.local==true)); }catch(Exception e){ logger.warning("Exception occurs while loading."); logger.warning(e); diff --git a/Common/customskinloader/Logger.java b/Common/customskinloader/Logger.java index de568a4..4a618ef 100644 --- a/Common/customskinloader/Logger.java +++ b/Common/customskinloader/Logger.java @@ -40,22 +40,20 @@ public class Logger { } public void log(Level level,String msg){ - if(level.intValue()>=LOWEST_DISPLAY_LEVEL) - System.out.println(msg); + if(level.intValue()=LOWEST_DISPLAY_LEVEL) + System.out.println(sb.toString()); if(writer==null) return; try { - StringBuilder sb=new StringBuilder(); - sb.append("["); - sb.append(DATE_FORMAT.format(new Date())); - sb.append(" "); - sb.append(Thread.currentThread().getName()); - sb.append(" "); - sb.append(level.getName()); - sb.append("] "); - sb.append(msg); - sb.append("\r\n"); - writer.write(sb.toString()); + StringBuilder sb2=new StringBuilder(); + sb2.append("[").append(DATE_FORMAT.format(new Date())).append("] "); + sb2.append(sb.toString()); + writer.write(sb2.toString()); writer.flush(); } catch (Exception e) { e.printStackTrace(); @@ -73,6 +71,5 @@ public class Logger { for(StackTraceElement ste : stes){ log(Level.WARNING,ste.toString()); } - log(Level.WARNING,""); } } diff --git a/Common/customskinloader/loader/CustomSkinAPILoader.java b/Common/customskinloader/loader/CustomSkinAPILoader.java index 820cbb6..b7934f2 100644 --- a/Common/customskinloader/loader/CustomSkinAPILoader.java +++ b/Common/customskinloader/loader/CustomSkinAPILoader.java @@ -20,13 +20,24 @@ import customskinloader.utils.HttpUtil0; public class CustomSkinAPILoader implements IProfileLoader { public static final String TEXTURES="textures/"; @Override - public UserProfile loadProfile(SkinSiteProfile ssp, GameProfile gameProfile) throws Exception { + public UserProfile loadProfile(SkinSiteProfile ssp, GameProfile gameProfile, boolean local) throws Exception { String username=gameProfile.getName(); if(ssp.root==null||ssp.root.equals("")){ CustomSkinLoader.logger.info("Root not defined."); return null; } - String json=HttpUtil0.readHttp(ssp.root+username+".json",ssp.userAgent); + String jsonUrl=ssp.root+username+".json"; + String json; + if(local){ + File jsonFile=new File(jsonUrl); + if(!jsonFile.exists()){ + CustomSkinLoader.logger.info("Profile File not found."); + return null; + } + json=IOUtils.toString(new FileInputStream(jsonFile)); + }else{ + json=HttpUtil0.readHttp(jsonUrl,ssp.userAgent); + } if(json==null||json.equals("")){ CustomSkinLoader.logger.info("Profile not found."); return null; @@ -46,32 +57,6 @@ public class CustomSkinAPILoader implements IProfileLoader { 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); diff --git a/Common/customskinloader/loader/IProfileLoader.java b/Common/customskinloader/loader/IProfileLoader.java index 4e8331e..00fc935 100644 --- a/Common/customskinloader/loader/IProfileLoader.java +++ b/Common/customskinloader/loader/IProfileLoader.java @@ -6,6 +6,5 @@ import customskinloader.config.SkinSiteProfile; import customskinloader.profile.UserProfile; public interface IProfileLoader { - public UserProfile loadProfile(SkinSiteProfile ssp,GameProfile gameProfile) throws Exception; - public UserProfile loadLocalProfile(SkinSiteProfile ssp,GameProfile gameProfile) throws Exception; + public UserProfile loadProfile(SkinSiteProfile ssp,GameProfile gameProfile,boolean local) throws Exception; } diff --git a/Common/customskinloader/loader/LegacyLoader.java b/Common/customskinloader/loader/LegacyLoader.java index b0d91e2..03fd208 100644 --- a/Common/customskinloader/loader/LegacyLoader.java +++ b/Common/customskinloader/loader/LegacyLoader.java @@ -12,59 +12,40 @@ import customskinloader.utils.HttpUtil0; public class LegacyLoader implements IProfileLoader { public static final String USERNAME_REGEX="\\{USERNAME\\}"; + @Override - public UserProfile loadProfile(SkinSiteProfile ssp, GameProfile gameProfile) throws Exception { - String username=gameProfile.getName(); - UserProfile profile=new UserProfile(); - if(ssp.skin!=null && !ssp.skin.equals("")){ - String skin=HttpUtil0.getFakeUrl(ssp.skin.replaceAll(USERNAME_REGEX, username),ssp.userAgent); - if(skin!=null&&!skin.equals("")){ - profile.skinUrl=skin; - profile.model=(ssp.model==null?"default":ssp.model); - } - } - if(ssp.cape!=null && !ssp.cape.equals("")){ - String cape=HttpUtil0.getFakeUrl(ssp.cape.replaceAll(USERNAME_REGEX, username),ssp.userAgent); - 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; - } - } - @Override - public UserProfile loadLocalProfile(SkinSiteProfile ssp, GameProfile gameProfile) throws Exception { + public UserProfile loadProfile(SkinSiteProfile ssp, GameProfile gameProfile, boolean local) 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("")){ + if(local){ File skinFile=new File(CustomSkinLoader.DATA_DIR,skin); - if(skinFile.exists()&&skinFile.isFile()){ + 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); - } + }else{ + String fakeSkinUrl=HttpUtil0.getFakeUrl(skin,ssp.userAgent); + if(fakeSkinUrl!=null&&!fakeSkinUrl.equals("")) + profile.skinUrl=fakeSkinUrl; } + profile.model=profile.hasSkinUrl()?ssp.model:null; } if(ssp.cape!=null && !ssp.cape.equals("")){ String cape=ssp.cape.replaceAll(USERNAME_REGEX, username); - if(cape!=null&&!cape.equals("")){ + if(local){ File capeFile=new File(CustomSkinLoader.DATA_DIR,cape); - if(capeFile.exists()&&capeFile.isFile()){ + if(capeFile.exists()&&capeFile.isFile()) profile.capeUrl=HttpTextureUtil.getLocalLegacyFakeUrl(cape, HttpTextureUtil.getHash(cape, capeFile.length(), capeFile.lastModified())); - } + }else{ + String fakeCapeUrl=HttpUtil0.getFakeUrl(cape,ssp.userAgent); + if(fakeCapeUrl!=null&&fakeCapeUrl.equals("")) + profile.capeUrl=fakeCapeUrl; } } if(profile.isEmpty()){ CustomSkinLoader.logger.info("Both skin and cape not found."); return null; - }else{ - return profile; } + return profile; } - } diff --git a/Common/customskinloader/loader/MojangAPILoader.java b/Common/customskinloader/loader/MojangAPILoader.java index eb28094..fffa2f7 100644 --- a/Common/customskinloader/loader/MojangAPILoader.java +++ b/Common/customskinloader/loader/MojangAPILoader.java @@ -23,7 +23,9 @@ public class MojangAPILoader implements IProfileLoader { public static MinecraftSessionService defaultSessionService=null; @Override - public UserProfile loadProfile(SkinSiteProfile ssp, GameProfile gameProfile) throws Exception { + public UserProfile loadProfile(SkinSiteProfile ssp, GameProfile gameProfile, boolean local) throws Exception { + if(local) + CustomSkinLoader.logger.warning("!!Local Skin couldn't load by MojangAPI.!!"); if(defaultSessionService==null){ CustomSkinLoader.logger.warning("Session Service Not Exist."); return null; @@ -59,10 +61,4 @@ public class MojangAPILoader implements IProfileLoader { return null; return new GameProfile(gameProfile.getId(),gameProfile.getName()); } - - @Override - public UserProfile loadLocalProfile(SkinSiteProfile ssp, GameProfile gameProfile) throws Exception { - CustomSkinLoader.logger.warning("Local Skin couldn't load by MojangAPI."); - return loadProfile(ssp,gameProfile); - } } diff --git a/Common/customskinloader/loader/UniSkinAPILoader.java b/Common/customskinloader/loader/UniSkinAPILoader.java index ff1d122..a93d3ce 100644 --- a/Common/customskinloader/loader/UniSkinAPILoader.java +++ b/Common/customskinloader/loader/UniSkinAPILoader.java @@ -20,13 +20,24 @@ import customskinloader.utils.HttpUtil0; public class UniSkinAPILoader implements IProfileLoader { public static final String TEXTURES="textures/"; @Override - public UserProfile loadProfile(SkinSiteProfile ssp, GameProfile gameProfile) throws Exception { + public UserProfile loadProfile(SkinSiteProfile ssp, GameProfile gameProfile, boolean local) throws Exception { String username=gameProfile.getName(); if(ssp.root==null||ssp.root.equals("")){ CustomSkinLoader.logger.info("Root not defined."); return null; } - String json=HttpUtil0.readHttp(ssp.root+username+".json",ssp.userAgent); + String jsonUrl=ssp.root+username+".json"; + String json; + if(local){ + File jsonFile=new File(jsonUrl); + if(!jsonFile.exists()){ + CustomSkinLoader.logger.info("Profile File not found."); + return null; + } + json=IOUtils.toString(new FileInputStream(jsonFile)); + }else{ + json=HttpUtil0.readHttp(jsonUrl,ssp.userAgent); + } if(json==null||json.equals("")){ CustomSkinLoader.logger.info("Profile not found."); return null; @@ -54,31 +65,6 @@ public class UniSkinAPILoader implements IProfileLoader { public int errno; public String msg; } - @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==null||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){ UniSkinAPI profile=CustomSkinLoader.GSON.fromJson(json, UniSkinAPI.class); diff --git a/Common/customskinloader/profile/UserProfile.java b/Common/customskinloader/profile/UserProfile.java index 4a6c570..832159b 100644 --- a/Common/customskinloader/profile/UserProfile.java +++ b/Common/customskinloader/profile/UserProfile.java @@ -41,6 +41,9 @@ public class UserProfile { * @return status (true - empty) */ public boolean isEmpty(){ - return skinUrl==null && (model==null||model.equalsIgnoreCase("default")) && capeUrl==null; + return skinUrl==null && capeUrl==null; + } + public boolean hasSkinUrl(){ + return (skinUrl!=null&&!skinUrl.equals("")); } }