Files

144 lines
4.4 KiB
Java
Raw Permalink Normal View History

2016-08-09 17:23:27 +08:00
package customskinloader.loader.jsonapi;
2016-09-24 19:08:01 +08:00
import java.util.LinkedHashMap;
import java.util.List;
2016-08-09 17:23:27 +08:00
import java.util.Map;
import com.google.common.collect.Lists;
2016-08-09 17:23:27 +08:00
import customskinloader.CustomSkinLoader;
2021-04-24 10:33:18 +08:00
import customskinloader.loader.JsonAPILoader;
import customskinloader.plugin.ICustomSkinLoaderPlugin;
2016-08-09 17:23:27 +08:00
import customskinloader.profile.ModelManager0;
import customskinloader.profile.UserProfile;
import customskinloader.utils.HttpTextureUtil;
2021-04-24 10:33:18 +08:00
import org.apache.commons.lang3.StringUtils;
public class CustomSkinAPI implements JsonAPILoader.IJsonAPI {
2021-04-24 10:33:18 +08:00
public static class LittleSkin extends JsonAPILoader.DefaultProfile {
2023-01-11 22:06:58 +08:00
public LittleSkin(JsonAPILoader loader) {
super(loader);
}
@Override
public String getName() {
return "LittleSkin";
}
@Override
public int getPriority() {
return 200;
}
@Override
public String getRoot() {
return "https://littleskin.cn/csl/";
}
2021-04-24 10:33:18 +08:00
}
public static class BlessingSkin extends JsonAPILoader.DefaultProfile {
2023-01-11 22:06:58 +08:00
public BlessingSkin(JsonAPILoader loader) {
super(loader);
}
@Override
public String getName() {
return "BlessingSkin";
}
@Override
public int getPriority() {
return 300;
}
@Override
public String getRoot() {
return "https://skin.prinzeugen.net/";
}
2021-04-24 10:33:18 +08:00
}
// // OneSkin has been removed temporarily
// public static class OneSkin extends JsonAPILoader.DefaultProfile {
// public OneSkin(JsonAPILoader loader) { super(loader); }
// @Override public String getName() { return "OneSkin"; }
// @Override public int getPriority() { return 500; }
// @Override public String getRoot() { return "http://fleey.cn/skin/skin_user/skin_json.php/"; }
// }
2016-08-09 17:23:27 +08:00
2023-01-11 22:06:58 +08:00
private static final String TEXTURES = "textures/";
private static final String SUFFIX = ".json";
2016-08-09 17:23:27 +08:00
@Override
public List<ICustomSkinLoaderPlugin.IDefaultProfile> getDefaultProfiles(JsonAPILoader loader) {
return Lists.newArrayList(new LittleSkin(loader), new BlessingSkin(loader));
}
2018-02-12 12:20:28 +08:00
@Override
public String toJsonUrl(String root, String username) {
2018-06-25 00:34:32 +08:00
return root + username + SUFFIX;
2018-02-12 12:20:28 +08:00
}
2016-08-09 17:23:27 +08:00
2018-02-12 12:20:28 +08:00
@Override
public UserProfile toUserProfile(String root, String json, boolean local) {
2023-01-11 22:06:58 +08:00
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);
2018-02-12 12:20:28 +08:00
}
2023-01-11 22:06:58 +08:00
if (StringUtils.isNotBlank(profile.cape)) {
p.capeUrl = root + TEXTURES + profile.cape;
if (local)
p.capeUrl = HttpTextureUtil.getLocalFakeUrl(p.capeUrl);
2018-02-12 12:20:28 +08:00
}
2023-01-11 22:06:58 +08:00
if (StringUtils.isNotBlank(profile.elytra)) {
p.elytraUrl = root + TEXTURES + profile.elytra;
if (local)
p.elytraUrl = HttpTextureUtil.getLocalFakeUrl(p.elytraUrl);
2018-02-12 12:20:28 +08:00
}
2023-01-11 22:06:58 +08:00
Map<String, String> textures = new LinkedHashMap<>();
if (profile.skins != null)
2018-02-12 12:20:28 +08:00
textures.putAll(profile.skins);
2023-01-11 22:06:58 +08:00
if (profile.textures != null)
2018-02-12 12:20:28 +08:00
textures.putAll(profile.textures);
2023-01-11 22:06:58 +08:00
if (textures.isEmpty())
2018-02-12 12:20:28 +08:00
return p;
2023-01-11 22:06:58 +08:00
boolean hasSkin = false;
for (String model : textures.keySet()) {
ModelManager0.Model enumModel = ModelManager0.getEnumModel(model);
if (enumModel == null || StringUtils.isEmpty(textures.get(model)))
2018-02-12 12:20:28 +08:00
continue;
2023-01-11 22:06:58 +08:00
if (ModelManager0.isSkin(enumModel))
if (hasSkin)
2018-02-12 12:20:28 +08:00
continue;
else
2023-01-11 22:06:58 +08:00
hasSkin = true;
String url = root + TEXTURES + textures.get(model);
if (local)
url = HttpTextureUtil.getLocalFakeUrl(url);
2018-02-12 12:20:28 +08:00
p.put(enumModel, url);
}
2023-01-11 22:06:58 +08:00
2018-02-12 12:20:28 +08:00
return p;
}
2023-01-11 22:06:58 +08:00
private static class CustomSkinAPIProfile {
2018-02-12 12:20:28 +08:00
public String username;
2023-01-11 22:06:58 +08:00
public LinkedHashMap<String, String> textures;
public LinkedHashMap<String, String> skins;
2018-02-12 12:20:28 +08:00
public String skin;
public String cape;
public String elytra;
}
2023-01-11 22:06:58 +08:00
2018-02-12 12:20:28 +08:00
@Override
public String getName() {
return "CustomSkinAPI";
}
2016-08-09 17:23:27 +08:00
}