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

public abstract class CraftsNetClassLoader extends URLClassLoader
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 Details

    • CraftsNetClassLoader

      public CraftsNetClassLoader(@NotNull @NotNull CraftsNet craftsNet, @NotNull @NotNull URL @NotNull [] urls)
      Constructs a new CraftsNetClassLoader with the specified CraftsNet instance and URLs. Uses the system class loader as the parent.
      Parameters:
      craftsNet - The CraftsNet instance 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 new CraftsNetClassLoader with the specified CraftsNet instance, URLs, and parent class loader.
      Parameters:
      craftsNet - The CraftsNet instance 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

      @NotNull public @NotNull CraftsNet getCraftsNet()
      Retrieves the CraftsNet instance which this class loader is linked to.
      Returns:
      The CraftsNet instance.
    • retrieveCraftsNet

      @Nullable public static @Nullable CraftsNet retrieveCraftsNet()
      Attempts to retrieve the CraftsNet instance associated with the class loader of the calling class. Returns null if the class was not loaded by a CraftsNetClassLoader.
      Returns:
      The associated CraftsNet instance, or null if unavailable.
    • retrieveCraftsNet

      @Nullable public static @Nullable CraftsNet retrieveCraftsNet(Class<?> type)
      Attempts to retrieve the CraftsNet instance associated with the class loader of the given class. Returns null if the class was not loaded by a CraftsNetClassLoader.
      Parameters:
      type - The class whose class loader should be checked.
      Returns:
      The associated CraftsNet instance, or null if unavailable.
    • isCraftsNetLoaded

      public static boolean isCraftsNetLoaded()
      Checks whether the calling class was loaded by a CraftsNetClassLoader.
      Returns:
      true if the calling class was loaded by a CraftsNetClassLoader, false otherwise.
    • isCraftsNetLoaded

      public static boolean isCraftsNetLoaded(Class<?> type)
      Checks whether the given class was loaded by a CraftsNetClassLoader.
      Parameters:
      type - The class to check.
      Returns:
      true if the class was loaded by a CraftsNetClassLoader, false otherwise.