From 4e30130da00de9d4edf1917cf8f77eefe7d866c2 Mon Sep 17 00:00:00 2001 From: Emily Date: Sat, 25 Mar 2023 03:30:48 -0300 Subject: [PATCH] Expose Path to jar file in PluginProviderContext (#9030) * Expose Path to jar file in PluginProviderContext * rename accessor, reword jd --- patches/api/Paper-Plugins.patch | 8 ++++++++ patches/server/Paper-Plugins.patch | 15 ++++++++++----- 2 files changed, 18 insertions(+), 5 deletions(-) diff --git a/patches/api/Paper-Plugins.patch b/patches/api/Paper-Plugins.patch index d4b3dba87f..dbbc7dea42 100644 --- a/patches/api/Paper-Plugins.patch +++ b/patches/api/Paper-Plugins.patch @@ -290,6 +290,14 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000 + @NotNull + ComponentLogger getLogger(); + ++ /** ++ * Provides the path to the originating source of the plugin, such as the plugin's JAR file. ++ * ++ * @return the previously described path ++ */ ++ @NotNull ++ Path getPluginSource(); ++ +} diff --git a/src/main/java/io/papermc/paper/plugin/configuration/PluginMeta.java b/src/main/java/io/papermc/paper/plugin/configuration/PluginMeta.java new file mode 100644 diff --git a/patches/server/Paper-Plugins.patch b/patches/server/Paper-Plugins.patch index 8e5b45fbe2..08ff10b757 100644 --- a/patches/server/Paper-Plugins.patch +++ b/patches/server/Paper-Plugins.patch @@ -609,18 +609,18 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000 +import java.nio.file.Path; + +public record PluginProviderContextImpl(PluginMeta config, Path dataFolder, -+ ComponentLogger logger) implements PluginProviderContext { ++ ComponentLogger logger, Path pluginSource) implements PluginProviderContext { + -+ public static PluginProviderContextImpl of(PluginMeta config, ComponentLogger logger) { ++ public static PluginProviderContextImpl of(PluginMeta config, ComponentLogger logger, Path pluginSource) { + Path dataFolder = PluginInitializerManager.instance().pluginDirectoryPath().resolve(config.getDisplayName()); + -+ return new PluginProviderContextImpl(config, dataFolder, logger); ++ return new PluginProviderContextImpl(config, dataFolder, logger, pluginSource); + } + + public static PluginProviderContextImpl of(PluginProvider provider, Path pluginFolder) { + Path dataFolder = pluginFolder.resolve(provider.getMeta().getDisplayName()); + -+ return new PluginProviderContextImpl(provider.getMeta(), dataFolder, provider.getLogger()); ++ return new PluginProviderContextImpl(provider.getMeta(), dataFolder, provider.getLogger(), provider.getSource()); + } + + @Override @@ -637,6 +637,11 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000 + public @NotNull ComponentLogger getLogger() { + return this.logger; + } ++ ++ @Override ++ public @NotNull Path getPluginSource() { ++ return this.pluginSource; ++ } +} diff --git a/src/main/java/io/papermc/paper/plugin/entrypoint/Entrypoint.java b/src/main/java/io/papermc/paper/plugin/entrypoint/Entrypoint.java new file mode 100644 @@ -5741,7 +5746,7 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000 + public PaperPluginParent build(JarFile file, PaperPluginMeta configuration, Path source) throws Exception { + Logger jul = PaperPluginLogger.getLogger(configuration); + ComponentLogger logger = ComponentLogger.logger(jul.getName()); -+ PluginProviderContext context = PluginProviderContextImpl.of(configuration, logger); ++ PluginProviderContext context = PluginProviderContextImpl.of(configuration, logger, source); + + PaperClasspathBuilder builder = new PaperClasspathBuilder(context); +