diff --git a/Common/source/customskinloader/CustomSkinLoader.java b/Common/source/customskinloader/CustomSkinLoader.java index aa70d2d..c534cc4 100644 --- a/Common/source/customskinloader/CustomSkinLoader.java +++ b/Common/source/customskinloader/CustomSkinLoader.java @@ -50,7 +50,7 @@ public class CustomSkinLoader { private static final DynamicSkullManager dynamicSkullManager=new DynamicSkullManager(); //For User Skin - public static Map loadProfile(GameProfile gameProfile){ + public static Map loadProfile(GameProfile gameProfile){ String username=gameProfile.getName(); String credential=MinecraftUtil.getCredential(gameProfile); //Fix: http://hopper.minecraft.net/crashes/minecraft/MCX-2773713 @@ -60,7 +60,7 @@ public class CustomSkinLoader { } String tempName=Thread.currentThread().getName(); Thread.currentThread().setName(username);//Change Thread Name - UserProfile profile=null; + UserProfile profile; if(profileCache.isReady(credential)){ logger.info("Cached profile will be used."); profile=profileCache.getProfile(credential); diff --git a/Common/source/customskinloader/Logger.java b/Common/source/customskinloader/Logger.java index ec1b678..e7dc281 100644 --- a/Common/source/customskinloader/Logger.java +++ b/Common/source/customskinloader/Logger.java @@ -7,6 +7,7 @@ import java.io.OutputStreamWriter; import java.text.SimpleDateFormat; import java.util.Date; +@SuppressWarnings("ResultOfMethodCallIgnored") public class Logger { private static final SimpleDateFormat DATE_FORMAT = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); public enum Level{ @@ -32,6 +33,9 @@ public class Logger { public Logger(){ //Logger isn't created. } + public Logger(String logFile) { + this(new File(logFile)); + } public Logger(File logFile){ try { if(!logFile.getParentFile().exists()){ @@ -59,18 +63,14 @@ public class Logger { public void log(Level level,String msg){ if(!level.display()&&writer==null) return; - StringBuilder sb=new StringBuilder(); - sb.append("[").append(Thread.currentThread().getName()).append(" ").append(level.getName()).append("] "); - sb.append(msg); + String sb = String.format("[%s %s] %s", Thread.currentThread().getName(), level.getName(), msg); if(level.display()) - System.out.println(sb.toString()); + System.out.println(sb); if(writer==null) return; try { - StringBuilder sb2=new StringBuilder(); - sb2.append("[").append(DATE_FORMAT.format(new Date())).append("] "); - sb2.append(sb.toString()).append("\r\n"); - writer.write(sb2.toString()); + String sb2 = String.format("[%s] %s\r\n", DATE_FORMAT.format(new Date()), sb); + writer.write(sb2); writer.flush(); } catch (Exception e) { e.printStackTrace(); @@ -82,9 +82,15 @@ public class Logger { public void info(String msg){ log(Level.INFO,msg); } + public void info(String format, Object... objs){ + info(String.format(format, objs)); + } public void warning(String msg){ log(Level.WARNING,msg); } + public void warning(String format, Object... objs){ + warning(String.format(format, objs)); + } public void warning(Throwable e){ log(Level.WARNING,"Exception: "+e.toString()); StackTraceElement[] stes=e.getStackTrace(); diff --git a/Common/source/customskinloader/config/Config.java b/Common/source/customskinloader/config/Config.java index e9f0edc..d983d3f 100644 --- a/Common/source/customskinloader/config/Config.java +++ b/Common/source/customskinloader/config/Config.java @@ -5,7 +5,6 @@ import java.util.ArrayList; import java.util.Arrays; import java.util.List; -import org.apache.commons.io.Charsets; import org.apache.commons.io.FileUtils; import customskinloader.CustomSkinLoader; @@ -14,6 +13,7 @@ import customskinloader.utils.HttpRequestUtil; import customskinloader.utils.HttpTextureUtil; import customskinloader.utils.HttpUtil0; +@SuppressWarnings("ResultOfMethodCallIgnored") public class Config { //Program public String version; @@ -104,7 +104,7 @@ public class Config { } try { CustomSkinLoader.logger.info("Try to load config."); - String json=FileUtils.readFileToString(CustomSkinLoader.CONFIG_FILE,Charsets.UTF_8); + String json=FileUtils.readFileToString(CustomSkinLoader.CONFIG_FILE, "UTF-8"); Config config=CustomSkinLoader.GSON.fromJson(json, Config.class); CustomSkinLoader.logger.info("Successfully load config."); return config; @@ -126,12 +126,12 @@ public class Config { } List adds=new ArrayList(); File[] files=listAddition.listFiles(); - for(File file:files){ + for(File file: files != null ? files : new File[0]){ if(!file.getName().toLowerCase().endsWith(".json")&&!file.getName().toLowerCase().endsWith(".txt")) continue; try { CustomSkinLoader.logger.info("Try to load Extra List.("+file.getName()+")"); - String json=FileUtils.readFileToString(file,Charsets.UTF_8); + String json=FileUtils.readFileToString(file, "UTF-8"); SkinSiteProfile ssp=CustomSkinLoader.GSON.fromJson(json, SkinSiteProfile.class); CustomSkinLoader.logger.info("Successfully load Extra List."); file.delete(); @@ -186,7 +186,7 @@ public class Config { CustomSkinLoader.CONFIG_FILE.delete(); try { CustomSkinLoader.CONFIG_FILE.createNewFile(); - FileUtils.write(CustomSkinLoader.CONFIG_FILE, json, Charsets.UTF_8); + FileUtils.write(CustomSkinLoader.CONFIG_FILE, json, "UTF-8"); CustomSkinLoader.logger.info("Successfully "+(update?"update":"create")+" config."); } catch (Exception e) { CustomSkinLoader.logger.info("Failed to "+(update?"update":"create")+" config.("+e.toString()+")"); diff --git a/Common/source/customskinloader/fake/FakeSkinManager.java b/Common/source/customskinloader/fake/FakeSkinManager.java index 3ef34e3..f8bcff9 100644 --- a/Common/source/customskinloader/fake/FakeSkinManager.java +++ b/Common/source/customskinloader/fake/FakeSkinManager.java @@ -28,7 +28,7 @@ import net.minecraft.client.resources.SkinManager.SkinAvailableCallback; import net.minecraft.util.ResourceLocation; public class FakeSkinManager{ - private static final ExecutorService THREAD_POOL = new ThreadPoolExecutor(0, 2, 1L, TimeUnit.MINUTES, new LinkedBlockingQueue()); + private static final ExecutorService THREAD_POOL = new ThreadPoolExecutor(0, 2, 1L, TimeUnit.MINUTES, new LinkedBlockingQueue()); private final TextureManager textureManager; public FakeSkinManager(TextureManager textureManagerInstance, File skinCacheDirectory, MinecraftSessionService sessionService) { @@ -48,7 +48,7 @@ public class FakeSkinManager{ if (itextureobject != null)//Have already loaded makeCallback(skinAvailableCallback,textureType, resourcelocation, profileTexture); else{ - ThreadDownloadImageData threaddownloadimagedata = new ThreadDownloadImageData(info.cacheFile, info.url, DefaultPlayerSkin.getDefaultSkinLegacy(), + ThreadDownloadImageData threaddownloadimagedata = new ThreadDownloadImageData(info.cacheFile, info.url, DefaultPlayerSkin.getDefaultSkinLegacy(), new BaseBuffer(skinAvailableCallback, textureType, resourcelocation, profileTexture)); this.textureManager.loadTexture(resourcelocation, threaddownloadimagedata); } @@ -57,14 +57,14 @@ public class FakeSkinManager{ public void loadProfileTextures(final GameProfile profile, final SkinAvailableCallback skinAvailableCallback, final boolean requireSecure){ THREAD_POOL.submit(new Runnable(){ public void run(){ - final Map map = Maps.newHashMap(); + final Map map = Maps.newHashMap(); map.putAll(customskinloader.CustomSkinLoader.loadProfile(profile)); Minecraft.getMinecraft().addScheduledTask(new Runnable(){ public void run(){ for(Type type:Type.values()) if(map.containsKey(type)) - FakeSkinManager.this.loadSkin((MinecraftProfileTexture)map.get(type), type, skinAvailableCallback); + FakeSkinManager.this.loadSkin(map.get(type), type, skinAvailableCallback); } }); } @@ -102,7 +102,7 @@ public class FakeSkinManager{ buffer.skinAvailable(); if ("auto".equals(texture.getMetadata("model")) && buffer instanceof FakeSkinBuffer){ //Auto judge skin type - Map metadata = Maps.newHashMap(); + Map metadata = Maps.newHashMap(); metadata.put("model", ((FakeSkinBuffer) buffer).judgeType()); texture = new MinecraftProfileTexture(texture.getUrl(), metadata); } diff --git a/Common/source/customskinloader/loader/JsonAPILoader.java b/Common/source/customskinloader/loader/JsonAPILoader.java index a735420..c928b5c 100644 --- a/Common/source/customskinloader/loader/JsonAPILoader.java +++ b/Common/source/customskinloader/loader/JsonAPILoader.java @@ -20,19 +20,19 @@ import customskinloader.utils.HttpRequestUtil.HttpResponce; public class JsonAPILoader implements ProfileLoader.IProfileLoader { public interface IJsonAPI { - public String toJsonUrl(String root,String username); - public String getPayload(SkinSiteProfile ssp); - public UserProfile toUserProfile(String root,String json,boolean local); - public String getName(); + String toJsonUrl(String root, String username); + String getPayload(SkinSiteProfile ssp); + UserProfile toUserProfile(String root, String json, boolean local); + String getName(); } public static class ErrorProfile{ public int errno; public String msg; } - public static enum Type{ + public enum Type{ CustomSkinAPI(new CustomSkinAPI()),CustomSkinAPIPlus(new CustomSkinAPIPlus()),UniSkinAPI(new UniSkinAPI()); public IJsonAPI jsonAPI; - private Type(IJsonAPI jsonAPI){ + Type(IJsonAPI jsonAPI){ this.jsonAPI=jsonAPI; } } @@ -58,7 +58,7 @@ public class JsonAPILoader implements ProfileLoader.IProfileLoader { CustomSkinLoader.logger.info("Profile File not found."); return null; } - json=IOUtils.toString(new FileInputStream(jsonFile)); + json=IOUtils.toString(new FileInputStream(jsonFile), "UTF-8"); }else{ HttpResponce responce=HttpRequestUtil.makeHttpRequest(new HttpRequest(jsonUrl).setCacheTime(90).setUserAgent(ssp.userAgent).setPayload(type.jsonAPI.getPayload(ssp))); json=responce.content; @@ -84,12 +84,13 @@ public class JsonAPILoader implements ProfileLoader.IProfileLoader { } @Override public boolean compare(SkinSiteProfile ssp0, SkinSiteProfile ssp1) { - return StringUtils.isNoneEmpty(ssp0.root)?ssp0.root.equalsIgnoreCase(ssp1.root):true; + return !StringUtils.isNoneEmpty(ssp0.root) || ssp0.root.equalsIgnoreCase(ssp1.root); } @Override public String getName() { return type.jsonAPI.getName(); } + @SuppressWarnings("ResultOfMethodCallIgnored") @Override public void initLocalFolder(SkinSiteProfile ssp) { if(HttpUtil0.isLocal(ssp.root)){ diff --git a/Common/source/customskinloader/loader/LegacyLoader.java b/Common/source/customskinloader/loader/LegacyLoader.java index 6bca551..5274047 100644 --- a/Common/source/customskinloader/loader/LegacyLoader.java +++ b/Common/source/customskinloader/loader/LegacyLoader.java @@ -55,7 +55,7 @@ public class LegacyLoader implements ProfileLoader.IProfileLoader { if(elytraFile.exists()&&elytraFile.isFile()) profile.elytraUrl=HttpTextureUtil.getLocalLegacyFakeUrl(elytra, HttpTextureUtil.getHash(elytra, elytraFile.length(), elytraFile.lastModified())); }else{ - HttpResponce responce=HttpRequestUtil.makeHttpRequest(new HttpRequest(elytra).setUserAgent(ssp.userAgent).setCheckPNG(ssp.checkPNG!=null&&ssp.checkPNG!=false).setLoadContent(false).setCacheTime(90)); + HttpResponce responce=HttpRequestUtil.makeHttpRequest(new HttpRequest(elytra).setUserAgent(ssp.userAgent).setCheckPNG(ssp.checkPNG!=null && ssp.checkPNG).setLoadContent(false).setCacheTime(90)); if(responce.success) profile.elytraUrl=HttpTextureUtil.getLegacyFakeUrl(elytra); } @@ -85,6 +85,7 @@ public class LegacyLoader implements ProfileLoader.IProfileLoader { if(HttpUtil0.isLocal(ssp.elytra)) initFolder(ssp.elytra); } + @SuppressWarnings("ResultOfMethodCallIgnored") private void initFolder(String target){ String file=target.replaceAll(USERNAME_REGEX, "init"); File folder=new File(CustomSkinLoader.DATA_DIR,file).getParentFile(); diff --git a/Common/source/customskinloader/loader/MojangAPILoader.java b/Common/source/customskinloader/loader/MojangAPILoader.java index 94447b8..009433e 100644 --- a/Common/source/customskinloader/loader/MojangAPILoader.java +++ b/Common/source/customskinloader/loader/MojangAPILoader.java @@ -1,9 +1,9 @@ package customskinloader.loader; -import java.util.HashMap; import java.util.Map; import java.util.UUID; +import com.google.common.collect.Maps; import org.apache.commons.codec.Charsets; import org.apache.commons.codec.binary.Base64; import org.apache.commons.lang3.StringUtils; @@ -56,7 +56,7 @@ public class MojangAPILoader implements ProfileLoader.IProfileLoader { } //Username -> UUID - public static GameProfile loadGameProfile(String username) throws Exception{ + public static GameProfile loadGameProfile(String username) { //Doc (http://wiki.vg/Mojang_API#Username_-.3E_UUID_at_time) HttpResponce responce=HttpRequestUtil.makeHttpRequest(new HttpRequest("https://api.mojang.com/users/profiles/minecraft/"+username).setCacheTime(0)); if(StringUtils.isEmpty(responce.content)) @@ -70,9 +70,11 @@ public class MojangAPILoader implements ProfileLoader.IProfileLoader { return new GameProfile(gameProfile.getId(),gameProfile.getName()); } //UUID -> Profile - public static GameProfile fillGameProfile(GameProfile profile) throws Exception{ + public static GameProfile fillGameProfile(GameProfile profile) { //Doc (http://wiki.vg/Mojang_API#UUID_-.3E_Profile_.2B_Skin.2FCape) - HttpResponce responce=HttpRequestUtil.makeHttpRequest(new HttpRequest("https://sessionserver.mojang.com/session/minecraft/profile/"+UUIDTypeAdapter.fromUUID(profile.getId())).setCacheTime(90)); + HttpResponce responce = HttpRequestUtil.makeHttpRequest( + new HttpRequest("https://sessionserver.mojang.com/session/minecraft/profile/" + + UUIDTypeAdapter.fromUUID(profile.getId())).setCacheTime(90)); if(StringUtils.isEmpty(responce.content)) return profile; @@ -87,20 +89,20 @@ public class MojangAPILoader implements ProfileLoader.IProfileLoader { return newGameProfile; } - public static Map getTextures(GameProfile gameProfile) throws Exception{ + public static Map getTextures(GameProfile gameProfile) { if(gameProfile==null) - return new HashMap(); - Property textureProperty=(Property)Iterables.getFirst(gameProfile.getProperties().get("textures"), null); + return Maps.newHashMap(); + Property textureProperty=Iterables.getFirst(gameProfile.getProperties().get("textures"), null); if (textureProperty==null) - return new HashMap(); + return Maps.newHashMap(); String value=textureProperty.getValue(); if(StringUtils.isBlank(value)) - return new HashMap(); - String json=new String(Base64.decodeBase64(value),Charsets.UTF_8); + return Maps.newHashMap(); + @SuppressWarnings("deprecation") String json = new String(Base64.decodeBase64(value), Charsets.UTF_8); Gson gson=new GsonBuilder().registerTypeAdapter(UUID.class,new UUIDTypeAdapter()).create(); MinecraftTexturesPayload result=gson.fromJson(json,MinecraftTexturesPayload.class); if (result==null||result.getTextures()==null) - return new HashMap(); + return Maps.newHashMap(); return result.getTextures(); } diff --git a/Common/source/customskinloader/loader/ProfileLoader.java b/Common/source/customskinloader/loader/ProfileLoader.java index 6e17e33..c9083fa 100644 --- a/Common/source/customskinloader/loader/ProfileLoader.java +++ b/Common/source/customskinloader/loader/ProfileLoader.java @@ -26,9 +26,9 @@ public class ProfileLoader { } public interface IProfileLoader { - public UserProfile loadProfile(SkinSiteProfile ssp,GameProfile gameProfile) throws Exception; - public boolean compare(SkinSiteProfile ssp0,SkinSiteProfile ssp1); - public String getName(); - public void initLocalFolder(SkinSiteProfile ssp); + UserProfile loadProfile(SkinSiteProfile ssp,GameProfile gameProfile) throws Exception; + boolean compare(SkinSiteProfile ssp0,SkinSiteProfile ssp1); + String getName(); + void initLocalFolder(SkinSiteProfile ssp); } } diff --git a/Common/source/customskinloader/loader/jsonapi/CustomSkinAPI.java b/Common/source/customskinloader/loader/jsonapi/CustomSkinAPI.java index 86d63b9..dba0f45 100644 --- a/Common/source/customskinloader/loader/jsonapi/CustomSkinAPI.java +++ b/Common/source/customskinloader/loader/jsonapi/CustomSkinAPI.java @@ -19,7 +19,7 @@ public class CustomSkinAPI implements IJsonAPI { @Override public String toJsonUrl(String root, String username) { - return new StringBuilder().append(root).append(username).append(SUFFIX).toString(); + return root + username + SUFFIX; } @Override diff --git a/Common/source/customskinloader/loader/jsonapi/CustomSkinAPIPlus.java b/Common/source/customskinloader/loader/jsonapi/CustomSkinAPIPlus.java index 7badc4e..8554e1a 100644 --- a/Common/source/customskinloader/loader/jsonapi/CustomSkinAPIPlus.java +++ b/Common/source/customskinloader/loader/jsonapi/CustomSkinAPIPlus.java @@ -22,14 +22,14 @@ public class CustomSkinAPIPlus implements IJsonAPI { if(clientIDFile.isFile()) try{ - clientID=FileUtils.readFileToString(clientIDFile); + clientID=FileUtils.readFileToString(clientIDFile, "UTF-8"); }catch(Exception e){ e.printStackTrace(); } if(clientID==null){ clientID=UUID.randomUUID().toString(); try { - FileUtils.write(clientIDFile, clientID); + FileUtils.write(clientIDFile, clientID, "UTF-8"); } catch (Exception e) { e.printStackTrace(); } diff --git a/Common/source/customskinloader/loader/jsonapi/UniSkinAPI.java b/Common/source/customskinloader/loader/jsonapi/UniSkinAPI.java index c466a9c..0dc7b4f 100644 --- a/Common/source/customskinloader/loader/jsonapi/UniSkinAPI.java +++ b/Common/source/customskinloader/loader/jsonapi/UniSkinAPI.java @@ -19,7 +19,7 @@ public class UniSkinAPI implements IJsonAPI { @Override public String toJsonUrl(String root, String username) { - return new StringBuilder().append(root).append(username).append(SUFFIX).toString(); + return root + username + SUFFIX; } @Override diff --git a/Common/source/customskinloader/profile/DynamicSkullManager.java b/Common/source/customskinloader/profile/DynamicSkullManager.java index 054e49f..28943c8 100644 --- a/Common/source/customskinloader/profile/DynamicSkullManager.java +++ b/Common/source/customskinloader/profile/DynamicSkullManager.java @@ -1,12 +1,9 @@ package customskinloader.profile; import java.io.File; -import java.util.ArrayList; -import java.util.HashMap; -import java.util.List; -import java.util.Map; -import java.util.UUID; +import java.util.*; +import com.google.common.collect.Lists; import org.apache.commons.codec.Charsets; import org.apache.commons.codec.binary.Base64; import org.apache.commons.io.FileUtils; @@ -46,33 +43,34 @@ public class DynamicSkullManager { private List loadingList=new ArrayList(); private void parseGameProfile(GameProfile profile){ - Property textureProperty=(Property)Iterables.getFirst(profile.getProperties().get("textures"), null); + Property textureProperty = Iterables.getFirst(profile.getProperties().get("textures"), null); if (textureProperty==null){ - staticTextures.put(profile, new HashMap()); + staticTextures.put(profile, Maps.newHashMap()); return; } String value=textureProperty.getValue(); if(StringUtils.isBlank(value)){ - staticTextures.put(profile, new HashMap()); + staticTextures.put(profile, Maps.newHashMap()); return; } - String json=new String(Base64.decodeBase64(value),Charsets.UTF_8); + @SuppressWarnings("deprecation") String json = new String(Base64.decodeBase64(value), Charsets.UTF_8); Gson gson=new GsonBuilder().registerTypeAdapter(UUID.class,new UUIDTypeAdapter()).create(); SkullTexture result=gson.fromJson(json,SkullTexture.class); if(result==null){ - staticTextures.put(profile, new HashMap()); + staticTextures.put(profile, Maps.newHashMap()); return; } - staticTextures.put(profile, (result.textures==null||!result.textures.containsKey(Type.SKIN))?new HashMap():parseTextures(result.textures)); + staticTextures.put(profile, (result.textures==null || !result.textures.containsKey(Type.SKIN)) ? + Maps.newHashMap() : parseTextures(result.textures)); if(StringUtils.isNotEmpty(result.index)){ File indexFile=new File(CustomSkinLoader.DATA_DIR,result.index); try{ - String index=FileUtils.readFileToString(indexFile, Charsets.UTF_8); + String index=FileUtils.readFileToString(indexFile, "UTF-8"); if(StringUtils.isNotEmpty(index)){ - ArrayList skins=CustomSkinLoader.GSON.fromJson(index, ArrayList.class); - if(skins!=null&&!skins.isEmpty()) - result.skins=skins; + String[] skins = CustomSkinLoader.GSON.fromJson(index, String[].class); + if(skins != null && skins.length != 0) + result.skins = Lists.newArrayList(skins); } }catch(Exception e){ CustomSkinLoader.logger.warning("Exception occurs while parsing index file: "+e.toString()); @@ -96,7 +94,6 @@ public class DynamicSkullManager { }else{ //Could not find skin result.skins.remove(i--); - continue; } }else{ //Online Skin @@ -104,7 +101,6 @@ public class DynamicSkullManager { if(!responce.success){ //Could not load skin result.skins.remove(i--); - continue; } } } @@ -130,7 +126,7 @@ public class DynamicSkullManager { return textures; File skinFile=new File(CustomSkinLoader.DATA_DIR,skinUrl); if(!skinFile.isFile()) - return new HashMap(); + return Maps.newHashMap(); textures.put(Type.SKIN, ModelManager0.getProfileTexture(HttpTextureUtil.getLocalFakeUrl(skinUrl), null)); return textures; } @@ -139,7 +135,7 @@ public class DynamicSkullManager { if(staticTextures.get(profile)!=null) return staticTextures.get(profile); if(loadingList.contains(profile)) - return new HashMap(); + return Maps.newHashMap(); if(dynamicTextures.containsKey(profile)){ SkullTexture texture=dynamicTextures.get(profile); long time=System.currentTimeMillis()-texture.startTime; @@ -158,6 +154,6 @@ public class DynamicSkullManager { }; loadThread.setName("Skull "+profile.hashCode()); loadThread.start(); - return new HashMap(); + return Maps.newHashMap(); } } diff --git a/Common/source/customskinloader/profile/ModelManager0.java b/Common/source/customskinloader/profile/ModelManager0.java index 7596a37..4f0f2b2 100644 --- a/Common/source/customskinloader/profile/ModelManager0.java +++ b/Common/source/customskinloader/profile/ModelManager0.java @@ -16,7 +16,7 @@ import com.mojang.authlib.minecraft.MinecraftProfileTexture.Type; * @since 13.1 */ public class ModelManager0 { - public static enum Model{ + public enum Model{ SKIN_DEFAULT, SKIN_SLIM, CAPE, @@ -88,12 +88,12 @@ public class ModelManager0 { * @return profile - hashMapProfile (HashMap) * @since 13.1 */ - public static Map fromUserProfile(UserProfile profile){ - Map map=Maps.newHashMap(); + public static Map fromUserProfile(UserProfile profile){ + Map map=Maps.newHashMap(); if(profile==null) return map; if(profile.skinUrl!=null){ - Map metadata = null; + Map metadata = null; if("slim".equals(profile.model) || "auto".equals(profile.model)){ metadata = Maps.newHashMap(); metadata.put("model", profile.model); @@ -115,7 +115,7 @@ public class ModelManager0 { * @return MinecraftProfileTexture * @since 14.5 */ - public static MinecraftProfileTexture getProfileTexture(String url,Map metadata){ + public static MinecraftProfileTexture getProfileTexture(String url,Map metadata){ return new MinecraftProfileTexture(url,metadata); } } diff --git a/Common/source/customskinloader/profile/ProfileCache.java b/Common/source/customskinloader/profile/ProfileCache.java index c083add..d7593e1 100644 --- a/Common/source/customskinloader/profile/ProfileCache.java +++ b/Common/source/customskinloader/profile/ProfileCache.java @@ -1,11 +1,9 @@ package customskinloader.profile; import java.io.File; -import java.io.FileInputStream; -import java.io.FileOutputStream; import java.util.HashMap; -import org.apache.commons.io.IOUtils; +import org.apache.commons.io.FileUtils; import customskinloader.CustomSkinLoader; import customskinloader.utils.TimeUtil; @@ -16,6 +14,7 @@ public class ProfileCache { private HashMap cachedProfiles=new HashMap(); private HashMap localProfiles=new HashMap(); + @SuppressWarnings("ResultOfMethodCallIgnored") public ProfileCache(){ if(!PROFILE_CACHE_DIR.exists()) PROFILE_CACHE_DIR.mkdir(); @@ -26,11 +25,11 @@ public class ProfileCache { } public boolean isReady(String username){ CachedProfile cp=cachedProfiles.get(username.toLowerCase()); - return cp==null?false:(cp.loading||cp.expiryTime>TimeUtil.getCurrentUnixTimestamp()); + return cp != null && (cp.loading || cp.expiryTime > TimeUtil.getCurrentUnixTimestamp()); } public boolean isExpired(String username){ CachedProfile cp=cachedProfiles.get(username.toLowerCase()); - return cp==null?true:(cp.expiryTime<=TimeUtil.getCurrentUnixTimestamp()); + return cp == null || (cp.expiryTime <= TimeUtil.getCurrentUnixTimestamp()); } public UserProfile getProfile(String username){ @@ -74,7 +73,7 @@ public class ProfileCache { localProfiles.put(username.toLowerCase(), null); } try{ - String json=IOUtils.toString(new FileInputStream(localProfile)); + String json = FileUtils.readFileToString(localProfile, "UTF-8"); UserProfile profile=CustomSkinLoader.GSON.fromJson(json, UserProfile.class); localProfiles.put(username.toLowerCase(), profile); CustomSkinLoader.logger.info("Successfully load LocalProfile."); @@ -85,14 +84,14 @@ public class ProfileCache { } return null; } - private void saveLocalProfile(String username,UserProfile profile){ + @SuppressWarnings("ResultOfMethodCallIgnored") + private void saveLocalProfile(String username, UserProfile profile){ String json=CustomSkinLoader.GSON.toJson(profile); File localProfile=new File(PROFILE_CACHE_DIR,username+".json"); if(localProfile.exists()) localProfile.delete(); try { - localProfile.createNewFile(); - IOUtils.write(json, new FileOutputStream(localProfile)); + FileUtils.write(localProfile, json, "UTF-8"); CustomSkinLoader.logger.info("Successfully save LocalProfile."); } catch (Exception e) { CustomSkinLoader.logger.info("Failed to save LocalProfile.("+e.toString()+")"); diff --git a/Common/source/customskinloader/profile/UserProfile.java b/Common/source/customskinloader/profile/UserProfile.java index bbd2775..7119647 100644 --- a/Common/source/customskinloader/profile/UserProfile.java +++ b/Common/source/customskinloader/profile/UserProfile.java @@ -52,7 +52,6 @@ public class UserProfile { return; case ELYTRA: this.capeUrl=url; - return; } } diff --git a/Common/source/customskinloader/utils/HttpRequestUtil.java b/Common/source/customskinloader/utils/HttpRequestUtil.java index 1e4cee6..8a9a8d6 100644 --- a/Common/source/customskinloader/utils/HttpRequestUtil.java +++ b/Common/source/customskinloader/utils/HttpRequestUtil.java @@ -89,7 +89,7 @@ public class HttpRequestUtil { if(request.cacheTime==0 && request.cacheFile.isFile()) return loadFromCache(request,new HttpResponce()); if(cacheInfoFile!=null&&cacheInfoFile.isFile()){ - String json=FileUtils.readFileToString(cacheInfoFile); + String json=FileUtils.readFileToString(cacheInfoFile, "UTF-8"); if(StringUtils.isNotEmpty(json)) cacheInfo=CustomSkinLoader.GSON.fromJson(json, CacheInfo.class); if(cacheInfo==null) @@ -121,7 +121,7 @@ public class HttpRequestUtil { CustomSkinLoader.logger.info("Payload: "+request.payload); c.setDoOutput(true); OutputStream os=c.getOutputStream(); - IOUtils.write(request.payload, os); + IOUtils.write(request.payload, os, "UTF-8"); IOUtils.closeQuietly(os); } c.connect(); @@ -154,13 +154,13 @@ public class HttpRequestUtil { cacheInfo.etag=c.getHeaderField("ETag"); cacheInfo.lastModified=c.getLastModified(); cacheInfo.expire=getExpire(c,request.cacheTime); - FileUtils.write(cacheInfoFile, CustomSkinLoader.GSON.toJson(cacheInfo)); + FileUtils.write(cacheInfoFile, CustomSkinLoader.GSON.toJson(cacheInfo), "UTF-8"); } CustomSkinLoader.logger.debug("Saved to cache (Length: "+request.cacheFile.length()+" , Path: '"+request.cacheFile.getAbsolutePath()+"' , Expire: "+cacheInfo.expire+")"); } if(!request.loadContent) return responce; - responce.content=new String(bytes,Charsets.UTF_8); + responce.content=new String(bytes, "UTF-8"); CustomSkinLoader.logger.debug("Content: "+responce.content); return responce; @@ -187,7 +187,7 @@ public class HttpRequestUtil { CustomSkinLoader.logger.info("Try to load from cache '"+request.cacheFile.getAbsolutePath()+"'."); try { - responce.content=FileUtils.readFileToString(request.cacheFile); + responce.content=FileUtils.readFileToString(request.cacheFile, "UTF-8"); CustomSkinLoader.logger.debug("Successfully load from cache"); CustomSkinLoader.logger.debug("Content: "+responce.content); } catch (IOException e) { @@ -201,7 +201,7 @@ public class HttpRequestUtil { String cacheControl=connection.getHeaderField("Cache-Control"); if(StringUtils.isNotEmpty(cacheControl)){ Matcher m=MAX_AGE_PATTERN.matcher(cacheControl); - if(m!=null && m.matches()) + if(m.matches()) return TimeUtil.getUnixTimestamp(Long.parseLong(m.group(m.groupCount()))); } long expires=connection.getExpiration(); diff --git a/Common/source/customskinloader/utils/HttpTextureUtil.java b/Common/source/customskinloader/utils/HttpTextureUtil.java index e7d0303..4ccca1d 100644 --- a/Common/source/customskinloader/utils/HttpTextureUtil.java +++ b/Common/source/customskinloader/utils/HttpTextureUtil.java @@ -18,6 +18,7 @@ public class HttpTextureUtil { LOCAL_MARK="(LOCAL)", LOCAL_LEGACY_MARK="(LOCAL_LEGACY)"; public static File defaultCacheDir; + @SuppressWarnings("ResultOfMethodCallIgnored") public static void cleanCacheDir(){ if(defaultCacheDir!=null){ defaultCacheDir.delete(); @@ -54,7 +55,7 @@ public class HttpTextureUtil { if(fakeUrl.startsWith(LEGACY_MARK)){ fakeUrl=fakeUrl.replace(LEGACY_MARK, ""); info.url=fakeUrl; - info.hash=DigestUtils.sha1Hex(info.url);; + info.hash=DigestUtils.sha1Hex(info.url); info.cacheFile=HttpTextureUtil.getCacheFile(info.hash); return info; } diff --git a/Common/source/customskinloader/utils/HttpUtil0.java b/Common/source/customskinloader/utils/HttpUtil0.java index d89398d..3ff7c16 100644 --- a/Common/source/customskinloader/utils/HttpUtil0.java +++ b/Common/source/customskinloader/utils/HttpUtil0.java @@ -15,7 +15,7 @@ import org.apache.commons.lang3.StringUtils; public class HttpUtil0 { public static boolean isLocal(String url){ - return url==null? false : !url.startsWith("http"); + return url != null && !url.startsWith("http"); } //From: http://blog.csdn.net/xiyushiyi/article/details/46685387 diff --git a/Common/source/customskinloader/utils/MinecraftUtil.java b/Common/source/customskinloader/utils/MinecraftUtil.java index db6d491..fe6130f 100644 --- a/Common/source/customskinloader/utils/MinecraftUtil.java +++ b/Common/source/customskinloader/utils/MinecraftUtil.java @@ -85,7 +85,7 @@ public class MinecraftUtil { private final static Pattern MINECRAFT_CORE_FILE_PATTERN = Pattern.compile("^(.*?)/versions/([^\\/\\\\]*?)/([^\\/\\\\]*?).jar$"); private static void testProbe(){ minecraftVersion.clear(); - URLClassLoader ucl = (URLClassLoader)new MinecraftUtil().getClass().getClassLoader(); + URLClassLoader ucl = (URLClassLoader) MinecraftUtil.class.getClassLoader(); URL urls[] = ucl.getURLs(); for(URL url:urls){ Matcher m = null; @@ -101,26 +101,26 @@ public class MinecraftUtil { } public static boolean isCoreFile(URL url){ - Matcher m = null; + Matcher m; try{ m=MINECRAFT_CORE_FILE_PATTERN.matcher(URLDecoder.decode(url.getPath(),"UTF-8")); }catch(Exception e){ e.printStackTrace(); return false; } - return m!=null && m.matches(); + return m.matches(); } private final static Pattern LIBRARY_FILE_PATTERN = Pattern.compile("^(.*?)/libraries/(.*?)/([^\\/\\\\]*?).jar$"); public static boolean isLibraryFile(URL url){ - Matcher m = null; + Matcher m; try{ m=LIBRARY_FILE_PATTERN.matcher(URLDecoder.decode(url.getPath(),"UTF-8")); }catch(Exception e){ e.printStackTrace(); return false; } - return m!=null && m.matches(); + return m.matches(); } public static String getCredential(GameProfile profile) { diff --git a/Common/source/customskinloader/utils/TimeUtil.java b/Common/source/customskinloader/utils/TimeUtil.java index 9c71352..38e4501 100644 --- a/Common/source/customskinloader/utils/TimeUtil.java +++ b/Common/source/customskinloader/utils/TimeUtil.java @@ -2,7 +2,7 @@ package customskinloader.utils; public class TimeUtil { public static long getCurrentUnixTimestamp(){ - return System.currentTimeMillis()/1000l; + return System.currentTimeMillis() / 1000L; } public static long getUnixTimestamp(long offset){ return getCurrentUnixTimestamp()+offset; diff --git a/Forge/source/customskinloader/forge/TransformerManager.java b/Forge/source/customskinloader/forge/TransformerManager.java index da08530..1b497ac 100644 --- a/Forge/source/customskinloader/forge/TransformerManager.java +++ b/Forge/source/customskinloader/forge/TransformerManager.java @@ -9,6 +9,7 @@ import java.util.HashMap; import java.util.List; import java.util.Map; +import customskinloader.Logger; import org.objectweb.asm.ClassReader; import org.objectweb.asm.ClassWriter; import org.objectweb.asm.tree.ClassNode; @@ -16,21 +17,21 @@ import org.objectweb.asm.tree.MethodNode; import net.minecraft.launchwrapper.IClassTransformer; import net.minecraftforge.fml.common.asm.transformers.deobf.FMLDeobfuscatingRemapper; -import net.minecraftforge.fml.relauncher.FMLRelaunchLog; import customskinloader.forge.PlayerTabTransformer.ScoreObjectiveTransformer; import customskinloader.forge.SkinManagerTransformer.*; import customskinloader.forge.SpectatorMenuTransformer.PlayerMenuObjectTransformer; public class TransformerManager implements IClassTransformer { + public static Logger logger = new Logger("ForgePlugin.log"); @Retention(RetentionPolicy.RUNTIME) @Target(ElementType.TYPE) public @interface TransformTarget{ - public String className(); - public String[] methodNames(); - public String desc(); + String className(); + String[] methodNames(); + String desc(); } public interface IMethodTransformer{ - public void transform(ClassNode cn,MethodNode mn); + void transform(ClassNode cn,MethodNode mn); } private static final IMethodTransformer[] TRANFORMERS={ new InitTransformer(), @@ -43,9 +44,9 @@ public class TransformerManager implements IClassTransformer { public TransformerManager(){ map = new HashMap>(); for(IMethodTransformer t:TRANFORMERS){ - FMLRelaunchLog.info("[CSL DEBUG] REGISTERING TRANSFORMER %s",t.getClass().getName()); + logger.info("[CSL DEBUG] REGISTERING TRANSFORMER %s" , t.getClass().getName()); if(!t.getClass().isAnnotationPresent(TransformTarget.class)){ - FMLRelaunchLog.info("[CSL DEBUG] ERROR occurs while parsing Annotation."); + logger.info("[CSL DEBUG] ERROR occurs while parsing Annotation."); continue; } addMethodTransformer(t.getClass().getAnnotation(TransformTarget.class),t); @@ -56,7 +57,7 @@ public class TransformerManager implements IClassTransformer { map.put(target.className(), new HashMap()); for(String methodName:target.methodNames()){ map.get(target.className()).put(methodName + target.desc(), transformer); - FMLRelaunchLog.info("[CSL DEBUG] REGISTERING METHOD %s(%s)",target.className(),methodName + target.desc()); + logger.info("[CSL DEBUG] REGISTERING METHOD %s(%s)",target.className(),methodName + target.desc()); } } @@ -64,7 +65,7 @@ public class TransformerManager implements IClassTransformer { @Override public byte[] transform(String obfClassName, String className, byte[] bytes) { if (!map.containsKey(className)) return bytes; - FMLRelaunchLog.info("[CSL DEBUG] CLASS %s will be transformed", className); + logger.info("[CSL DEBUG] CLASS %s will be transformed", className); Map transMap = map.get(className); ClassReader cr = new ClassReader(bytes); @@ -72,18 +73,17 @@ public class TransformerManager implements IClassTransformer { cr.accept(cn, 0); // NOTE: `map` = convert obfuscated name to srgName; - List ml = new ArrayList(); - ml.addAll(cn.methods); + List ml = new ArrayList(cn.methods); for (MethodNode mn : ml) { String methodName = FMLDeobfuscatingRemapper.INSTANCE.mapMethodName(obfClassName, mn.name, mn.desc); String methodDesc = FMLDeobfuscatingRemapper.INSTANCE.mapMethodDesc(mn.desc); if (transMap.containsKey(methodName + methodDesc)) { try { - FMLRelaunchLog.info("[CSL DEBUG] Transforming method %s in class %s(%s)", methodName + methodDesc, obfClassName, className); + logger.info("[CSL DEBUG] Transforming method %s in class %s(%s)", methodName + methodDesc, obfClassName, className); transMap.get(methodName + methodDesc).transform(cn,mn); - FMLRelaunchLog.info("[CSL DEBUG] Successfully transformed method %s in class %s(%s)", methodName + methodDesc, obfClassName, className); + logger.info("[CSL DEBUG] Successfully transformed method %s in class %s(%s)", methodName + methodDesc, obfClassName, className); } catch (Exception e) { - FMLRelaunchLog.warning("[CSL DEBUG] An error happened when transforming method %s in class %s(%s). The whole class was not modified.", methodName + methodDesc, obfClassName, className); + logger.warning("[CSL DEBUG] An error happened when transforming method %s in class %s(%s). The whole class was not modified.", methodName + methodDesc, obfClassName, className); e.printStackTrace(); return bytes; } diff --git a/Vanilla/customskinloader/tweaker/ClassTransformer.java b/Vanilla/customskinloader/tweaker/ClassTransformer.java index 1e8d733..6f8a642 100644 --- a/Vanilla/customskinloader/tweaker/ClassTransformer.java +++ b/Vanilla/customskinloader/tweaker/ClassTransformer.java @@ -35,7 +35,7 @@ public class ClassTransformer implements IClassTransformer { continue; } File file = new File(url.toURI()); - if(file==null||!file.isFile()){ + if(!file.isFile()){ ModSystemTweaker.logger.info(url.toString()+" : EXCEPTION (file not found)."); continue; } @@ -75,7 +75,7 @@ public class ClassTransformer implements IClassTransformer { private static ZipFile getZipFile(File file) { - ZipFile zipFile0=null; + ZipFile zipFile0; try { zipFile0 = new ZipFile(file); return zipFile0; @@ -89,11 +89,11 @@ public class ClassTransformer implements IClassTransformer { if (zipFile == null) return bytes; - String fullName = new StringBuilder().append(name.startsWith("net") ? name.replaceAll("\\.", "\\/") : name).append(".class").toString();//Notch(Run)/MCP(Dev) Class Name + String fullName = (name.startsWith("net") ? name.replaceAll("\\.", "\\/") : name) + ".class";//Notch(Run)/MCP(Dev) Class Name if(!classes.contains(fullName)){//Check Name if(name.equals(transformedName)) return bytes; - fullName = new StringBuilder().append(transformedName.replaceAll("\\.", "\\/")).append(".class").toString();//MCP Class Name + fullName = transformedName.replaceAll("\\.", "\\/") + ".class";//MCP Class Name if(!classes.contains(fullName))//check Again return bytes; }