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
-
-
Constructor Summary
Constructors Constructor Description PluginClassLoader(File file)
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description voidclose()static FiledisablePlugin(Plugin plugin)Used to disable pluginstatic FiledisablePlugin0(Plugin plugin)static 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, 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 pluginsPluginLoadException- if there is an error while enabling the pluginPluginUnloadException- if the plugin should be unloaded
-
disablePlugin
@Nullable 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()
-
close
public void close() throws IOException- Specified by:
closein interfaceAutoCloseable- Specified by:
closein interfaceCloseable- Overrides:
closein classURLClassLoader- Throws:
IOException
-
load
public boolean load()
-
findClass
public Class<?> findClass(String name, boolean resolve) throws ClassNotFoundException
- Throws:
ClassNotFoundException
-
-