diff --git a/ProtocolLib/src/main/java/com/comphenix/protocol/injector/player/PlayerInjector.java b/ProtocolLib/src/main/java/com/comphenix/protocol/injector/player/PlayerInjector.java index 8f84cdd0..26acc9e6 100644 --- a/ProtocolLib/src/main/java/com/comphenix/protocol/injector/player/PlayerInjector.java +++ b/ProtocolLib/src/main/java/com/comphenix/protocol/injector/player/PlayerInjector.java @@ -24,6 +24,7 @@ import java.lang.reflect.InvocationTargetException; import java.lang.reflect.Method; import java.net.Socket; import java.net.SocketAddress; +import java.util.concurrent.Callable; import net.sf.cglib.proxy.Factory; @@ -100,7 +101,7 @@ abstract class PlayerInjector { protected ErrorReporter reporter; // Scheduled action on the next packet event - protected Runnable scheduledAction; + protected Callable scheduledAction; // Whether or not the injector has been cleaned private boolean clean; @@ -519,9 +520,16 @@ abstract class PlayerInjector { // Hack #1: Handle a single scheduled action if (scheduledAction != null) { - scheduledAction.run(); - scheduledAction = null; + try { + if (scheduledAction.call()) { + scheduledAction = null; + } + } catch (Exception e) { + reporter.reportDetailed(this, "Cannot perform hack #1.", e, scheduledAction, packet); + scheduledAction = null; + } } + // Hack #2 if (updateOnLogin) { if (id == Packets.Server.LOGIN) { @@ -595,9 +603,11 @@ abstract class PlayerInjector { /** * Schedule an action to occur on the next sent packet. + *

+ * If the callable returns TRUE, the action is removed. * @param action - action to execute. */ - public void scheduleAction(Runnable action) { + public void scheduleAction(Callable action) { scheduledAction = action; } diff --git a/ProtocolLib/src/main/java/com/comphenix/protocol/injector/player/ProxyPlayerInjectionHandler.java b/ProtocolLib/src/main/java/com/comphenix/protocol/injector/player/ProxyPlayerInjectionHandler.java index 053fe0ef..1c3945c6 100644 --- a/ProtocolLib/src/main/java/com/comphenix/protocol/injector/player/ProxyPlayerInjectionHandler.java +++ b/ProtocolLib/src/main/java/com/comphenix/protocol/injector/player/ProxyPlayerInjectionHandler.java @@ -24,6 +24,7 @@ import java.net.Socket; import java.net.SocketAddress; import java.util.Map; import java.util.Set; +import java.util.concurrent.Callable; import java.util.concurrent.TimeUnit; import org.bukkit.Server; @@ -663,10 +664,17 @@ class ProxyPlayerInjectionHandler implements PlayerInjectionHandler { // Update the DataInputStream if (injector != null) { - injector.scheduleAction(new Runnable() { + injector.scheduleAction(new Callable() { @Override - public void run() { - dataInputLookup.put(injector.getInputStream(false), injector); + public Boolean call() throws Exception { + DataInputStream inputStream = injector.getInputStream(false); + + if (inputStream != null) { + dataInputLookup.put(inputStream, injector); + return true; + } + // Try again + return false; } }); }