2021-06-12 13:18:01 +02:00
|
|
|
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
|
|
|
|
From: Minecrell <minecrell@minecrell.net>
|
|
|
|
Date: Thu, 21 Sep 2017 19:41:20 +0200
|
|
|
|
Subject: [PATCH] Add workaround for plugins modifying the parent of the plugin
|
|
|
|
logger
|
|
|
|
|
|
|
|
Essentials uses a custom logger name ("Essentials") instead of the
|
|
|
|
plugin logger. Log messages are redirected to the plugin logger by
|
|
|
|
setting the parent of the "Essentials" logger to the plugin logger.
|
|
|
|
|
|
|
|
With our changes, the plugin logger is now also called "Essentials",
|
|
|
|
resulting in an infinite loop. Make sure plugins can't change the
|
|
|
|
parent of the plugin logger to avoid this.
|
|
|
|
|
|
|
|
diff --git a/src/main/java/com/destroystokyo/paper/utils/PaperPluginLogger.java b/src/main/java/com/destroystokyo/paper/utils/PaperPluginLogger.java
|
|
|
|
new file mode 100644
|
2023-02-19 15:57:10 +01:00
|
|
|
index 0000000000000000000000000000000000000000..087ee57fe5485bc760fadd45a176d4d90a18f9f8
|
2021-06-12 13:18:01 +02:00
|
|
|
--- /dev/null
|
|
|
|
+++ b/src/main/java/com/destroystokyo/paper/utils/PaperPluginLogger.java
|
2023-02-19 15:57:10 +01:00
|
|
|
@@ -0,0 +1,48 @@
|
2021-06-12 13:18:01 +02:00
|
|
|
+package com.destroystokyo.paper.utils;
|
|
|
|
+
|
2023-02-19 15:57:10 +01:00
|
|
|
+import io.papermc.paper.plugin.configuration.PluginMeta;
|
2021-06-12 13:18:01 +02:00
|
|
|
+import org.bukkit.plugin.PluginDescriptionFile;
|
|
|
|
+
|
|
|
|
+import java.util.logging.Level;
|
|
|
|
+import java.util.logging.LogManager;
|
|
|
|
+import java.util.logging.Logger;
|
|
|
|
+import org.jetbrains.annotations.NotNull;
|
|
|
|
+
|
|
|
|
+/**
|
|
|
|
+ * Prevents plugins (e.g. Essentials) from changing the parent of the plugin logger.
|
|
|
|
+ */
|
|
|
|
+public class PaperPluginLogger extends Logger {
|
|
|
|
+
|
2023-02-19 15:57:10 +01:00
|
|
|
+ @Deprecated(forRemoval = true)
|
2021-06-12 13:18:01 +02:00
|
|
|
+ @NotNull
|
|
|
|
+ public static Logger getLogger(@NotNull PluginDescriptionFile description) {
|
2023-02-19 15:57:10 +01:00
|
|
|
+ return getLogger((PluginMeta) description);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ @NotNull
|
|
|
|
+ public static Logger getLogger(@NotNull PluginMeta meta) {
|
|
|
|
+ Logger logger = new PaperPluginLogger(meta);
|
2021-06-12 13:18:01 +02:00
|
|
|
+ if (!LogManager.getLogManager().addLogger(logger)) {
|
|
|
|
+ // Disable this if it's going to happen across reloads anyways...
|
|
|
|
+ //logger.log(Level.WARNING, "Could not insert plugin logger - one was already found: {}", LogManager.getLogManager().getLogger(this.getName()));
|
2023-02-19 15:57:10 +01:00
|
|
|
+ logger = LogManager.getLogManager().getLogger(meta.getLoggerPrefix() != null ? meta.getLoggerPrefix() : meta.getName());
|
2021-06-12 13:18:01 +02:00
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ return logger;
|
|
|
|
+ }
|
|
|
|
+
|
2023-02-19 15:57:10 +01:00
|
|
|
+ private PaperPluginLogger(@NotNull PluginMeta meta) {
|
|
|
|
+ super(meta.getLoggerPrefix() != null ? meta.getLoggerPrefix() : meta.getName(), null);
|
2021-06-12 13:18:01 +02:00
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ @Override
|
|
|
|
+ public void setParent(@NotNull Logger parent) {
|
|
|
|
+ if (getParent() != null) {
|
|
|
|
+ warning("Ignoring attempt to change parent of plugin logger");
|
|
|
|
+ } else {
|
|
|
|
+ this.log(Level.FINE, "Setting plugin logger parent to {0}", parent);
|
|
|
|
+ super.setParent(parent);
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+}
|
|
|
|
diff --git a/src/main/java/org/bukkit/plugin/java/JavaPlugin.java b/src/main/java/org/bukkit/plugin/java/JavaPlugin.java
|
2023-02-22 04:27:49 +01:00
|
|
|
index 71c8d2345eef6895edb8d210553ec3cddd9c76d0..6d31f3a2569ae9c522a5e6cddd38ac8f252f1bfe 100644
|
2021-06-12 13:18:01 +02:00
|
|
|
--- a/src/main/java/org/bukkit/plugin/java/JavaPlugin.java
|
|
|
|
+++ b/src/main/java/org/bukkit/plugin/java/JavaPlugin.java
|
2023-02-19 15:57:10 +01:00
|
|
|
@@ -44,7 +44,7 @@ public abstract class JavaPlugin extends PluginBase {
|
2021-06-12 13:18:01 +02:00
|
|
|
private boolean naggable = true;
|
|
|
|
private FileConfiguration newConfig = null;
|
|
|
|
private File configFile = null;
|
|
|
|
- private Logger logger = null; // Paper - PluginLogger -> Logger
|
2023-02-19 15:57:10 +01:00
|
|
|
+ public Logger logger = null; // Paper - PluginLogger -> Logger, public
|
2021-06-12 13:18:01 +02:00
|
|
|
|
|
|
|
public JavaPlugin() {
|
2023-02-19 15:57:10 +01:00
|
|
|
// Paper start
|
2023-02-20 19:02:53 +01:00
|
|
|
@@ -302,7 +302,11 @@ public abstract class JavaPlugin extends PluginBase {
|
2021-06-12 13:18:01 +02:00
|
|
|
this.classLoader = classLoader;
|
|
|
|
this.configFile = new File(dataFolder, "config.yml");
|
2023-02-19 15:57:10 +01:00
|
|
|
this.pluginMeta = configuration; // Paper
|
|
|
|
- this.logger = Logger.getLogger(description.getPrefix() != null ? description.getPrefix() : description.getName()); // Paper - Handle plugin prefix in implementation
|
2021-06-12 13:18:01 +02:00
|
|
|
+ // Paper start
|
|
|
|
+ if (this.logger == null) {
|
|
|
|
+ this.logger = com.destroystokyo.paper.utils.PaperPluginLogger.getLogger(this.description);
|
|
|
|
+ }
|
|
|
|
+ // Paper end
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
diff --git a/src/main/java/org/bukkit/plugin/java/PluginClassLoader.java b/src/main/java/org/bukkit/plugin/java/PluginClassLoader.java
|
2023-02-22 04:27:49 +01:00
|
|
|
index dd569f2fc6098650d202e834b343b1bff2d42284..fade45ef475ae20922f5abea49a0f035d19b7819 100644
|
2021-06-12 13:18:01 +02:00
|
|
|
--- a/src/main/java/org/bukkit/plugin/java/PluginClassLoader.java
|
|
|
|
+++ b/src/main/java/org/bukkit/plugin/java/PluginClassLoader.java
|
2023-02-22 04:27:49 +01:00
|
|
|
@@ -64,7 +64,7 @@ public final class PluginClassLoader extends URLClassLoader implements io.paperm
|
2021-06-12 13:18:01 +02:00
|
|
|
this.url = file.toURI().toURL();
|
|
|
|
this.libraryLoader = libraryLoader;
|
|
|
|
|
2023-02-19 15:57:10 +01:00
|
|
|
-
|
2021-06-12 13:18:01 +02:00
|
|
|
+ this.logger = com.destroystokyo.paper.utils.PaperPluginLogger.getLogger(description); // Paper - Register logger early
|
2023-02-19 15:57:10 +01:00
|
|
|
// Paper start
|
|
|
|
this.classLoaderGroup = io.papermc.paper.plugin.provider.classloader.PaperClassLoaderStorage.instance().registerSpigotGroup(this); // Paper
|
2023-02-21 02:09:38 +01:00
|
|
|
// Paper end
|
2023-02-22 04:27:49 +01:00
|
|
|
@@ -247,6 +247,7 @@ public final class PluginClassLoader extends URLClassLoader implements io.paperm
|
2021-06-12 13:18:01 +02:00
|
|
|
pluginState = new IllegalStateException("Initial initialization");
|
|
|
|
this.pluginInit = javaPlugin;
|
|
|
|
|
|
|
|
+ javaPlugin.logger = this.logger; // Paper - set logger
|
2023-02-19 15:57:10 +01:00
|
|
|
javaPlugin.init(null, org.bukkit.Bukkit.getServer(), description, dataFolder, file, this); // Paper
|
2021-06-12 13:18:01 +02:00
|
|
|
}
|
2023-02-19 15:57:10 +01:00
|
|
|
|