From a74d2ca8bce0a5c93a15d3e2bb5f7fc77e6b492c Mon Sep 17 00:00:00 2001 From: "Kristian S. Stangeland" Date: Sun, 8 Dec 2013 00:51:46 +0100 Subject: [PATCH] Prevent cancelled packets from been cancelled over and over again. --- .../injector/netty/ChannelInjector.java | 18 ++++++++++++++---- .../protocol/injector/netty/ChannelProxy.java | 4 ++-- 2 files changed, 16 insertions(+), 6 deletions(-) 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 cd343177..2019ba84 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 @@ -304,7 +304,7 @@ class ChannelInjector extends ByteToMessageDecoder { // Schedule the transmission on the main thread instead if (channelListener.hasMainThreadListener(clazz)) { // Delay the packet - scheduleMainThread(marker, packet); + scheduleMainThread(packet); packet = null; } else { @@ -338,11 +338,14 @@ class ChannelInjector extends ByteToMessageDecoder { } } - private void scheduleMainThread(final NetworkMarker marker, final Object packetCopy) { + private void scheduleMainThread(final Object packetCopy) { + // Do not process this packet agai + processedPackets.add(packetCopy); + ProtocolLibrary.getExecutorSync().execute(new Runnable() { @Override public void run() { - sendServerPacket(packetCopy, marker, true); + invokeSendPacket(packetCopy); } }); } @@ -433,7 +436,14 @@ class ChannelInjector extends ByteToMessageDecoder { } else { ignoredPackets.remove(packet); } - + invokeSendPacket(packet); + } + + /** + * Invoke the sendPacket method in Minecraft. + * @param packet - the packet to send. + */ + private void invokeSendPacket(Object packet) { // Attempt to send the packet with NetworkMarker.handle(), or the PlayerConnection if its active try { if (player instanceof Factory) { diff --git a/ProtocolLib/src/main/java/com/comphenix/protocol/injector/netty/ChannelProxy.java b/ProtocolLib/src/main/java/com/comphenix/protocol/injector/netty/ChannelProxy.java index 66798a80..70c5a593 100644 --- a/ProtocolLib/src/main/java/com/comphenix/protocol/injector/netty/ChannelProxy.java +++ b/ProtocolLib/src/main/java/com/comphenix/protocol/injector/netty/ChannelProxy.java @@ -91,7 +91,7 @@ abstract class ChannelProxy implements Channel { if (packet != null) accessor.set(runnable, packet); else - getEmptyRunnable(); + return getEmptyRunnable(); } return runnable; } @@ -106,7 +106,7 @@ abstract class ChannelProxy implements Channel { if (packet != null) accessor.set(callable, packet); else - getEmptyCallable(); + return getEmptyCallable(); } return callable; }