From 4440e6fcaa5f8a22e9e31137526aac871f3d3a90 Mon Sep 17 00:00:00 2001 From: "Kristian S. Stangeland" Date: Wed, 12 Dec 2012 18:34:02 +0100 Subject: [PATCH] Prevent ProtocolLib from spamming the console too. --- .../protocol/error/DetailedErrorReporter.java | 21 ++++++++++++------- 1 file changed, 14 insertions(+), 7 deletions(-) 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 baec9121..9964f2c7 100644 --- a/ProtocolLib/src/main/java/com/comphenix/protocol/error/DetailedErrorReporter.java +++ b/ProtocolLib/src/main/java/com/comphenix/protocol/error/DetailedErrorReporter.java @@ -44,7 +44,8 @@ public class DetailedErrorReporter implements ErrorReporter { protected String prefix; protected String supportURL; - protected int errorCount; + protected AtomicInteger internalErrorCount = new AtomicInteger(); + protected int maxErrorCount; protected Logger logger; @@ -185,12 +186,18 @@ public class DetailedErrorReporter implements ErrorReporter { public void reportDetailed(Object sender, String message, Throwable error, Object... parameters) { final Plugin plugin = pluginReference.get(); + final int errorCount = internalErrorCount.incrementAndGet(); // Do not overtly spam the server! - if (++errorCount > maxErrorCount) { - String maxReached = String.format("Reached maxmimum error count. Cannot pass error %s from %s.", error, sender); - logger.severe(maxReached); - return; + if (errorCount > getMaxErrorCount()) { + // Only allow the error count at rare occations + if (isPowerOfTwo(errorCount)) { + // Permit it - but print the number of exceptions first + reportWarning(this, "Internal exception count: " + errorCount + "!"); + } else { + // NEVER SPAM THE CONSOLE + return; + } } StringWriter text = new StringWriter(); @@ -297,11 +304,11 @@ public class DetailedErrorReporter implements ErrorReporter { } public int getErrorCount() { - return errorCount; + return internalErrorCount.get(); } public void setErrorCount(int errorCount) { - this.errorCount = errorCount; + internalErrorCount.set(errorCount); } public int getMaxErrorCount() {