mirror of
https://github.com/xfl03/MCCustomSkinLoader.git
synced 2026-11-22 21:20:01 +00:00
Add CSLPluginsLoader (#48)
* Add CSLPluginsLoader * Remove plugin loader. Add some events. * Use ServiceLoader to load plugins * Remove PluginClassLoader.
This commit is contained in:
1 parent
42c48c5c2e
commit
cc3616a074
3 files changed
+48
No files matched your search
@@ -5,6 +5,7 @@ import java.util.HashMap;
|
||||
import com.mojang.authlib.GameProfile;
|
||||
|
||||
import customskinloader.config.SkinSiteProfile;
|
||||
import customskinloader.plugin.PluginLoader;
|
||||
import customskinloader.profile.UserProfile;
|
||||
|
||||
public class ProfileLoader {
|
||||
@@ -23,6 +24,7 @@ public class ProfileLoader {
|
||||
for(IProfileLoader loader:DEFAULT_LOADERS){
|
||||
loaders.put(loader.getName().toLowerCase(), loader);
|
||||
}
|
||||
loaders.putAll(PluginLoader.loadPlugins());
|
||||
return loaders;
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,7 @@
|
||||
package customskinloader.plugin;
|
||||
|
||||
import customskinloader.loader.ProfileLoader;
|
||||
|
||||
public interface ICustomSkinLoaderPlugin {
|
||||
ProfileLoader.IProfileLoader getProfileLoader();
|
||||
}
|
||||
@@ -0,0 +1,39 @@
|
||||
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.HashMap;
|
||||
import java.util.ServiceLoader;
|
||||
|
||||
import org.apache.commons.io.FileUtils;
|
||||
|
||||
import customskinloader.CustomSkinLoader;
|
||||
import customskinloader.loader.ProfileLoader;
|
||||
|
||||
public class PluginLoader {
|
||||
public static HashMap<String, ProfileLoader.IProfileLoader> loadPlugins() {
|
||||
File pluginsDir = new File(CustomSkinLoader.DATA_DIR, "Plugins");
|
||||
ArrayList<URL> urls = new ArrayList<URL>();
|
||||
if (!pluginsDir.isDirectory()) {
|
||||
pluginsDir.mkdirs();
|
||||
} else {
|
||||
for (File plugin : FileUtils.listFiles(pluginsDir, new String[] {"jar", "zip"}, false)) {
|
||||
try {
|
||||
urls.add(plugin.toURI().toURL());
|
||||
CustomSkinLoader.logger.info("Found a jar or zip file: " + plugin.getName());
|
||||
} catch (MalformedURLException ignored) {}
|
||||
}
|
||||
}
|
||||
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());
|
||||
}
|
||||
return profileLoaders;
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user