mirror of
https://github.com/xfl03/MCCustomSkinLoader.git
synced 2026-11-11 19:37:33 +00:00
* Enhance ICustomSkinLoaderPlugin. * Support auto update config file per snapshot. Fix crash with forge 1.14.2 ~ 1.15.2. * ElyByAPI should check root now. * Remove unnecessary packages, add some deprecated loaders. * Reformat imports. * Move forge stuffs to another commit. * Fix config updating incorrectly.
107 lines
3.6 KiB
Java
107 lines
3.6 KiB
Java
package customskinloader.loader.jsonapi;
|
|
|
|
import java.util.LinkedHashMap;
|
|
import java.util.Map;
|
|
|
|
import customskinloader.CustomSkinLoader;
|
|
import customskinloader.config.SkinSiteProfile;
|
|
import customskinloader.loader.JsonAPILoader;
|
|
import customskinloader.profile.ModelManager0;
|
|
import customskinloader.profile.UserProfile;
|
|
import customskinloader.utils.HttpTextureUtil;
|
|
import org.apache.commons.lang3.StringUtils;
|
|
|
|
public abstract class CustomSkinAPI implements JsonAPILoader.IJsonAPI {
|
|
|
|
public static class LittleSkin extends CustomSkinAPI {
|
|
@Override public String getLoaderName() { return "LittleSkin"; }
|
|
@Override public String getRoot() { return "https://littlesk.in/csl/"; }
|
|
}
|
|
|
|
public static class BlessingSkin extends CustomSkinAPI {
|
|
@Override public String getLoaderName() { return "BlessingSkin"; }
|
|
@Override public String getRoot() { return "http://skin.prinzeugen.net/"; }
|
|
}
|
|
|
|
/* OneSkin has been removed temporarily
|
|
public static class OneSkin extends CustomSkinAPI {
|
|
@Override public String getLoaderName() { return "OneSkin"; }
|
|
@Override public String getRoot() { return "http://fleey.cn/skin/skin_user/skin_json.php/"; }
|
|
}
|
|
*/
|
|
|
|
private static final String TEXTURES="textures/";
|
|
private static final String SUFFIX=".json";
|
|
|
|
@Override
|
|
public String toJsonUrl(String root, String username) {
|
|
return root + username + SUFFIX;
|
|
}
|
|
|
|
@Override
|
|
public UserProfile toUserProfile(String root, String json, boolean local) {
|
|
CustomSkinAPIProfile profile=CustomSkinLoader.GSON.fromJson(json, CustomSkinAPIProfile.class);
|
|
UserProfile p=new UserProfile();
|
|
|
|
if(StringUtils.isNotBlank(profile.skin)){
|
|
p.skinUrl=root+TEXTURES+profile.skin;
|
|
if(local)
|
|
p.skinUrl=HttpTextureUtil.getLocalFakeUrl(p.skinUrl);
|
|
}
|
|
if(StringUtils.isNotBlank(profile.cape)){
|
|
p.capeUrl=root+TEXTURES+profile.cape;
|
|
if(local)
|
|
p.capeUrl=HttpTextureUtil.getLocalFakeUrl(p.capeUrl);
|
|
}
|
|
if(StringUtils.isNotBlank(profile.elytra)){
|
|
p.elytraUrl=root+TEXTURES+profile.elytra;
|
|
if(local)
|
|
p.elytraUrl=HttpTextureUtil.getLocalFakeUrl(p.elytraUrl);
|
|
}
|
|
|
|
Map<String,String> textures=new LinkedHashMap<String,String>();
|
|
if(profile.skins!=null)
|
|
textures.putAll(profile.skins);
|
|
if(profile.textures!=null)
|
|
textures.putAll(profile.textures);
|
|
if(textures.isEmpty())
|
|
return p;
|
|
|
|
boolean hasSkin=false;
|
|
for(String model:textures.keySet()){
|
|
ModelManager0.Model enumModel=ModelManager0.getEnumModel(model);
|
|
if(enumModel==null||StringUtils.isEmpty(textures.get(model)))
|
|
continue;
|
|
if(ModelManager0.isSkin(enumModel))
|
|
if(hasSkin)
|
|
continue;
|
|
else
|
|
hasSkin=true;
|
|
String url=root+TEXTURES+textures.get(model);
|
|
if(local)
|
|
url=HttpTextureUtil.getLocalFakeUrl(url);
|
|
p.put(enumModel, url);
|
|
}
|
|
|
|
return p;
|
|
}
|
|
private static class CustomSkinAPIProfile{
|
|
public String username;
|
|
public LinkedHashMap<String,String> textures;
|
|
|
|
public LinkedHashMap<String,String> skins;
|
|
|
|
public String skin;
|
|
public String cape;
|
|
public String elytra;
|
|
}
|
|
@Override
|
|
public String getPayload(SkinSiteProfile ssp) {
|
|
return null;
|
|
}
|
|
@Override
|
|
public String getName() {
|
|
return "CustomSkinAPI";
|
|
}
|
|
}
|