diff --git a/Common/source/customskinloader/config/Config.java b/Common/source/customskinloader/config/Config.java index d983d3f..dbace26 100644 --- a/Common/source/customskinloader/config/Config.java +++ b/Common/source/customskinloader/config/Config.java @@ -26,7 +26,7 @@ public class Config { public boolean forceLoadAllTextures=false; //Cache - public int cacheExpiry=20; + public int cacheExpiry=30; public boolean enableUpdateSkull=false; public boolean enableLocalProfileCache=false; public boolean enableCacheAutoClean=false; diff --git a/Common/source/customskinloader/loader/JsonAPILoader.java b/Common/source/customskinloader/loader/JsonAPILoader.java index c928b5c..46b9b65 100644 --- a/Common/source/customskinloader/loader/JsonAPILoader.java +++ b/Common/source/customskinloader/loader/JsonAPILoader.java @@ -30,7 +30,10 @@ public class JsonAPILoader implements ProfileLoader.IProfileLoader { public String msg; } public enum Type{ - CustomSkinAPI(new CustomSkinAPI()),CustomSkinAPIPlus(new CustomSkinAPIPlus()),UniSkinAPI(new UniSkinAPI()); + CustomSkinAPI(new CustomSkinAPI()), + CustomSkinAPIPlus(new CustomSkinAPIPlus()), + UniSkinAPI(new UniSkinAPI()), + ElyByAPI(new ElyByAPI()); public IJsonAPI jsonAPI; Type(IJsonAPI jsonAPI){ this.jsonAPI=jsonAPI; @@ -45,11 +48,11 @@ public class JsonAPILoader implements ProfileLoader.IProfileLoader { @Override public UserProfile loadProfile(SkinSiteProfile ssp, GameProfile gameProfile) throws Exception { String username=gameProfile.getName(); - boolean local=HttpUtil0.isLocal(ssp.root); - if(ssp.root==null||ssp.root.equals("")){ + if(StringUtils.isEmpty(ssp.root) && type!=Type.ElyByAPI){ CustomSkinLoader.logger.info("Root not defined."); return null; } + boolean local = HttpUtil0.isLocal(ssp.root); String jsonUrl=type.jsonAPI.toJsonUrl(ssp.root, username); String json; if(local){ diff --git a/Common/source/customskinloader/loader/ProfileLoader.java b/Common/source/customskinloader/loader/ProfileLoader.java index c9083fa..dbddc1b 100644 --- a/Common/source/customskinloader/loader/ProfileLoader.java +++ b/Common/source/customskinloader/loader/ProfileLoader.java @@ -12,8 +12,9 @@ public class ProfileLoader { new MojangAPILoader(), new JsonAPILoader(JsonAPILoader.Type.CustomSkinAPI), new JsonAPILoader(JsonAPILoader.Type.CustomSkinAPIPlus), - new LegacyLoader(), - new JsonAPILoader(JsonAPILoader.Type.UniSkinAPI)}; + new JsonAPILoader(JsonAPILoader.Type.UniSkinAPI), + new JsonAPILoader(JsonAPILoader.Type.ElyByAPI), + new LegacyLoader()}; public static final HashMap LOADERS=initLoaders(); diff --git a/Common/source/customskinloader/loader/jsonapi/ElyByAPI.java b/Common/source/customskinloader/loader/jsonapi/ElyByAPI.java new file mode 100644 index 0000000..033c2b1 --- /dev/null +++ b/Common/source/customskinloader/loader/jsonapi/ElyByAPI.java @@ -0,0 +1,50 @@ +package customskinloader.loader.jsonapi; + +import com.google.gson.Gson; +import com.google.gson.reflect.TypeToken; +import com.mojang.authlib.minecraft.MinecraftProfileTexture; +import com.mojang.authlib.minecraft.MinecraftProfileTexture.Type; +import customskinloader.config.SkinSiteProfile; +import customskinloader.loader.JsonAPILoader; +import customskinloader.profile.ModelManager0; +import customskinloader.profile.UserProfile; +import customskinloader.utils.MinecraftUtil; + +import java.net.URI; +import java.util.Map; + +public class ElyByAPI implements JsonAPILoader.IJsonAPI { + @Override + public String toJsonUrl(String root, String username) { + return "http://skinsystem.ely.by/textures/" + username + "?version=2&minecraft_version=" + MinecraftUtil.getMinecraftMainVersion(); + } + + @Override + public UserProfile toUserProfile(String root, String json, boolean local) { + Map result = new Gson().fromJson(json, new TypeToken>() { + }.getType()); + if (!result.containsKey(Type.SKIN)) + return null; + + //Check URL + try { + URI uri = new URI(result.get(Type.SKIN).getUrl()); + if (!uri.getHost().endsWith("ely.by")) + return null; + } catch (Exception e) { + return null; + } + + return ModelManager0.toUserProfile(result); + } + + @Override + public String getPayload(SkinSiteProfile ssp) { + return null; + } + + @Override + public String getName() { + return "ElyByAPI"; + } +} diff --git a/Common/source/customskinloader/profile/ModelManager0.java b/Common/source/customskinloader/profile/ModelManager0.java index 4f0f2b2..40e60dc 100644 --- a/Common/source/customskinloader/profile/ModelManager0.java +++ b/Common/source/customskinloader/profile/ModelManager0.java @@ -67,17 +67,17 @@ public class ModelManager0 { * @return profile - UserProfile instance * @since 13.1 */ - public static UserProfile toUserProfile(Map profile){ + public static UserProfile toUserProfile(Map profile){ UserProfile userProfile=new UserProfile(); if(profile==null) return userProfile; - MinecraftProfileTexture skin=(MinecraftProfileTexture)profile.get(Type.SKIN); + MinecraftProfileTexture skin = profile.get(Type.SKIN); userProfile.skinUrl= skin==null?null:skin.getUrl();//Avoid NullPointerException userProfile.model= skin==null?null:skin.getMetadata("model"); if(StringUtils.isEmpty(userProfile.model)) userProfile.model="default"; - MinecraftProfileTexture cape=(MinecraftProfileTexture)profile.get(Type.CAPE); + MinecraftProfileTexture cape = profile.get(Type.CAPE); userProfile.capeUrl= cape==null?null:cape.getUrl(); return userProfile; } diff --git a/Common/source/customskinloader/profile/UserProfile.java b/Common/source/customskinloader/profile/UserProfile.java index 7119647..84b4448 100644 --- a/Common/source/customskinloader/profile/UserProfile.java +++ b/Common/source/customskinloader/profile/UserProfile.java @@ -91,8 +91,10 @@ public class UserProfile { public void mix(UserProfile profile){ if(profile==null) return; - if(StringUtils.isEmpty(this.skinUrl)) - this.skinUrl=profile.skinUrl; + if(StringUtils.isEmpty(this.skinUrl)) { + this.skinUrl = profile.skinUrl; + this.model = profile.model; + } if(StringUtils.isEmpty(this.capeUrl)) this.capeUrl=profile.capeUrl; if(StringUtils.isEmpty(this.elytraUrl)) diff --git a/README.md b/README.md index dfbc1e2..8904e1e 100644 --- a/README.md +++ b/README.md @@ -14,6 +14,7 @@ Skin Load API Supported: - [CustomSkinAPI](https://github.com/xfl03/CustomSkinLoaderAPI/tree/master/CustomSkinAPI) - CustomSkinAPIPlus (Test Only) - [UniSkinAPI](https://github.com/RecursiveG/UniSkinServer/tree/master/doc) +- [ElfByAPI](http://docs.ely.by/api.html) - Legacy You can use this feature to customize your skin load list so as to load from any skin server you want.