mirror of
https://github.com/xfl03/MCCustomSkinLoader.git
synced 2026-11-18 18:29:16 +00:00
Added Skull Support[1.9]
Added Profile Cache Fixed Default Profile Not Used Close #6
This commit is contained in:
1 parent
199c5d674e
commit
1dbfa30ba8
4 files changed
+51
-17
No files matched your search
@@ -131,14 +131,13 @@ public class SkinManager
|
||||
|
||||
//CustomSkinLoader Begin
|
||||
if(customskinloader.CustomSkinLoader.config.enable){
|
||||
Map newMap=customskinloader.CustomSkinLoader.loadProfile(profile.getName(), map);
|
||||
Map<Type, MinecraftProfileTexture> newMap=customskinloader.CustomSkinLoader.loadProfile(profile.getName(), map);
|
||||
if(!newMap.isEmpty()){
|
||||
map.clear();
|
||||
map.putAll(newMap);
|
||||
}
|
||||
}
|
||||
//CustomSkinLoader End
|
||||
|
||||
Minecraft.getMinecraft().addScheduledTask(new Runnable()
|
||||
{
|
||||
public void run()
|
||||
@@ -160,7 +159,8 @@ public class SkinManager
|
||||
|
||||
public Map<Type, MinecraftProfileTexture> loadSkinFromCache(GameProfile profile)
|
||||
{
|
||||
return (Map)this.skinCacheLoader.getUnchecked(profile);
|
||||
return customskinloader.CustomSkinLoader.loadProfileFromCache(profile.getName());
|
||||
//return (Map)this.skinCacheLoader.getUnchecked(profile);
|
||||
}
|
||||
|
||||
public interface SkinAvailableCallback
|
||||
|
||||
@@ -12,6 +12,8 @@ import org.apache.commons.io.IOUtils;
|
||||
|
||||
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;
|
||||
@@ -25,10 +27,10 @@ import net.minecraft.client.Minecraft;
|
||||
/**
|
||||
* Custom skin loader mod for Minecraft.
|
||||
* @author (C) Jeremy Lam [JLChnToZ] 2013 & Alexander Xia [xfl03] 2014-2016
|
||||
* @version 13.3 (2016.3.13)
|
||||
* @version 13.4 (2016.4.3)
|
||||
*/
|
||||
public class CustomSkinLoader {
|
||||
public static final String CustomSkinLoader_VERSION="13.3";
|
||||
public static final String CustomSkinLoader_VERSION="13.4";
|
||||
public static final File DATA_DIR=new File(Minecraft.getMinecraft().mcDataDir,"CustomSkinLoader"),
|
||||
LOG_FILE=new File(DATA_DIR,"CustomSkinLoader.log"),
|
||||
CONFIG_FILE=new File(DATA_DIR,"CustomSkinLoader.json");
|
||||
@@ -43,14 +45,33 @@ public class CustomSkinLoader {
|
||||
public static final Logger logger=initLogger();
|
||||
public static final Config config=loadConfig0();
|
||||
|
||||
private static final Map<String,UserProfile> profileCache=new HashMap<String,UserProfile>();
|
||||
|
||||
//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(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<config.loadlist.length;i++){
|
||||
SkinSiteProfile ssp=config.loadlist[i];
|
||||
logger.info((i+1)+"/"+config.loadlist.length+" Try to load profile from '"+ssp.name+"'.");
|
||||
if(ssp.type.equalsIgnoreCase("MojangAPI") && !defaultProfile.isEmpty()){
|
||||
logger.info("Default profile will be used.");
|
||||
logger.info(ModelManager0.toUserProfile(defaultProfile).toString());
|
||||
return defaultProfile;
|
||||
logger.info(defaultProfile.toString());
|
||||
profileCache.put(username, defaultProfile);
|
||||
return defaultProfile;//Create a new map instance
|
||||
}
|
||||
IProfileLoader loader=LOADERS.get(ssp.type.toLowerCase());
|
||||
if(loader==null){
|
||||
@@ -67,9 +88,18 @@ public class CustomSkinLoader {
|
||||
continue;
|
||||
logger.info(username+"'s profile loaded.");
|
||||
logger.info(profile.toString());
|
||||
profileCache.put(username, profile);
|
||||
return profile;
|
||||
}
|
||||
logger.info(username+"'s profile not found.");
|
||||
return defaultProfile;
|
||||
}
|
||||
public static Map<Type, MinecraftProfileTexture> loadProfileFromCache(String username) {
|
||||
if(profileCache.containsKey(username)){
|
||||
UserProfile profile=profileCache.get(username);
|
||||
return ModelManager0.fromUserProfile(profile);
|
||||
}
|
||||
return defaultProfile;
|
||||
return loadProfile(username,(Map)null);
|
||||
}
|
||||
|
||||
private static Logger initLogger() {
|
||||
|
||||
@@ -40,15 +40,17 @@ public class Logger {
|
||||
if(level.intValue()>=LOWEST_DISPLAY_LEVEL)
|
||||
System.out.println(msg);
|
||||
try {
|
||||
writer.write("[");
|
||||
writer.write(DATE_FORMAT.format(new Date()));
|
||||
writer.write(" ");
|
||||
writer.write(Thread.currentThread().getName());
|
||||
writer.write(" ");
|
||||
writer.write(level.getName());
|
||||
writer.write("] ");
|
||||
writer.write(msg);
|
||||
writer.write("\r\n");
|
||||
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());
|
||||
writer.flush();
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
|
||||
@@ -53,6 +53,8 @@ public class ModelManager0 {
|
||||
*/
|
||||
public static Map fromUserProfile(UserProfile profile){
|
||||
Map map=Maps.newHashMap();
|
||||
if(profile==null)
|
||||
return map;
|
||||
if(profile.skinUrl!=null){
|
||||
Map metadata=null;
|
||||
if(profile.model!=null&&profile.model.equals("slim")){
|
||||
|
||||
Reference in new issue
Block a user