2019-03-08 13:38:44 +08:00
|
|
|
package customskinloader.plugin;
|
|
|
|
|
|
|
|
|
|
import java.io.File;
|
|
|
|
|
import java.net.MalformedURLException;
|
|
|
|
|
import java.net.URL;
|
|
|
|
|
import java.net.URLClassLoader;
|
|
|
|
|
import java.util.ArrayList;
|
|
|
|
|
import java.util.ServiceLoader;
|
|
|
|
|
|
2021-05-25 12:55:42 +08:00
|
|
|
import com.google.common.collect.Lists;
|
2019-03-08 13:38:44 +08:00
|
|
|
import customskinloader.CustomSkinLoader;
|
2021-04-24 10:33:18 +08:00
|
|
|
import customskinloader.loader.JsonAPILoader;
|
|
|
|
|
import customskinloader.loader.LegacyLoader;
|
|
|
|
|
import customskinloader.loader.MojangAPILoader;
|
2022-07-28 11:03:27 +08:00
|
|
|
import customskinloader.loader.jsonapi.*;
|
2021-04-24 10:33:18 +08:00
|
|
|
import org.apache.commons.io.FileUtils;
|
2019-03-08 13:38:44 +08:00
|
|
|
|
|
|
|
|
public class PluginLoader {
|
2022-07-28 11:03:27 +08:00
|
|
|
public static final ICustomSkinLoaderPlugin[] DEFAULT_PLUGINS = new ICustomSkinLoaderPlugin[]{
|
|
|
|
|
new MojangAPILoader(),
|
|
|
|
|
new LegacyLoader(),
|
|
|
|
|
new JsonAPILoader(new CustomSkinAPI()),
|
|
|
|
|
new JsonAPILoader(new CustomSkinAPIPlus()),
|
|
|
|
|
new JsonAPILoader(new UniSkinAPI()),
|
|
|
|
|
new JsonAPILoader(new ElyByAPI()),
|
|
|
|
|
new JsonAPILoader(new GlitchlessAPI()),
|
2023-01-11 22:06:58 +08:00
|
|
|
new JsonAPILoader(new MinecraftCapesAPI()),
|
|
|
|
|
new JsonAPILoader(new WynntilsAPI()),
|
2021-04-24 10:33:18 +08:00
|
|
|
};
|
2021-05-25 12:55:42 +08:00
|
|
|
public static final ArrayList<ICustomSkinLoaderPlugin> PLUGINS = loadPlugins();
|
2021-04-24 10:33:18 +08:00
|
|
|
|
2021-05-25 12:55:42 +08:00
|
|
|
private static ArrayList<ICustomSkinLoaderPlugin> loadPlugins() {
|
2019-03-08 13:38:44 +08:00
|
|
|
File pluginsDir = new File(CustomSkinLoader.DATA_DIR, "Plugins");
|
2021-05-25 12:55:42 +08:00
|
|
|
ArrayList<URL> urls = new ArrayList<>();
|
2019-03-08 13:38:44 +08:00
|
|
|
if (!pluginsDir.isDirectory()) {
|
2022-07-28 11:03:27 +08:00
|
|
|
//noinspection ResultOfMethodCallIgnored
|
2019-03-08 13:38:44 +08:00
|
|
|
pluginsDir.mkdirs();
|
|
|
|
|
} else {
|
2022-07-28 11:03:27 +08:00
|
|
|
for (File plugin : FileUtils.listFiles(pluginsDir, new String[]{"jar", "zip"}, false)) {
|
2019-03-08 13:38:44 +08:00
|
|
|
try {
|
|
|
|
|
urls.add(plugin.toURI().toURL());
|
|
|
|
|
CustomSkinLoader.logger.info("Found a jar or zip file: " + plugin.getName());
|
2022-07-28 11:03:27 +08:00
|
|
|
} catch (MalformedURLException ignored) {
|
|
|
|
|
}
|
2019-03-08 13:38:44 +08:00
|
|
|
}
|
|
|
|
|
}
|
2021-05-25 12:55:42 +08:00
|
|
|
ArrayList<ICustomSkinLoaderPlugin> plugins = Lists.newArrayList(DEFAULT_PLUGINS);
|
2021-04-24 10:33:18 +08:00
|
|
|
|
2019-03-08 13:38:44 +08:00
|
|
|
ServiceLoader<ICustomSkinLoaderPlugin> sl = ServiceLoader.load(ICustomSkinLoaderPlugin.class, new URLClassLoader(urls.toArray(new URL[0]), PluginLoader.class.getClassLoader()));
|
2021-04-24 10:33:18 +08:00
|
|
|
for (ICustomSkinLoaderPlugin plugin : sl) {
|
2021-05-25 12:55:42 +08:00
|
|
|
plugins.add(plugin);
|
2021-04-24 10:33:18 +08:00
|
|
|
}
|
|
|
|
|
return plugins;
|
|
|
|
|
}
|
2019-03-08 13:38:44 +08:00
|
|
|
}
|