mirror of
https://github.com/xfl03/MCCustomSkinLoader.git
synced 2026-11-26 08:02:59 +00:00
Enhanced default skin loaders. (#157)
* 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.
This commit is contained in:
1 parent
c84f506af1
commit
6c9494970f
17 files changed
+286
-218
No files matched your search
@@ -5,16 +5,33 @@ import java.net.MalformedURLException;
|
||||
import java.net.URL;
|
||||
import java.net.URLClassLoader;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.ServiceLoader;
|
||||
|
||||
import customskinloader.CustomSkinLoader;
|
||||
import customskinloader.loader.JsonAPILoader;
|
||||
import customskinloader.loader.LegacyLoader;
|
||||
import customskinloader.loader.MojangAPILoader;
|
||||
import customskinloader.loader.jsonapi.CustomSkinAPI;
|
||||
import customskinloader.loader.jsonapi.ElyByAPI;
|
||||
import customskinloader.loader.jsonapi.GlitchlessAPI;
|
||||
import customskinloader.loader.jsonapi.UniSkinAPI;
|
||||
import org.apache.commons.io.FileUtils;
|
||||
|
||||
import customskinloader.CustomSkinLoader;
|
||||
import customskinloader.loader.ProfileLoader;
|
||||
|
||||
public class PluginLoader {
|
||||
public static HashMap<String, ProfileLoader.IProfileLoader> loadPlugins() {
|
||||
// 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())
|
||||
};
|
||||
public static final LinkedHashMap<String, ICustomSkinLoaderPlugin> PLUGINS = loadPlugins();
|
||||
|
||||
private static LinkedHashMap<String, ICustomSkinLoaderPlugin> loadPlugins() {
|
||||
File pluginsDir = new File(CustomSkinLoader.DATA_DIR, "Plugins");
|
||||
ArrayList<URL> urls = new ArrayList<URL>();
|
||||
if (!pluginsDir.isDirectory()) {
|
||||
@@ -27,13 +44,19 @@ public class PluginLoader {
|
||||
} catch (MalformedURLException ignored) {}
|
||||
}
|
||||
}
|
||||
LinkedHashMap<String, ICustomSkinLoaderPlugin> plugins = new LinkedHashMap<>();
|
||||
addPlugin(plugins, DEFAULT_PLUGINS);
|
||||
|
||||
ServiceLoader<ICustomSkinLoaderPlugin> sl = ServiceLoader.load(ICustomSkinLoaderPlugin.class, new URLClassLoader(urls.toArray(new URL[0]), PluginLoader.class.getClassLoader()));
|
||||
HashMap<String, ProfileLoader.IProfileLoader> profileLoaders = new HashMap<String, ProfileLoader.IProfileLoader>();
|
||||
for (ICustomSkinLoaderPlugin cslPlugin : sl) {
|
||||
ProfileLoader.IProfileLoader profileLoader = cslPlugin.getProfileLoader();
|
||||
profileLoaders.put(profileLoader.getName().toLowerCase(), profileLoader);
|
||||
CustomSkinLoader.logger.info("Add profile loader: " + profileLoader.getName());
|
||||
for (ICustomSkinLoaderPlugin plugin : sl) {
|
||||
plugins.put(plugin.getLoaderName(), plugin);
|
||||
}
|
||||
return plugins;
|
||||
}
|
||||
|
||||
public static void addPlugin(LinkedHashMap<String, ICustomSkinLoaderPlugin> pluginMap, ICustomSkinLoaderPlugin... plugins) {
|
||||
for (ICustomSkinLoaderPlugin plugin : plugins) {
|
||||
pluginMap.put(plugin.getLoaderName(), plugin);
|
||||
}
|
||||
return profileLoaders;
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user