From dc186df695f36d0b8290a0a68855c1e51d6c3eda Mon Sep 17 00:00:00 2001 From: "Kristian S. Stangeland" Date: Tue, 20 Nov 2012 06:48:05 +0100 Subject: [PATCH] Small fix for OpenJDK (FindBugs). --- .../comphenix/protocol/ProtocolLibrary.java | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) diff --git a/ProtocolLib/src/main/java/com/comphenix/protocol/ProtocolLibrary.java b/ProtocolLib/src/main/java/com/comphenix/protocol/ProtocolLibrary.java index 2e1fe58c..65a85100 100644 --- a/ProtocolLib/src/main/java/com/comphenix/protocol/ProtocolLibrary.java +++ b/ProtocolLib/src/main/java/com/comphenix/protocol/ProtocolLibrary.java @@ -79,6 +79,7 @@ public class ProtocolLibrary extends JavaPlugin { // Logger private Logger logger; + private Handler redirectHandler; // Commands private CommandProtocol commandProtocol; @@ -137,8 +138,12 @@ public class ProtocolLibrary extends JavaPlugin { } private void broadcastUsers(final String permission) { - // Broadcast information to every user too - logger.addHandler(new Handler() { + // Guard against multiple calls + if (redirectHandler != null) + return; + + // Broadcast information to every user too + redirectHandler = new Handler() { @Override public void publish(LogRecord record) { commandPacket.broadcastMessageSilently(record.getMessage(), permission); @@ -153,7 +158,9 @@ public class ProtocolLibrary extends JavaPlugin { public void close() throws SecurityException { // Do nothing. } - }); + }; + + logger.addHandler(redirectHandler); } @Override @@ -293,6 +300,11 @@ public class ProtocolLibrary extends JavaPlugin { asyncPacketTask = -1; } + // And redirect handler too + if (redirectHandler != null) { + logger.removeHandler(redirectHandler); + } + unhookTask.close(); protocolManager.close(); protocolManager = null;