Class ClassPreloader

java.lang.Object
fr.robie.machineengine.api.paper.ClassPreloader

public final class ClassPreloader extends Object
Loads a plugin's own classes when it starts. The JVM loads classes on first use, from the jar file; if the jar is replaced while the server runs (a rebuild on a dev server, an update copied over it), a class first used later fails with NoClassDefFoundError. The shutdown save is the worst place for that: machines would not be saved. With every class loaded up front, the running plugin no longer reads its jar.
  • Method Details

    • preload

      public static int preload(@NotNull @NotNull Class<?> anchor, @NotNull @NotNull String packagePrefix, @NotNull @NotNull String... skipped)
      Loads (without initializing) every class under packagePrefix in the jar of anchor. Classes that cannot load here (e.g. they need an optional plugin that is missing) are skipped.
      Parameters:
      packagePrefix - e.g. fr/robie/machineengine/
      skipped - prefixes under it never to load, e.g. the nms modules of other Minecraft versions: Java 25 classes make Paper 1.20.6's class loader throw (its ASM reads every class first), which is not a LinkageError
      Returns:
      how many classes were loaded