package vg.civcraft.mc.civmodcore.util;

import com.google.common.base.Strings;
import java.util.logging.LogRecord;
import java.util.logging.Logger;
import javax.annotation.Nonnull;
import org.apache.commons.lang3.reflect.FieldUtils;
import org.bukkit.plugin.java.PluginClassLoader;

public final class CivLogger extends Logger {

	private final String prefix;

	private CivLogger(final Logger logger, final String prefix) {
		super(logger.getName(), logger.getResourceBundleName());
		setParent(logger);
		this.prefix = prefix;
	}

	@Override
	public void log(final LogRecord record) {
		if (!Strings.isNullOrEmpty(this.prefix)) {
			record.setMessage("[" + this.prefix + "] " + record.getMessage());
		}
		super.log(record);
	}

	/**
	 * Creates a logger based on a given class. If the given class was loaded by a plugin, it will piggy back off that
	 * plugin's logger.
	 *
	 * @param clazz The class to base the logger on.
	 * @return Returns a new civ logger.
	 */
	public static CivLogger getLogger(@Nonnull final Class<?> clazz) {
		final ClassLoader classLoader = clazz.getClassLoader();
		if (classLoader instanceof PluginClassLoader) {
			final var plugin = ((PluginClassLoader) classLoader).getPlugin();
			if (plugin != null) {
				return new CivLogger(plugin.getLogger(), clazz.getSimpleName());
			}
			// Plugin has been constructed but not initialised yet
			final var loaderLoggerField = FieldUtils.getDeclaredField(PluginClassLoader.class, "logger", true);
			try {
				final var loaderLogger = (Logger) loaderLoggerField.get(classLoader);
				return new CivLogger(loaderLogger, clazz.getSimpleName());
			}
			catch (final IllegalAccessException ignored) {}
		}
		return new CivLogger(Logger.getLogger(CivLogger.class.getSimpleName()), clazz.getSimpleName());
	}

}

@@ -34,16 +34,72 @@
 .util;%0A%0A
+import com.destroystokyo.paper.utils.PaperPluginLogger;%0A
 import c
@@ -283,16 +283,64 @@
 dUtils;%0A
+import org.bukkit.plugin.PluginDescriptionFile;%0A
 import o
@@ -1482,28 +1482,27 @@
 nal var 
-loaderLogger
+description
 Field = 
@@ -1555,22 +1555,27 @@
 class, %22
-logger
+description
 %22, true)
@@ -1603,65 +1603,143 @@
 var 
-loaderLogger = (Logger) loaderLoggerField.get(classLoader
+description = (PluginDescriptionFile) descriptionField.get(classLoader);%0A%09%09%09%09final var logger = PaperPluginLogger.getLogger(description
 );%0A%09
@@ -1768,14 +1768,8 @@
 r(lo
-aderLo
 gger

Fix another CivLogger bug, hopefully last one