Class CraftsNetClassLoader
java.lang.Object
java.lang.ClassLoader
java.security.SecureClassLoader
java.net.URLClassLoader
de.craftsblock.craftsnet.addon.loaders.CraftsNetClassLoader
- All Implemented Interfaces:
Closeable,AutoCloseable
- Direct Known Subclasses:
AddonClassLoader,DependencyClassLoader
A specialized class loader for loading classes and resources in the context of a
CraftsNet instance.
This class loader supports parallel class loading and associates each loaded class with a specific
CraftsNet context.- Since:
- 3.5.0
- See Also:
-
Constructor Summary
ConstructorsConstructorDescriptionCraftsNetClassLoader(@NotNull CraftsNet craftsNet, @NotNull URL @NotNull [] urls) Constructs a newCraftsNetClassLoaderwith the specifiedCraftsNetinstance and URLs.CraftsNetClassLoader(@NotNull CraftsNet craftsNet, @NotNull URL @NotNull [] urls, @NotNull ClassLoader parent) Constructs a newCraftsNetClassLoaderwith the specifiedCraftsNetinstance, URLs, and parent class loader. -
Method Summary
Modifier and TypeMethodDescription@NotNull CraftsNetRetrieves theCraftsNetinstance which this class loader is linked to.static booleanChecks whether the calling class was loaded by aCraftsNetClassLoader.static booleanisCraftsNetLoaded(Class<?> type) Checks whether the given class was loaded by aCraftsNetClassLoader.static @Nullable CraftsNetAttempts to retrieve theCraftsNetinstance associated with the class loader of the calling class.static @Nullable CraftsNetretrieveCraftsNet(Class<?> type) Attempts to retrieve theCraftsNetinstance associated with the class loader of the given class.Methods inherited from class java.net.URLClassLoader
addURL, close, definePackage, findClass, findResource, findResources, getPermissions, getResourceAsStream, getURLs, newInstance, newInstanceMethods inherited from class java.security.SecureClassLoader
defineClass, defineClassMethods 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 Details
-
CraftsNetClassLoader
public CraftsNetClassLoader(@NotNull @NotNull CraftsNet craftsNet, @NotNull @NotNull URL @NotNull [] urls) Constructs a newCraftsNetClassLoaderwith the specifiedCraftsNetinstance and URLs. Uses the system class loader as the parent.- Parameters:
craftsNet- TheCraftsNetinstance this class loader is associated with.urls- The list of URLs from which to load classes and resources.
-
CraftsNetClassLoader
public CraftsNetClassLoader(@NotNull @NotNull CraftsNet craftsNet, @NotNull @NotNull URL @NotNull [] urls, @NotNull @NotNull ClassLoader parent) Constructs a newCraftsNetClassLoaderwith the specifiedCraftsNetinstance, URLs, and parent class loader.- Parameters:
craftsNet- TheCraftsNetinstance this class loader is associated with.urls- The list of URLs from which to load classes and resources.parent- The parent class loader for delegation.
-
-
Method Details
-
getCraftsNet
Retrieves theCraftsNetinstance which this class loader is linked to.- Returns:
- The
CraftsNetinstance.
-
retrieveCraftsNet
Attempts to retrieve theCraftsNetinstance associated with the class loader of the calling class. Returnsnullif the class was not loaded by aCraftsNetClassLoader.- Returns:
- The associated
CraftsNetinstance, ornullif unavailable.
-
retrieveCraftsNet
Attempts to retrieve theCraftsNetinstance associated with the class loader of the given class. Returnsnullif the class was not loaded by aCraftsNetClassLoader.- Parameters:
type- The class whose class loader should be checked.- Returns:
- The associated
CraftsNetinstance, ornullif unavailable.
-
isCraftsNetLoaded
public static boolean isCraftsNetLoaded()Checks whether the calling class was loaded by aCraftsNetClassLoader.- Returns:
trueif the calling class was loaded by aCraftsNetClassLoader,falseotherwise.
-
isCraftsNetLoaded
Checks whether the given class was loaded by aCraftsNetClassLoader.- Parameters:
type- The class to check.- Returns:
trueif the class was loaded by aCraftsNetClassLoader,falseotherwise.
-