mirror of
https://github.com/xfl03/MCCustomSkinLoader.git
synced 2026-11-18 13:49:16 +00:00
Fix CustomSkinAPIPlus loading incorrectly. Fix unable to complete config with default value. (#168)
This commit is contained in:
1 parent
3e001c4cdf
commit
4df8ce38d6
12 files changed
+240
-114
No files matched your search
@@ -3,11 +3,12 @@ package customskinloader.config;
|
||||
import java.io.File;
|
||||
import java.lang.reflect.Field;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Comparator;
|
||||
import java.util.List;
|
||||
import java.util.Objects;
|
||||
|
||||
import customskinloader.CustomSkinLoader;
|
||||
import customskinloader.loader.ProfileLoader;
|
||||
import customskinloader.plugin.ICustomSkinLoaderPlugin;
|
||||
import customskinloader.plugin.PluginLoader;
|
||||
import customskinloader.utils.HttpRequestUtil;
|
||||
import customskinloader.utils.HttpTextureUtil;
|
||||
@@ -41,9 +42,15 @@ public class Config {
|
||||
public boolean enableCacheAutoClean=false;
|
||||
public boolean forceDisableCache = false;
|
||||
|
||||
// Used by Gson to create an instance with default value.
|
||||
public Config() {
|
||||
this(new ArrayList<>());
|
||||
}
|
||||
|
||||
//Init config
|
||||
public Config(List<SkinSiteProfile> loadlist){
|
||||
this.version=CustomSkinLoader.CustomSkinLoader_VERSION;
|
||||
this.buildNumber=CustomSkinLoader.CustomSkinLoader_BUILD_NUMBER;
|
||||
this.loadlist=loadlist;
|
||||
}
|
||||
|
||||
@@ -85,12 +92,8 @@ public class Config {
|
||||
CustomSkinLoader.logger.info("Config File is out of date: " + config.version + ", build number: " + config.buildNumber);
|
||||
config.version = CustomSkinLoader.CustomSkinLoader_VERSION;
|
||||
config.buildNumber = CustomSkinLoader.CustomSkinLoader_BUILD_NUMBER;
|
||||
|
||||
//Update some config
|
||||
if (configVersion.compareTo("14.10") < 0)//Lower than 14.10
|
||||
config.enableCape = true;
|
||||
writeConfig(config, true);
|
||||
}
|
||||
writeConfig(config, true);
|
||||
|
||||
//Output config
|
||||
for (Field field : config.getClass().getDeclaredFields()) {
|
||||
@@ -184,22 +187,41 @@ public class Config {
|
||||
|
||||
// The config file does not exist or was broken.
|
||||
private static Config initConfig() {
|
||||
List<SkinSiteProfile> loadlist = new ArrayList<SkinSiteProfile>();
|
||||
PluginLoader.PLUGINS.forEach((name, plugin) -> {
|
||||
List<ICustomSkinLoaderPlugin.IDefaultProfile> profiles = new ArrayList<>();
|
||||
for (ICustomSkinLoaderPlugin plugin : PluginLoader.PLUGINS) {
|
||||
List<ICustomSkinLoaderPlugin.IDefaultProfile> defaultProfiles = plugin.getDefaultProfiles();
|
||||
if (defaultProfiles != null) {
|
||||
profiles.addAll(defaultProfiles);
|
||||
}
|
||||
}
|
||||
profiles.sort(Comparator.comparingInt(ICustomSkinLoaderPlugin.IDefaultProfile::getPriority));
|
||||
|
||||
List<SkinSiteProfile> loadlist = new ArrayList<>();
|
||||
for (ICustomSkinLoaderPlugin.IDefaultProfile profile : profiles) {
|
||||
SkinSiteProfile ssp = new SkinSiteProfile();
|
||||
ssp.name = name;
|
||||
plugin.updateSkinSiteProfile(ssp);
|
||||
ssp.name = profile.getName();
|
||||
profile.updateSkinSiteProfile(ssp);
|
||||
loadlist.add(ssp);
|
||||
});
|
||||
Config config=new Config(loadlist);
|
||||
writeConfig(config,false);
|
||||
}
|
||||
|
||||
Config config = new Config(loadlist);
|
||||
writeConfig(config, false);
|
||||
return config;
|
||||
}
|
||||
private static void writeConfig(Config config,boolean update){
|
||||
private static void writeConfig(Config config, boolean update){
|
||||
if (update && config.loadlist != null) { // Update loadlist, complete missing elements
|
||||
PluginLoader.PLUGINS.forEach((name, plugin) -> config.loadlist.stream()
|
||||
.filter(ssp -> Objects.equals(ssp.name, name))
|
||||
.forEach(plugin::updateSkinSiteProfile));
|
||||
for (ICustomSkinLoaderPlugin plugin : PluginLoader.PLUGINS) {
|
||||
List<ICustomSkinLoaderPlugin.IDefaultProfile> profiles = plugin.getDefaultProfiles();
|
||||
if (profiles != null) {
|
||||
for (ICustomSkinLoaderPlugin.IDefaultProfile profile : profiles) {
|
||||
for (SkinSiteProfile ssp : config.loadlist) {
|
||||
if (profile.getName().equals(ssp.name)) {
|
||||
profile.updateSkinSiteProfile(ssp);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
String json=CustomSkinLoader.GSON.toJson(config);
|
||||
|
||||
@@ -2,6 +2,7 @@ package customskinloader.loader;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.FileInputStream;
|
||||
import java.util.List;
|
||||
|
||||
import com.mojang.authlib.GameProfile;
|
||||
import customskinloader.CustomSkinLoader;
|
||||
@@ -16,8 +17,7 @@ import org.apache.commons.lang3.StringUtils;
|
||||
public class JsonAPILoader implements ICustomSkinLoaderPlugin, ProfileLoader.IProfileLoader {
|
||||
|
||||
public interface IJsonAPI {
|
||||
String getLoaderName();
|
||||
String getRoot();
|
||||
List<IDefaultProfile> getDefaultProfiles(JsonAPILoader loader);
|
||||
String toJsonUrl(String root, String username);
|
||||
String getPayload(SkinSiteProfile ssp);
|
||||
UserProfile toUserProfile(String root, String json, boolean local);
|
||||
@@ -41,14 +41,24 @@ public class JsonAPILoader implements ICustomSkinLoaderPlugin, ProfileLoader.IPr
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getLoaderName() {
|
||||
return this.jsonAPI.getLoaderName();
|
||||
public List<IDefaultProfile> getDefaultProfiles() {
|
||||
return this.jsonAPI.getDefaultProfiles(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void updateSkinSiteProfile(SkinSiteProfile ssp) {
|
||||
ssp.type = this.getName();
|
||||
ssp.root = this.jsonAPI.getRoot();
|
||||
public abstract static class DefaultProfile implements ICustomSkinLoaderPlugin.IDefaultProfile {
|
||||
protected final JsonAPILoader loader;
|
||||
|
||||
public DefaultProfile(JsonAPILoader loader) {
|
||||
this.loader = loader;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void updateSkinSiteProfile(SkinSiteProfile ssp) {
|
||||
ssp.type = this.loader.getName();
|
||||
ssp.root = this.getRoot();
|
||||
}
|
||||
|
||||
public abstract String getRoot();
|
||||
}
|
||||
|
||||
// === IProfileLoader ===
|
||||
|
||||
@@ -1,8 +1,10 @@
|
||||
package customskinloader.loader;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.List;
|
||||
import javax.annotation.Nonnull;
|
||||
|
||||
import com.google.common.collect.Lists;
|
||||
import com.mojang.authlib.GameProfile;
|
||||
import com.mojang.util.UUIDTypeAdapter;
|
||||
import customskinloader.CustomSkinLoader;
|
||||
@@ -15,9 +17,7 @@ import customskinloader.utils.HttpTextureUtil;
|
||||
import customskinloader.utils.HttpUtil0;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
|
||||
public abstract class LegacyLoader implements ICustomSkinLoaderPlugin, ProfileLoader.IProfileLoader {
|
||||
|
||||
// === ICustomSkinLoaderPlugin ===
|
||||
public class LegacyLoader implements ICustomSkinLoaderPlugin, ProfileLoader.IProfileLoader {
|
||||
|
||||
@Override
|
||||
public ProfileLoader.IProfileLoader getProfileLoader() {
|
||||
@@ -25,36 +25,50 @@ public abstract class LegacyLoader implements ICustomSkinLoaderPlugin, ProfileLo
|
||||
}
|
||||
|
||||
@Override
|
||||
public void updateSkinSiteProfile(SkinSiteProfile ssp) {
|
||||
ssp.type = this.getName();
|
||||
if (ssp.checkPNG == null) ssp.checkPNG = false;
|
||||
if (ssp.model == null) ssp.model = "auto";
|
||||
if (ssp.skin == null || !HttpUtil0.isLocal(this.getSkinRoot())) ssp.skin = this.getSkinRoot();
|
||||
if (ssp.cape == null || !HttpUtil0.isLocal(this.getCapeRoot())) ssp.cape = this.getCapeRoot();
|
||||
if (ssp.elytra == null || !HttpUtil0.isLocal(this.getElytraRoot())) ssp.elytra = this.getElytraRoot();
|
||||
public List<IDefaultProfile> getDefaultProfiles() {
|
||||
return Lists.newArrayList(new LocalSkin(this));
|
||||
}
|
||||
|
||||
public abstract String getSkinRoot();
|
||||
public abstract String getCapeRoot();
|
||||
public abstract String getElytraRoot();
|
||||
public abstract static class DefaultProfile implements ICustomSkinLoaderPlugin.IDefaultProfile {
|
||||
protected final LegacyLoader loader;
|
||||
|
||||
public static class LocalSkin extends LegacyLoader {
|
||||
@Override public String getLoaderName() { return "LocalSkin"; }
|
||||
public DefaultProfile(LegacyLoader loader) {
|
||||
this.loader = loader;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void updateSkinSiteProfile(SkinSiteProfile ssp) {
|
||||
ssp.type = this.loader.getName();
|
||||
if (ssp.checkPNG == null) ssp.checkPNG = false;
|
||||
if (ssp.model == null) ssp.model = "auto";
|
||||
if (ssp.skin == null || !HttpUtil0.isLocal(this.getSkinRoot())) ssp.skin = this.getSkinRoot();
|
||||
if (ssp.cape == null || !HttpUtil0.isLocal(this.getCapeRoot())) ssp.cape = this.getCapeRoot();
|
||||
if (ssp.elytra == null || !HttpUtil0.isLocal(this.getElytraRoot())) ssp.elytra = this.getElytraRoot();
|
||||
}
|
||||
|
||||
public abstract String getSkinRoot();
|
||||
public abstract String getCapeRoot();
|
||||
public abstract String getElytraRoot();
|
||||
}
|
||||
|
||||
public static class LocalSkin extends LegacyLoader.DefaultProfile {
|
||||
public LocalSkin(LegacyLoader loader) { super(loader); }
|
||||
@Override public String getName() { return "LocalSkin"; }
|
||||
@Override public int getPriority() { return 600; }
|
||||
@Override public String getSkinRoot() { return "LocalSkin/skins/{USERNAME}.png"; }
|
||||
@Override public String getCapeRoot() { return "LocalSkin/capes/{USERNAME}.png"; }
|
||||
@Override public String getElytraRoot() { return "LocalSkin/elytras/{USERNAME}.png"; }
|
||||
}
|
||||
|
||||
/* Minecrack could not load skin correctly
|
||||
public static class Minecrack extends LegacyLoader {
|
||||
@Override public String getLoaderName() { return "Minecrack"; }
|
||||
@Override public String getSkinRoot() { return "http://minecrack.fr.nf/mc/skinsminecrackd/{USERNAME}.png"; }
|
||||
@Override public String getCapeRoot() { return "http://minecrack.fr.nf/mc/cloaksminecrackd/{USERNAME}.png"; }
|
||||
@Override public String getElytraRoot() { return null; }
|
||||
}
|
||||
*/
|
||||
|
||||
// === IProfileLoader ===
|
||||
// // Minecrack could not load skin correctly
|
||||
// public static class Minecrack extends LegacyLoader.DefaultProfile {
|
||||
// public Minecrack(LegacyLoader loader) { super(loader); }
|
||||
// @Override public String getName() { return "Minecrack"; }
|
||||
// @Override public int getPriority() { return 600; }
|
||||
// @Override public String getSkinRoot() { return "http://minecrack.fr.nf/mc/skinsminecrackd/{USERNAME}.png"; }
|
||||
// @Override public String getCapeRoot() { return "http://minecrack.fr.nf/mc/cloaksminecrackd/{USERNAME}.png"; }
|
||||
// @Override public String getElytraRoot() { return null; }
|
||||
// }
|
||||
|
||||
public static final String USERNAME_PLACEHOLDER = "{USERNAME}";
|
||||
public static final String UUID_PLACEHOLDER = "{UUID}";
|
||||
|
||||
@@ -1,10 +1,12 @@
|
||||
package customskinloader.loader;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.UUID;
|
||||
|
||||
import com.google.common.collect.Iterables;
|
||||
import com.google.common.collect.Lists;
|
||||
import com.google.common.collect.Maps;
|
||||
import com.google.gson.Gson;
|
||||
import com.google.gson.GsonBuilder;
|
||||
@@ -25,9 +27,7 @@ import org.apache.commons.codec.Charsets;
|
||||
import org.apache.commons.codec.binary.Base64;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
|
||||
public abstract class MojangAPILoader implements ICustomSkinLoaderPlugin, ProfileLoader.IProfileLoader {
|
||||
|
||||
// === ICustomSkinLoaderPlugin ===
|
||||
public class MojangAPILoader implements ICustomSkinLoaderPlugin, ProfileLoader.IProfileLoader {
|
||||
|
||||
@Override
|
||||
public ProfileLoader.IProfileLoader getProfileLoader() {
|
||||
@@ -35,23 +35,36 @@ public abstract class MojangAPILoader implements ICustomSkinLoaderPlugin, Profil
|
||||
}
|
||||
|
||||
@Override
|
||||
public void updateSkinSiteProfile(SkinSiteProfile ssp) {
|
||||
ssp.type = this.getName();
|
||||
ssp.apiRoot = this.getAPIRoot();
|
||||
ssp.sessionRoot = this.getSessionRoot();
|
||||
public List<IDefaultProfile> getDefaultProfiles() {
|
||||
return Lists.newArrayList(new Mojang(this));
|
||||
}
|
||||
|
||||
public abstract String getAPIRoot();
|
||||
public abstract String getSessionRoot();
|
||||
public abstract static class DefaultProfile implements ICustomSkinLoaderPlugin.IDefaultProfile {
|
||||
protected final MojangAPILoader loader;
|
||||
|
||||
public static class Mojang extends MojangAPILoader {
|
||||
@Override public String getLoaderName() { return "Mojang"; }
|
||||
public DefaultProfile(MojangAPILoader loader) {
|
||||
this.loader = loader;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void updateSkinSiteProfile(SkinSiteProfile ssp) {
|
||||
ssp.type = this.loader.getName();
|
||||
ssp.apiRoot = this.getAPIRoot();
|
||||
ssp.sessionRoot = this.getSessionRoot();
|
||||
}
|
||||
|
||||
public abstract String getAPIRoot();
|
||||
public abstract String getSessionRoot();
|
||||
}
|
||||
|
||||
public static class Mojang extends MojangAPILoader.DefaultProfile {
|
||||
public Mojang(MojangAPILoader loader) { super(loader); }
|
||||
@Override public String getName() { return "Mojang"; }
|
||||
@Override public int getPriority() { return 100; }
|
||||
@Override public String getAPIRoot() { return getMojangApiRoot(); }
|
||||
@Override public String getSessionRoot() { return getMojangSessionRoot(); }
|
||||
}
|
||||
|
||||
// === IProfileLoader ===
|
||||
|
||||
@Override
|
||||
public UserProfile loadProfile(SkinSiteProfile ssp, GameProfile gameProfile) throws Exception {
|
||||
Map<MinecraftProfileTexture.Type, MinecraftProfileTexture> map = getTextures(gameProfile);
|
||||
|
||||
@@ -10,11 +10,11 @@ import customskinloader.plugin.PluginLoader;
|
||||
import customskinloader.profile.UserProfile;
|
||||
|
||||
public class ProfileLoader {
|
||||
public static final HashMap<String,IProfileLoader> LOADERS=initLoaders();
|
||||
public static final HashMap<String, IProfileLoader> LOADERS = initLoaders();
|
||||
|
||||
private static HashMap<String, IProfileLoader> initLoaders() {
|
||||
HashMap<String, ProfileLoader.IProfileLoader> profileLoaders = new HashMap<String, ProfileLoader.IProfileLoader>();
|
||||
for (ICustomSkinLoaderPlugin plugin : PluginLoader.PLUGINS.values()) {
|
||||
HashMap<String, ProfileLoader.IProfileLoader> profileLoaders = new HashMap<>();
|
||||
for (ICustomSkinLoaderPlugin plugin : PluginLoader.PLUGINS) {
|
||||
ProfileLoader.IProfileLoader profileLoader = plugin.getProfileLoader();
|
||||
if (profileLoader != null) {
|
||||
profileLoaders.put(profileLoader.getName().toLowerCase(), profileLoader);
|
||||
|
||||
@@ -1,38 +1,51 @@
|
||||
package customskinloader.loader.jsonapi;
|
||||
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import com.google.common.collect.Lists;
|
||||
import customskinloader.CustomSkinLoader;
|
||||
import customskinloader.config.SkinSiteProfile;
|
||||
import customskinloader.loader.JsonAPILoader;
|
||||
import customskinloader.plugin.ICustomSkinLoaderPlugin;
|
||||
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 class CustomSkinAPI implements JsonAPILoader.IJsonAPI {
|
||||
|
||||
public static class LittleSkin extends CustomSkinAPI {
|
||||
@Override public String getLoaderName() { return "LittleSkin"; }
|
||||
public static class LittleSkin extends JsonAPILoader.DefaultProfile {
|
||||
public LittleSkin(JsonAPILoader loader) { super(loader); }
|
||||
@Override public String getName() { return "LittleSkin"; }
|
||||
@Override public int getPriority() { return 200; }
|
||||
@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/"; }
|
||||
public static class BlessingSkin extends JsonAPILoader.DefaultProfile {
|
||||
public BlessingSkin(JsonAPILoader loader) { super(loader); }
|
||||
@Override public String getName() { return "BlessingSkin"; }
|
||||
@Override public int getPriority() { return 300; }
|
||||
@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/"; }
|
||||
}
|
||||
*/
|
||||
// // 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/"; }
|
||||
// }
|
||||
|
||||
private static final String TEXTURES="textures/";
|
||||
private static final String SUFFIX=".json";
|
||||
|
||||
@Override
|
||||
public List<ICustomSkinLoaderPlugin.IDefaultProfile> getDefaultProfiles(JsonAPILoader loader) {
|
||||
return Lists.newArrayList(new LittleSkin(loader), new BlessingSkin(loader));
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toJsonUrl(String root, String username) {
|
||||
return root + username + SUFFIX;
|
||||
|
||||
@@ -1,15 +1,19 @@
|
||||
package customskinloader.loader.jsonapi;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.List;
|
||||
import java.util.UUID;
|
||||
|
||||
import com.google.common.collect.Lists;
|
||||
import com.google.gson.Gson;
|
||||
import customskinloader.CustomSkinLoader;
|
||||
import customskinloader.config.SkinSiteProfile;
|
||||
import customskinloader.loader.JsonAPILoader;
|
||||
import customskinloader.plugin.ICustomSkinLoaderPlugin;
|
||||
import customskinloader.utils.MinecraftUtil;
|
||||
import org.apache.commons.io.FileUtils;
|
||||
|
||||
public abstract class CustomSkinAPIPlus extends CustomSkinAPI {
|
||||
public class CustomSkinAPIPlus extends CustomSkinAPI {
|
||||
|
||||
private static String clientID=null;
|
||||
public CustomSkinAPIPlus(){
|
||||
@@ -31,6 +35,11 @@ public abstract class CustomSkinAPIPlus extends CustomSkinAPI {
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<ICustomSkinLoaderPlugin.IDefaultProfile> getDefaultProfiles(JsonAPILoader loader) {
|
||||
return Lists.newArrayList();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getPayload(SkinSiteProfile ssp) {
|
||||
return new Gson().toJson(new CustomSkinAPIPlusPayload());
|
||||
|
||||
@@ -1,20 +1,30 @@
|
||||
package customskinloader.loader.jsonapi;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import com.google.common.collect.Lists;
|
||||
import com.google.gson.Gson;
|
||||
import com.google.gson.reflect.TypeToken;
|
||||
import com.mojang.authlib.minecraft.MinecraftProfileTexture;
|
||||
import customskinloader.config.SkinSiteProfile;
|
||||
import customskinloader.loader.JsonAPILoader;
|
||||
import customskinloader.plugin.ICustomSkinLoaderPlugin;
|
||||
import customskinloader.profile.ModelManager0;
|
||||
import customskinloader.profile.UserProfile;
|
||||
|
||||
public abstract class ElyByAPI implements JsonAPILoader.IJsonAPI {
|
||||
public class ElyByAPI implements JsonAPILoader.IJsonAPI {
|
||||
|
||||
public static class ElyBy extends ElyByAPI {
|
||||
@Override public String getLoaderName() { return "ElyBy"; }
|
||||
@Override public String getRoot() { return "http://skinsystem.ely.by/textures/"; }
|
||||
public static class ElyBy extends JsonAPILoader.DefaultProfile {
|
||||
public ElyBy(JsonAPILoader loader) { super(loader); }
|
||||
@Override public String getName() { return "ElyBy"; }
|
||||
@Override public int getPriority() { return 400; }
|
||||
@Override public String getRoot() { return "http://skinsystem.ely.by/textures/"; }
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<ICustomSkinLoaderPlugin.IDefaultProfile> getDefaultProfiles(JsonAPILoader loader) {
|
||||
return Lists.newArrayList(new ElyBy(loader));
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -1,19 +1,29 @@
|
||||
package customskinloader.loader.jsonapi;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import com.google.common.collect.Lists;
|
||||
import com.google.gson.Gson;
|
||||
import com.mojang.authlib.minecraft.MinecraftProfileTexture;
|
||||
import customskinloader.config.SkinSiteProfile;
|
||||
import customskinloader.loader.JsonAPILoader;
|
||||
import customskinloader.plugin.ICustomSkinLoaderPlugin;
|
||||
import customskinloader.profile.ModelManager0;
|
||||
import customskinloader.profile.UserProfile;
|
||||
|
||||
public abstract class GlitchlessAPI implements JsonAPILoader.IJsonAPI {
|
||||
public class GlitchlessAPI implements JsonAPILoader.IJsonAPI {
|
||||
|
||||
public static class GlitchlessGames extends GlitchlessAPI {
|
||||
@Override public String getLoaderName() { return "GlitchlessGames"; }
|
||||
@Override public String getRoot() { return "https://games.glitchless.ru/api/minecraft/users/profiles/textures/?nickname="; }
|
||||
public static class GlitchlessGames extends JsonAPILoader.DefaultProfile {
|
||||
public GlitchlessGames(JsonAPILoader loader) { super(loader); }
|
||||
@Override public String getName() { return "GlitchlessGames"; }
|
||||
@Override public int getPriority() { return 700; }
|
||||
@Override public String getRoot() { return "https://games.glitchless.ru/api/minecraft/users/profiles/textures/?nickname="; }
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<ICustomSkinLoaderPlugin.IDefaultProfile> getDefaultProfiles(JsonAPILoader loader) {
|
||||
return Lists.newArrayList(new GlitchlessGames(loader));
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -3,24 +3,33 @@ package customskinloader.loader.jsonapi;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import com.google.common.collect.Lists;
|
||||
import customskinloader.CustomSkinLoader;
|
||||
import customskinloader.config.SkinSiteProfile;
|
||||
import customskinloader.loader.JsonAPILoader;
|
||||
import customskinloader.plugin.ICustomSkinLoaderPlugin;
|
||||
import customskinloader.profile.ModelManager0;
|
||||
import customskinloader.profile.UserProfile;
|
||||
import customskinloader.utils.HttpTextureUtil;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
|
||||
public abstract class UniSkinAPI implements JsonAPILoader.IJsonAPI {
|
||||
public class UniSkinAPI implements JsonAPILoader.IJsonAPI {
|
||||
|
||||
public static class SkinMe extends UniSkinAPI {
|
||||
@Override public String getLoaderName() { return "SkinMe"; }
|
||||
@Override public String getRoot() { return "http://www.skinme.cc/uniskin/"; }
|
||||
public static class SkinMe extends JsonAPILoader.DefaultProfile {
|
||||
public SkinMe(JsonAPILoader loader) { super(loader); }
|
||||
@Override public String getName() { return "SkinMe"; }
|
||||
@Override public int getPriority() { return 500; }
|
||||
@Override public String getRoot() { return "http://www.skinme.cc/uniskin/"; }
|
||||
}
|
||||
|
||||
private static final String TEXTURES="textures/";
|
||||
private static final String SUFFIX=".json";
|
||||
|
||||
@Override
|
||||
public List<ICustomSkinLoaderPlugin.IDefaultProfile> getDefaultProfiles(JsonAPILoader loader) {
|
||||
return Lists.newArrayList(new SkinMe(loader));
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toJsonUrl(String root, String username) {
|
||||
return root + username + SUFFIX;
|
||||
|
||||
@@ -1,12 +1,35 @@
|
||||
package customskinloader.plugin;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import customskinloader.config.SkinSiteProfile;
|
||||
import customskinloader.loader.ProfileLoader;
|
||||
|
||||
public interface ICustomSkinLoaderPlugin {
|
||||
/**
|
||||
* @return return a non-null value if need to add a new profile loader, otherwise return null.
|
||||
*/
|
||||
ProfileLoader.IProfileLoader getProfileLoader();
|
||||
|
||||
String getLoaderName();
|
||||
/**
|
||||
* @return the default implementations which import by {@link ICustomSkinLoaderPlugin#getProfileLoader()}.
|
||||
*/
|
||||
List<IDefaultProfile> getDefaultProfiles();
|
||||
|
||||
void updateSkinSiteProfile(SkinSiteProfile ssp);
|
||||
interface IDefaultProfile {
|
||||
/**
|
||||
* @return the name of {@link SkinSiteProfile#name}.
|
||||
*/
|
||||
String getName();
|
||||
|
||||
/**
|
||||
* @return the lower the number, the first to load.
|
||||
*/
|
||||
int getPriority();
|
||||
|
||||
/**
|
||||
* Complete the {@link SkinSiteProfile} from config and write to config.
|
||||
*/
|
||||
void updateSkinSiteProfile(SkinSiteProfile ssp);
|
||||
}
|
||||
}
|
||||
@@ -5,35 +5,35 @@ import java.net.MalformedURLException;
|
||||
import java.net.URL;
|
||||
import java.net.URLClassLoader;
|
||||
import java.util.ArrayList;
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.ServiceLoader;
|
||||
|
||||
import com.google.common.collect.Lists;
|
||||
import customskinloader.CustomSkinLoader;
|
||||
import customskinloader.loader.JsonAPILoader;
|
||||
import customskinloader.loader.LegacyLoader;
|
||||
import customskinloader.loader.MojangAPILoader;
|
||||
import customskinloader.loader.jsonapi.CustomSkinAPI;
|
||||
import customskinloader.loader.jsonapi.CustomSkinAPIPlus;
|
||||
import customskinloader.loader.jsonapi.ElyByAPI;
|
||||
import customskinloader.loader.jsonapi.GlitchlessAPI;
|
||||
import customskinloader.loader.jsonapi.UniSkinAPI;
|
||||
import org.apache.commons.io.FileUtils;
|
||||
|
||||
public class PluginLoader {
|
||||
// This controls the default loading order.
|
||||
public static final ICustomSkinLoaderPlugin[] DEFAULT_PLUGINS = new ICustomSkinLoaderPlugin[] {
|
||||
new MojangAPILoader.Mojang(),
|
||||
new JsonAPILoader(new CustomSkinAPI.LittleSkin()),
|
||||
new JsonAPILoader(new CustomSkinAPI.BlessingSkin()),
|
||||
new JsonAPILoader(new ElyByAPI.ElyBy()),
|
||||
new JsonAPILoader(new UniSkinAPI.SkinMe()),
|
||||
new LegacyLoader.LocalSkin(),
|
||||
new JsonAPILoader(new GlitchlessAPI.GlitchlessGames())
|
||||
new MojangAPILoader(),
|
||||
new LegacyLoader(),
|
||||
new JsonAPILoader(new CustomSkinAPI()),
|
||||
new JsonAPILoader(new CustomSkinAPIPlus()),
|
||||
new JsonAPILoader(new UniSkinAPI()),
|
||||
new JsonAPILoader(new ElyByAPI()),
|
||||
new JsonAPILoader(new GlitchlessAPI())
|
||||
};
|
||||
public static final LinkedHashMap<String, ICustomSkinLoaderPlugin> PLUGINS = loadPlugins();
|
||||
public static final ArrayList<ICustomSkinLoaderPlugin> PLUGINS = loadPlugins();
|
||||
|
||||
private static LinkedHashMap<String, ICustomSkinLoaderPlugin> loadPlugins() {
|
||||
private static ArrayList<ICustomSkinLoaderPlugin> loadPlugins() {
|
||||
File pluginsDir = new File(CustomSkinLoader.DATA_DIR, "Plugins");
|
||||
ArrayList<URL> urls = new ArrayList<URL>();
|
||||
ArrayList<URL> urls = new ArrayList<>();
|
||||
if (!pluginsDir.isDirectory()) {
|
||||
pluginsDir.mkdirs();
|
||||
} else {
|
||||
@@ -44,19 +44,12 @@ public class PluginLoader {
|
||||
} catch (MalformedURLException ignored) {}
|
||||
}
|
||||
}
|
||||
LinkedHashMap<String, ICustomSkinLoaderPlugin> plugins = new LinkedHashMap<>();
|
||||
addPlugin(plugins, DEFAULT_PLUGINS);
|
||||
ArrayList<ICustomSkinLoaderPlugin> plugins = Lists.newArrayList(DEFAULT_PLUGINS);
|
||||
|
||||
ServiceLoader<ICustomSkinLoaderPlugin> sl = ServiceLoader.load(ICustomSkinLoaderPlugin.class, new URLClassLoader(urls.toArray(new URL[0]), PluginLoader.class.getClassLoader()));
|
||||
for (ICustomSkinLoaderPlugin plugin : sl) {
|
||||
plugins.put(plugin.getLoaderName(), plugin);
|
||||
plugins.add(plugin);
|
||||
}
|
||||
return plugins;
|
||||
}
|
||||
|
||||
public static void addPlugin(LinkedHashMap<String, ICustomSkinLoaderPlugin> pluginMap, ICustomSkinLoaderPlugin... plugins) {
|
||||
for (ICustomSkinLoaderPlugin plugin : plugins) {
|
||||
pluginMap.put(plugin.getLoaderName(), plugin);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user