diff --git a/paper-server/src/main/java/io/papermc/paper/plugin/loader/PaperClasspathBuilder.java b/paper-server/src/main/java/io/papermc/paper/plugin/loader/PaperClasspathBuilder.java index f871a329eb..21a0a4e29c 100644 --- a/paper-server/src/main/java/io/papermc/paper/plugin/loader/PaperClasspathBuilder.java +++ b/paper-server/src/main/java/io/papermc/paper/plugin/loader/PaperClasspathBuilder.java @@ -41,15 +41,7 @@ public class PaperClasspathBuilder implements PluginClasspathBuilder { } public PaperPluginClassLoader buildClassLoader(Logger logger, Path source, JarFile jarFile, PaperPluginMeta configuration) { - PaperLibraryStore paperLibraryStore = new PaperLibraryStore(); - for (ClassPathLibrary library : this.libraries) { - library.register(paperLibraryStore); - } - - List paths = paperLibraryStore.getPaths(); - if (PluginInitializerManager.instance().pluginRemapper != null) { - paths = PluginInitializerManager.instance().pluginRemapper.remapLibraries(paths); - } + List paths = this.buildLibraryPaths(true); URL[] urls = new URL[paths.size()]; for (int i = 0; i < paths.size(); i++) { Path path = paths.get(i); @@ -69,4 +61,17 @@ public class PaperClasspathBuilder implements PluginClasspathBuilder { throw new RuntimeException(exception); } } + + public List buildLibraryPaths(final boolean remap) { + PaperLibraryStore paperLibraryStore = new PaperLibraryStore(); + for (ClassPathLibrary library : this.libraries) { + library.register(paperLibraryStore); + } + + List paths = paperLibraryStore.getPaths(); + if (remap && PluginInitializerManager.instance().pluginRemapper != null) { + paths = PluginInitializerManager.instance().pluginRemapper.remapLibraries(paths); + } + return paths; + } } diff --git a/paper-server/src/main/java/io/papermc/paper/plugin/provider/type/spigot/SpigotPluginProvider.java b/paper-server/src/main/java/io/papermc/paper/plugin/provider/type/spigot/SpigotPluginProvider.java index 75a2b687d5..0fd1040ed3 100644 --- a/paper-server/src/main/java/io/papermc/paper/plugin/provider/type/spigot/SpigotPluginProvider.java +++ b/paper-server/src/main/java/io/papermc/paper/plugin/provider/type/spigot/SpigotPluginProvider.java @@ -40,15 +40,17 @@ public class SpigotPluginProvider implements PluginProvider, Provide private final PluginDescriptionFile description; private final JarFile jarFile; private final Logger logger; + private final List paperLibraryPaths; private final ComponentLogger componentLogger; private ProviderStatus status; private DependencyContext dependencyContext; - SpigotPluginProvider(Path path, JarFile file, PluginDescriptionFile description) { + SpigotPluginProvider(Path path, JarFile file, PluginDescriptionFile description, List paperLibraryPaths) { this.path = path; this.jarFile = file; this.description = description; this.logger = PaperPluginLogger.getLogger(description); + this.paperLibraryPaths = paperLibraryPaths; this.componentLogger = ComponentLogger.logger(this.logger.getName()); } @@ -120,7 +122,7 @@ public class SpigotPluginProvider implements PluginProvider, Provide final PluginClassLoader loader; try { - loader = new PluginClassLoader(this.getClass().getClassLoader(), this.description, dataFolder, this.path.toFile(), LIBRARY_LOADER.createLoader(this.description), this.jarFile, this.dependencyContext); // Paper + loader = new PluginClassLoader(this.getClass().getClassLoader(), this.description, dataFolder, this.path.toFile(), LIBRARY_LOADER.createLoader(this.description, this.paperLibraryPaths), this.jarFile, this.dependencyContext); // Paper } catch (InvalidPluginException ex) { throw ex; } catch (Throwable ex) { diff --git a/paper-server/src/main/java/io/papermc/paper/plugin/provider/type/spigot/SpigotPluginProviderFactory.java b/paper-server/src/main/java/io/papermc/paper/plugin/provider/type/spigot/SpigotPluginProviderFactory.java index 1bf0fa1530..9edf79dffd 100644 --- a/paper-server/src/main/java/io/papermc/paper/plugin/provider/type/spigot/SpigotPluginProviderFactory.java +++ b/paper-server/src/main/java/io/papermc/paper/plugin/provider/type/spigot/SpigotPluginProviderFactory.java @@ -1,9 +1,18 @@ package io.papermc.paper.plugin.provider.type.spigot; +import com.destroystokyo.paper.utils.PaperPluginLogger; +import io.papermc.paper.plugin.bootstrap.PluginProviderContextImpl; import io.papermc.paper.plugin.entrypoint.classloader.BytecodeModifyingURLClassLoader; +import io.papermc.paper.plugin.entrypoint.classloader.PaperSimplePluginClassLoader; +import io.papermc.paper.plugin.loader.PaperClasspathBuilder; +import io.papermc.paper.plugin.loader.PluginLoader; import io.papermc.paper.plugin.provider.configuration.serializer.constraints.PluginConfigConstraints; import io.papermc.paper.plugin.provider.type.PluginTypeFactory; +import io.papermc.paper.plugin.provider.util.ProviderUtil; import io.papermc.paper.util.MappingEnvironment; +import java.util.List; +import java.util.logging.Logger; +import net.kyori.adventure.text.logger.slf4j.ComponentLogger; import org.bukkit.plugin.InvalidDescriptionException; import org.bukkit.plugin.PluginDescriptionFile; import org.bukkit.plugin.java.LibraryLoader; @@ -36,7 +45,28 @@ class SpigotPluginProviderFactory implements PluginTypeFactory paperLibraryPaths; + if (configuration.getPaperPluginLoader() != null) { + final Logger logger = PaperPluginLogger.getLogger(configuration); + PaperClasspathBuilder builder = new PaperClasspathBuilder(PluginProviderContextImpl.create( + configuration, ComponentLogger.logger(logger.getName()), source + )); + + try ( + PaperSimplePluginClassLoader simplePluginClassLoader = new PaperSimplePluginClassLoader(source, file, configuration, this.getClass().getClassLoader()) + ) { + PluginLoader loader = ProviderUtil.loadClass(configuration.getPaperPluginLoader(), PluginLoader.class, simplePluginClassLoader); + loader.classloader(builder); + } catch (IOException e) { + throw new RuntimeException(e); + } + + paperLibraryPaths = builder.buildLibraryPaths(false); + } else { + paperLibraryPaths = null; + } + + return new SpigotPluginProvider(source, file, configuration, paperLibraryPaths); } @Override