From cdc5740f85d362a194a135ae35945ba05fa06c0f Mon Sep 17 00:00:00 2001 From: "Kristian S. Stangeland" Date: Mon, 19 Nov 2012 23:27:04 +0100 Subject: [PATCH] Log the plugin version too. --- .../comphenix/protocol/ProtocolLibrary.java | 2 +- .../protocol/error/DetailedErrorReporter.java | 26 +++++++++++++++---- 2 files changed, 22 insertions(+), 6 deletions(-) diff --git a/ProtocolLib/src/main/java/com/comphenix/protocol/ProtocolLibrary.java b/ProtocolLib/src/main/java/com/comphenix/protocol/ProtocolLibrary.java index b97b35f9..772066fb 100644 --- a/ProtocolLib/src/main/java/com/comphenix/protocol/ProtocolLibrary.java +++ b/ProtocolLib/src/main/java/com/comphenix/protocol/ProtocolLibrary.java @@ -90,7 +90,7 @@ public class ProtocolLibrary extends JavaPlugin { logger = getLoggerSafely(); // Add global parameters - DetailedErrorReporter reporter = new DetailedErrorReporter(); + DetailedErrorReporter reporter = new DetailedErrorReporter(this); updater = new Updater(this, logger, "protocollib", getFile(), "protocol.info"); try { diff --git a/ProtocolLib/src/main/java/com/comphenix/protocol/error/DetailedErrorReporter.java b/ProtocolLib/src/main/java/com/comphenix/protocol/error/DetailedErrorReporter.java index bceb7dca..7fd85123 100644 --- a/ProtocolLib/src/main/java/com/comphenix/protocol/error/DetailedErrorReporter.java +++ b/ProtocolLib/src/main/java/com/comphenix/protocol/error/DetailedErrorReporter.java @@ -2,6 +2,7 @@ package com.comphenix.protocol.error; import java.io.PrintWriter; import java.io.StringWriter; +import java.lang.ref.WeakReference; import java.util.HashMap; import java.util.Map; import java.util.Set; @@ -40,6 +41,8 @@ public class DetailedErrorReporter implements ErrorReporter { protected int errorCount; protected int maxErrorCount; protected Logger logger; + + protected WeakReference pluginReference; // Whether or not Apache Commons is not present protected boolean apacheCommonsMissing; @@ -50,17 +53,18 @@ public class DetailedErrorReporter implements ErrorReporter { /** * Create a default error reporting system. */ - public DetailedErrorReporter() { - this(DEFAULT_PREFIX, DEFAULT_SUPPORT_URL); + public DetailedErrorReporter(Plugin plugin) { + this(plugin, DEFAULT_PREFIX, DEFAULT_SUPPORT_URL); } /** * Create a central error reporting system. + * @param plugin - the plugin owner. * @param prefix - default line prefix. * @param supportURL - URL to report the error. */ - public DetailedErrorReporter(String prefix, String supportURL) { - this(prefix, supportURL, DEFAULT_MAX_ERROR_COUNT, getBukkitLogger()); + public DetailedErrorReporter(Plugin plugin, String prefix, String supportURL) { + this(plugin, prefix, supportURL, DEFAULT_MAX_ERROR_COUNT, getBukkitLogger()); } // Attempt to get the logger. @@ -74,12 +78,17 @@ public class DetailedErrorReporter implements ErrorReporter { /** * Create a central error reporting system. + * @param plugin - the plugin owner. * @param prefix - default line prefix. * @param supportURL - URL to report the error. * @param maxErrorCount - number of errors to print before giving up. * @param logger - current logger. */ - public DetailedErrorReporter(String prefix, String supportURL, int maxErrorCount, Logger logger) { + public DetailedErrorReporter(Plugin plugin, String prefix, String supportURL, int maxErrorCount, Logger logger) { + if (plugin == null) + throw new IllegalArgumentException("Plugin cannot be NULL."); + + this.pluginReference = new WeakReference(plugin); this.prefix = prefix; this.supportURL = supportURL; this.maxErrorCount = maxErrorCount; @@ -157,6 +166,13 @@ public class DetailedErrorReporter implements ErrorReporter { writer.println("Sender:"); writer.println(addPrefix(getStringDescription(sender), SECOND_LEVEL_PREFIX)); + // And plugin + if (pluginReference.get() != null) { + Plugin plugin = pluginReference.get(); + writer.println("Version:"); + writer.println(addPrefix(plugin.toString() + "-" + plugin.getDescription().getVersion(), SECOND_LEVEL_PREFIX)); + } + // Add the server version too if (Bukkit.getServer() != null) { writer.println("Server:");