Package org.bukkit.plugin.java
Class PluginClassLoader
java.lang.Object
java.lang.ClassLoader
java.security.SecureClassLoader
java.net.URLClassLoader
org.bukkit.plugin.java.PluginClassLoader
- All Implemented Interfaces:
ConfiguredPluginClassLoader
,Closeable
,AutoCloseable
@Internal
public final class PluginClassLoader
extends URLClassLoader
implements ConfiguredPluginClassLoader
A ClassLoader for plugins, to allow shared classes across multiple plugins
-
Field Summary
-
Constructor Summary
ConstructorDescriptionPluginClassLoader
(@Nullable ClassLoader parent, @NotNull PluginDescriptionFile description, @NotNull File dataFolder, @NotNull File file, @Nullable ClassLoader libraryLoader, JarFile jarFile, DependencyContext dependencyContext) -
Method Summary
Modifier and TypeMethodDescriptionvoid
close()
protected Class
<?> Provides the configuration of the plugin that this plugin classloader provides type access to.getGroup()
Get the plugin classloader group that is used by the underlying classloaderGets the plugin held by this class loader.getResource
(String name) getResources
(String name) void
init
(JavaPlugin plugin) Initializes both this configured plugin class loader and the java plugin passed to link to each other.void
initialize
(@NotNull JavaPlugin javaPlugin) Class
<?> Attempts to load a class from this plugin class loader using the passed fully qualified name.protected Class
<?> toString()
Methods inherited from class java.net.URLClassLoader
addURL, definePackage, 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, getSystemClassLoader, getSystemResource, getSystemResourceAsStream, getSystemResources, getUnnamedModule, isRegisteredAsParallelCapable, loadClass, registerAsParallelCapable, resolveClass, resources, setClassAssertionStatus, setDefaultAssertionStatus, setPackageAssertionStatus, setSigners
-
Field Details
-
dependencyContext
-
-
Constructor Details
-
PluginClassLoader
@Internal public PluginClassLoader(@Nullable @Nullable ClassLoader parent, @NotNull @NotNull PluginDescriptionFile description, @NotNull @NotNull File dataFolder, @NotNull @NotNull File file, @Nullable @Nullable ClassLoader libraryLoader, JarFile jarFile, DependencyContext dependencyContext) throws IOException, InvalidPluginException, MalformedURLException
-
-
Method Details
-
getResource
- Overrides:
getResource
in classClassLoader
-
getResources
- Overrides:
getResources
in classClassLoader
- Throws:
IOException
-
loadClass
public Class<?> loadClass(@NotNull @NotNull String name, boolean resolve, boolean checkGlobal, boolean checkLibraries) throws ClassNotFoundException Description copied from interface:ConfiguredPluginClassLoader
Attempts to load a class from this plugin class loader using the passed fully qualified name. This lookup logic can be configured through the following parameters to define how wide or how narrow the class lookup should be.- Specified by:
loadClass
in interfaceConfiguredPluginClassLoader
- Parameters:
name
- the fully qualified name of the class to loadresolve
- whether the class should be resolved if needed or notcheckGlobal
- whether this lookup should check transitive dependencies, including either the legacy spigot global class loader or the paperPluginClassLoaderGroup
checkLibraries
- whether the defined libraries should be checked for the class or not- Returns:
- the class found at the fully qualified class name passed under the passed restrictions
- Throws:
ClassNotFoundException
- if the class could not be found considering the passed restrictions- See Also:
-
getConfiguration
Description copied from interface:ConfiguredPluginClassLoader
Provides the configuration of the plugin that this plugin classloader provides type access to.- Specified by:
getConfiguration
in interfaceConfiguredPluginClassLoader
- Returns:
- the plugin meta instance, holding all meta information about the plugin instance.
-
init
Description copied from interface:ConfiguredPluginClassLoader
Initializes both this configured plugin class loader and the java plugin passed to link to each other. This logic is to be called exactly once when the initial setup between the class loader and the instantiatedJavaPlugin
is loaded.- Specified by:
init
in interfaceConfiguredPluginClassLoader
- Parameters:
plugin
- theJavaPlugin
that should be interlinked with this class loader.
-
getPlugin
Description copied from interface:ConfiguredPluginClassLoader
Gets the plugin held by this class loader.- Specified by:
getPlugin
in interfaceConfiguredPluginClassLoader
- Returns:
- the plugin or null if it doesn't exist yet
-
loadClass
- Overrides:
loadClass
in classClassLoader
- Throws:
ClassNotFoundException
-
findClass
- Overrides:
findClass
in classURLClassLoader
- Throws:
ClassNotFoundException
-
close
- Specified by:
close
in interfaceAutoCloseable
- Specified by:
close
in interfaceCloseable
- Overrides:
close
in classURLClassLoader
- Throws:
IOException
-
initialize
-
toString
-
getGroup
Description copied from interface:ConfiguredPluginClassLoader
Get the plugin classloader group that is used by the underlying classloader- Specified by:
getGroup
in interfaceConfiguredPluginClassLoader
- Returns:
- classloader
-