Class DynamicSoulPowerClassLoader

java.lang.Object
java.lang.ClassLoader
valorless.rarespawns.compilers.DynamicSoulPowerClassLoader

public class DynamicSoulPowerClassLoader extends ClassLoader
Dynamic class loader for RareSpawns Soul Powers.

This loader resolves compiled power classes from the plugin's data folder at runtime, specifically from: {pluginDataFolder}/soulpowers/compiled/. It expects a compiled .class file whose filename matches the provided class name (without package) and defines the class with that name.

Typical use is to hot-load custom Soul Power implementations that were compiled outside the main plugin JAR. The parent class loader (usually the plugin class loader) is preserved so that standard and plugin classes remain available.

Implementation note: this loader does not translate the class name into a package path. It looks for a single file named {name}.class directly under soulpowers/compiled, and defines the class with the given name. This implies that loaded classes should be compiled in the default package or with a name matching the simple class name provided.

Since:
1.0
  • Constructor Details

    • DynamicSoulPowerClassLoader

      public DynamicSoulPowerClassLoader(ClassLoader parent)
      Creates a new dynamic class loader that delegates to the given parent.
      Parameters:
      parent - the parent class loader to delegate to for standard lookups
  • Method Details

    • findClass

      public Class<?> findClass(String name) throws ClassNotFoundException
      Attempts to find and define a class by reading a compiled class file from disk.

      Lookup location: {pluginDataFolder}/soulpowers/compiled/{name}.class. The name is passed as-is to ClassLoader.defineClass(String, byte[], int, int) and is expected to be the simple (unqualified) class name that matches the file name.

      Overrides:
      findClass in class ClassLoader
      Parameters:
      name - the class name to load (expected to match the filename without the .class suffix)
      Returns:
      the defined Class object
      Throws:
      ClassNotFoundException - if the class file is missing or cannot be read/defined