diff --git a/ProtocolLib/src/main/java/com/comphenix/protocol/ProtocolConfig.java b/ProtocolLib/src/main/java/com/comphenix/protocol/ProtocolConfig.java
index 76bf8ebc..a2cec719 100644
--- a/ProtocolLib/src/main/java/com/comphenix/protocol/ProtocolConfig.java
+++ b/ProtocolLib/src/main/java/com/comphenix/protocol/ProtocolConfig.java
@@ -2,16 +2,16 @@
* ProtocolLib - Bukkit server library that allows access to the Minecraft protocol.
* Copyright (C) 2012 Kristian S. Stangeland
*
- * This program is free software; you can redistribute it and/or modify it under the terms of the
- * GNU General Public License as published by the Free Software Foundation; either version 2 of
+ * This program is free software; you can redistribute it and/or modify it under the terms of the
+ * GNU General Public License as published by the Free Software Foundation; either version 2 of
* the License, or (at your option) any later version.
*
- * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
- * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
+ * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
+ * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
* See the GNU General Public License for more details.
*
- * You should have received a copy of the GNU General Public License along with this program;
- * if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+ * You should have received a copy of the GNU General Public License along with this program;
+ * if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
* 02111-1307 USA
*/
@@ -44,7 +44,7 @@ public class ProtocolConfig {
private static final String METRICS_ENABLED = "metrics";
- private static final String IGNORE_VERSION_CHECK = "ignore version check";
+ private static final String IGNORE_VERSION_CHECK = "ignore version check";
private static final String BACKGROUND_COMPILER_ENABLED = "background compiler";
private static final String DEBUG_MODE_ENABLED = "debug";
@@ -167,10 +167,10 @@ public class ProtocolConfig {
config.options().copyDefaults(true);
plugin.saveDefaultConfig();
plugin.reloadConfig();
- loadingSections = false;
+ loadingSections = false;
// Inform the user
- System.out.println("[ProtocolLib] Created default configuration.");
+ ProtocolLibrary.log("Created default configuration.");
}
}
@@ -373,11 +373,11 @@ public class ProtocolConfig {
/**
* Set the last time we updated, in seconds since 1970.01.01 00:00.
*
- * Note that this is not considered to modify the configuration, so the modification count
+ * Note that this is not considered to modify the configuration, so the modification count
* will not be incremented.
* @param lastTimeSeconds - new last update time.
*/
- public void setAutoLastTime(long lastTimeSeconds) {
+ public void setAutoLastTime(long lastTimeSeconds) {
this.valuesChanged = true;
this.lastUpdateTime = lastTimeSeconds;
}
@@ -420,7 +420,7 @@ public class ProtocolConfig {
// Default hook if nothing has been set
PlayerInjectHooks hook = getDefaultMethod();
- if (text != null)
+ if (text != null)
hook = PlayerInjectHooks.valueOf(text.toUpperCase().replace(" ", "_"));
return hook;
}
diff --git a/ProtocolLib/src/main/java/com/comphenix/protocol/ProtocolLibrary.java b/ProtocolLib/src/main/java/com/comphenix/protocol/ProtocolLibrary.java
index 6768a0fb..089b36cb 100644
--- a/ProtocolLib/src/main/java/com/comphenix/protocol/ProtocolLibrary.java
+++ b/ProtocolLib/src/main/java/com/comphenix/protocol/ProtocolLibrary.java
@@ -19,6 +19,7 @@ package com.comphenix.protocol;
import java.io.File;
import java.io.IOException;
+import java.text.MessageFormat;
import java.util.Set;
import java.util.logging.Handler;
import java.util.logging.Level;
@@ -140,7 +141,7 @@ public class ProtocolLibrary extends JavaPlugin {
private int configExpectedMod = -1;
// Logger
- private Logger logger;
+ private static Logger logger;
private Handler redirectHandler;
// Commands
@@ -652,4 +653,14 @@ public class ProtocolLibrary extends JavaPlugin {
public static ListeningScheduledExecutorService getExecutorSync() {
return executorSync;
}
+
+ // ---- Logging
+
+ public static void log(Level level, String message, Object... args) {
+ logger.log(level, MessageFormat.format(message, args));
+ }
+
+ public static void log(String message, Object... args) {
+ log(Level.INFO, message, args);
+ }
}
diff --git a/ProtocolLib/src/main/java/com/comphenix/protocol/async/AsyncMarker.java b/ProtocolLib/src/main/java/com/comphenix/protocol/async/AsyncMarker.java
index e919c5a1..5bcd077b 100644
--- a/ProtocolLib/src/main/java/com/comphenix/protocol/async/AsyncMarker.java
+++ b/ProtocolLib/src/main/java/com/comphenix/protocol/async/AsyncMarker.java
@@ -24,9 +24,11 @@ import java.lang.reflect.Method;
import java.util.Iterator;
import java.util.List;
import java.util.concurrent.atomic.AtomicInteger;
+import java.util.logging.Level;
import com.comphenix.protocol.PacketStream;
import com.comphenix.protocol.PacketType;
+import com.comphenix.protocol.ProtocolLibrary;
import com.comphenix.protocol.events.NetworkMarker;
import com.comphenix.protocol.events.PacketEvent;
import com.comphenix.protocol.injector.PrioritizedListener;
@@ -426,7 +428,7 @@ public class AsyncMarker implements Serializable, Comparable {
// Incoming chat packets are async only if they aren't commands
return ! content.startsWith("/");
} else {
- System.err.println("[ProtocolLib] Failed to determine contents of incoming chat packet!");
+ ProtocolLibrary.log(Level.WARNING, "Failed to determine contents of incoming chat packet!");
alwaysSync = true;
}
} else {
@@ -434,7 +436,7 @@ public class AsyncMarker implements Serializable, Comparable {
return false;
}
} else {
- System.err.println("[ProtocolLib] Cannot determine asynchronous state of packets!");
+ ProtocolLibrary.log(Level.WARNING, "Cannot determine asynchronous state of packets!");
alwaysSync = true;
}
}
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 16eb4ada..9593c4f7 100644
--- a/ProtocolLib/src/main/java/com/comphenix/protocol/error/DetailedErrorReporter.java
+++ b/ProtocolLib/src/main/java/com/comphenix/protocol/error/DetailedErrorReporter.java
@@ -35,6 +35,7 @@ import org.apache.commons.lang.builder.ToStringStyle;
import org.bukkit.Bukkit;
import org.bukkit.plugin.Plugin;
+import com.comphenix.protocol.ProtocolLibrary;
import com.comphenix.protocol.collections.ExpireHashMap;
import com.comphenix.protocol.error.Report.ReportBuilder;
import com.comphenix.protocol.events.PacketAdapter;
@@ -456,7 +457,7 @@ public class DetailedErrorReporter implements ErrorReporter {
apacheCommonsMissing = true;
} catch (Exception e) {
// Don't use the error logger to log errors in error logging (that could lead to infinite loops)
- System.err.print("[ProtocolLib] Warning: Cannot convert to a String with Apache: " + e.getMessage());
+ ProtocolLibrary.log(Level.WARNING, "Cannot convert to a String with Apache: " + e.getMessage());
}
// Use our custom object printer instead
diff --git a/ProtocolLib/src/main/java/com/comphenix/protocol/injector/netty/ChannelInjector.java b/ProtocolLib/src/main/java/com/comphenix/protocol/injector/netty/ChannelInjector.java
index 93e680aa..8ab08bdb 100644
--- a/ProtocolLib/src/main/java/com/comphenix/protocol/injector/netty/ChannelInjector.java
+++ b/ProtocolLib/src/main/java/com/comphenix/protocol/injector/netty/ChannelInjector.java
@@ -14,6 +14,7 @@ import io.netty.handler.codec.MessageToByteEncoder;
import io.netty.util.concurrent.GenericFutureListener;
import io.netty.util.internal.TypeParameterMatcher;
+import java.lang.ref.WeakReference;
import java.lang.reflect.InvocationTargetException;
import java.net.Socket;
import java.net.SocketAddress;
@@ -84,9 +85,10 @@ class ChannelInjector extends ByteToMessageDecoder implements Injector {
// The factory that created this injector
private InjectionFactory factory;
- // The player, or temporary player
- private Player player;
- private Player updated;
+ // The player
+ private WeakReference player;
+ private WeakReference updated;
+ private String playerName;
// The player connection
private Object playerConnection;
@@ -149,7 +151,7 @@ class ChannelInjector extends ByteToMessageDecoder implements Injector {
* @param factory - the factory that created this injector
*/
public ChannelInjector(Player player, Object networkManager, Channel channel, ChannelListener channelListener, InjectionFactory factory) {
- this.player = Preconditions.checkNotNull(player, "player cannot be NULL");
+ this.player = new WeakReference(Preconditions.checkNotNull(player, "player cannot be NULL"));
this.networkManager = Preconditions.checkNotNull(networkManager, "networkMananger cannot be NULL");
this.originalChannel = Preconditions.checkNotNull(channel, "channel cannot be NULL");
this.channelListener = Preconditions.checkNotNull(channelListener, "channelListener cannot be NULL");
@@ -486,6 +488,11 @@ class ChannelInjector extends ByteToMessageDecoder implements Injector {
// Reset queue
finishQueue.clear();
+ if (player.get() == null) {
+ ProtocolLibrary.log("Failed to intercept client packet for {0}: Invalid player.", playerName);
+ return;
+ }
+
for (ListIterator