Package top.focess.qq.core.plugin
Class PluginClassLoader
- java.lang.Object
-
- java.lang.ClassLoader
-
- java.security.SecureClassLoader
-
- java.net.URLClassLoader
-
- top.focess.qq.core.plugin.PluginClassLoader
-
- All Implemented Interfaces:
Closeable,AutoCloseable
public class PluginClassLoader extends URLClassLoader
-
-
Field Summary
Fields Modifier and Type Field Description static Map<Class<? extends Plugin>,Plugin>CLASS_PLUGIN_MAPstatic Map<String,Plugin>NAME_PLUGIN_MAPstatic List<Plugin>REGISTERED_PLUGINS
-
Constructor Summary
Constructors Constructor Description PluginClassLoader(File file)
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description static FiledisablePlugin(Plugin plugin)Used to disable pluginstatic voidenablePlugin(Plugin plugin)Used to enable pluginClass<?>findClass(String name, boolean resolve)FilegetFile()Set<Class<?>>getLoadedClasses()PlugingetPlugin()static <T extends Plugin>
TgetPlugin(Class<T> plugin)Get Plugin instance by the class instancestatic PlugingetPlugin(String name)Get Plugin instance by the namePluginDescriptiongetPluginDescription()static List<Plugin>getPlugins()Get all plugins registeredbooleanload()-
Methods inherited from class java.net.URLClassLoader
addURL, close, definePackage, findClass, findResource, findResources, getPermissions, getResourceAsStream, getURLs, newInstance, newInstance
-
Methods inherited from class java.security.SecureClassLoader
defineClass, defineClass
-
Methods inherited from class java.lang.ClassLoader
clearAssertionStatus, defineClass, defineClass, defineClass, defineClass, definePackage, findClass, findLibrary, findLoadedClass, findResource, findSystemClass, getClassLoadingLock, getDefinedPackage, getDefinedPackages, getName, getPackage, getPackages, getParent, getPlatformClassLoader, getResource, getResources, getSystemClassLoader, getSystemResource, getSystemResourceAsStream, getSystemResources, getUnnamedModule, isRegisteredAsParallelCapable, loadClass, loadClass, registerAsParallelCapable, resolveClass, resources, setClassAssertionStatus, setDefaultAssertionStatus, setPackageAssertionStatus, setSigners
-
-
-
-
Constructor Detail
-
PluginClassLoader
public PluginClassLoader(@NotNull File file) throws MalformedURLException- Throws:
MalformedURLException
-
-
Method Detail
-
getPluginDescription
public PluginDescription getPluginDescription()
-
enablePlugin
public static void enablePlugin(Plugin plugin)
Used to enable plugin- Parameters:
plugin- the plugin need to be enabled- Throws:
PluginLoaderException- if the classloader of the plugin is notPluginClassLoaderPluginDuplicateException- if the plugin name already exists in the registered plugins
-
disablePlugin
public static File disablePlugin(Plugin plugin)
Used to disable plugin- Parameters:
plugin- the plugin need to be disabled- Returns:
- the plugin jar file, or null if the plugin is MainPlugin
-
getPlugin
@Nullable public static <T extends Plugin> T getPlugin(Class<T> plugin)
Get Plugin instance by the class instance- Type Parameters:
T- the plugin type- Parameters:
plugin- the class instance of the plugin- Returns:
- the plugin instance
- See Also:
Plugin.getPlugin(Class)
-
getPlugins
@NotNull public static List<Plugin> getPlugins()
Get all plugins registered- Returns:
- a list of registered plugins
-
getPlugin
@Nullable public static Plugin getPlugin(String name)
Get Plugin instance by the name- Parameters:
name- the name of the plugin- Returns:
- the plugin instance
- See Also:
Plugin.getPlugin(String)
-
getFile
public File getFile()
-
getPlugin
public Plugin getPlugin()
-
load
public boolean load()
-
findClass
public Class<?> findClass(String name, boolean resolve) throws ClassNotFoundException
- Throws:
ClassNotFoundException
-
-