package customskinloader; import java.io.File; import java.io.FileInputStream; import java.io.FileNotFoundException; import java.io.FileOutputStream; import java.io.IOException; import java.util.HashMap; import java.util.Map; import org.apache.commons.io.IOUtils; import com.google.common.collect.Maps; import com.google.gson.Gson; import com.google.gson.GsonBuilder; import com.mojang.authlib.minecraft.MinecraftProfileTexture; import com.mojang.authlib.minecraft.MinecraftProfileTexture.Type; import customskinloader.config.Config; import customskinloader.config.SkinSiteProfile; import customskinloader.loader.CustomSkinAPILoader; import customskinloader.loader.IProfileLoader; import customskinloader.loader.LegacyLoader; import customskinloader.loader.MojangAPILoader; import customskinloader.loader.UniSkinAPILoader; import customskinloader.utils.MinecraftUtil; /** * Custom skin loader mod for Minecraft. * @author (C) Jeremy Lam [JLChnToZ] 2013 & Alexander Xia [xfl03] 2014-2016 * @version 13.9 (2016.6.6) */ public class CustomSkinLoader { public static final String CustomSkinLoader_VERSION="13.9"; 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"); public static final SkinSiteProfile[] DEFAULT_LOAD_LIST={ new SkinSiteProfile("Mojang","MojangAPI"), new SkinSiteProfile("BlessingSkin","CustomSkinAPI","https://skin.prinzeugen.net/csl/"), //Minecrack could not load skin correctly //new SkinSiteProfile("Minecrack","Legacy","http://minecrack.fr.nf/mc/skinsminecrackd/{USERNAME}.png","http://minecrack.fr.nf/mc/cloaksminecrackd/{USERNAME}.png"), new SkinSiteProfile("SkinMe","UniSkinAPI","http://www.skinme.cc/uniskin/"), new SkinSiteProfile("McSkin","CustomSkinAPI","http://www.mcskin.cc/")}; public static final HashMap LOADERS=initLoaders(); public static final Logger logger=initLogger(); public static final Config config=loadConfig0(); private static final Map profileCache=new HashMap(); //Entrance public static Map loadProfile(String username,Map defaultProfile){ String tempName=Thread.currentThread().getName(); Thread.currentThread().setName(username);//Change Thread Name UserProfile profile=loadProfile(username,ModelManager0.toUserProfile(defaultProfile)); Thread.currentThread().setName(tempName); return ModelManager0.fromUserProfile(profile); } public static UserProfile loadProfile(String username,UserProfile defaultProfile){ logger.info("Loading "+username+"'s profile."); if(config.enableCache&&profileCache.get(username)!=null){ logger.info("Cached profile will be used."); UserProfile profile=profileCache.get(username); logger.info(profile.toString()); return profile; } profileCache.put(username, null); for(int i=0;i loadProfileFromCache(final String username,final Map defaultProfile) { if(defaultProfile!=null&&!defaultProfile.isEmpty()) return defaultProfile; if(profileCache.containsKey(username)){ UserProfile profile=profileCache.get(username); return ModelManager0.fromUserProfile(profile); } profileCache.put(username, null); Thread loadThread=new Thread(){ public void run(){ loadProfile(username,ModelManager0.toUserProfile(defaultProfile));//Load in thread } }; loadThread.setName(username+"'s skull"); loadThread.start(); return Maps.newHashMap(); } public static Map loadProfileFromCache(final String username) { return loadProfileFromCache(username,null); } private static Logger initLogger() { Logger logger=new Logger(LOG_FILE); logger.info("CustomSkinLoader "+CustomSkinLoader_VERSION); logger.info("DataDir: "+DATA_DIR.getAbsolutePath()); logger.info("Minecraft: "+MinecraftUtil.getMinecraftVersion()); return logger; } private static HashMap initLoaders() { HashMap loaders=new HashMap(); loaders.put("mojangapi", new MojangAPILoader()); loaders.put("customskinapi", new CustomSkinAPILoader()); loaders.put("legacy", new LegacyLoader()); loaders.put("uniskinapi", new UniSkinAPILoader()); return loaders; } private static Config loadConfig0() { Config config=loadConfig(); logger.info("Enable:"+config.enable+", EnableCache:"+config.enableCache+ ", EnableSkull:"+config.enableSkull+", EnableTranSkin:"+config.enableTransparentSkin+ ", LoadList:"+(config.loadlist==null?0:config.loadlist.length)); if(config.version==null||Float.parseFloat(config.version)