From 65b5a0e8ec2be4fcf8ce55a07cf2e7e0f9fd6195 Mon Sep 17 00:00:00 2001 From: "Kristian S. Stangeland" Date: Sat, 29 Sep 2012 21:42:16 +0200 Subject: [PATCH] We don't expect consumers to create asynchronous markers, so don't allow them to set it in the packet event. --- .../com/comphenix/protocol/ProtocolManager.java | 7 +++++++ .../protocol/async/PacketProcessingQueue.java | 3 ++- .../protocol/async/PacketSendingQueue.java | 2 +- .../comphenix/protocol/events/PacketEvent.java | 16 ++-------------- .../protocol/injector/PacketFilterManager.java | 9 ++++----- 5 files changed, 16 insertions(+), 21 deletions(-) diff --git a/ProtocolLib/src/com/comphenix/protocol/ProtocolManager.java b/ProtocolLib/src/com/comphenix/protocol/ProtocolManager.java index 2fa911e3..f3f25d63 100644 --- a/ProtocolLib/src/com/comphenix/protocol/ProtocolManager.java +++ b/ProtocolLib/src/com/comphenix/protocol/ProtocolManager.java @@ -24,6 +24,7 @@ import org.bukkit.entity.Entity; import org.bukkit.entity.Player; import org.bukkit.plugin.Plugin; +import com.comphenix.protocol.async.AsyncFilterManager; import com.comphenix.protocol.events.PacketContainer; import com.comphenix.protocol.events.PacketListener; import com.comphenix.protocol.injector.PacketConstructor; @@ -122,4 +123,10 @@ public interface ProtocolManager extends PacketStream { * @return TRUE if it has, FALSE otherwise. */ public boolean isClosed(); + + /** + * Retrieve the current asyncronous packet manager. + * @return Asyncronous packet manager. + */ + public AsyncFilterManager getAsyncFilterManager(); } \ No newline at end of file diff --git a/ProtocolLib/src/com/comphenix/protocol/async/PacketProcessingQueue.java b/ProtocolLib/src/com/comphenix/protocol/async/PacketProcessingQueue.java index 80554803..d2ffe29e 100644 --- a/ProtocolLib/src/com/comphenix/protocol/async/PacketProcessingQueue.java +++ b/ProtocolLib/src/com/comphenix/protocol/async/PacketProcessingQueue.java @@ -79,6 +79,7 @@ class PacketProcessingQueue extends AbstractConcurrentListenerMultimap> list = getListener(packet.getPacketID()); AsyncMarker marker = packet.getAsyncMarker(); + // Yes, removing the marker will cause the chain to stop if (list != null) { Iterator> iterator = list.iterator(); @@ -89,7 +90,7 @@ class PacketProcessingQueue extends AbstractConcurrentListenerMultimap - * If the packet is synchronous, this marker will be used to schedule an asynchronous event. In this + * If the packet is synchronous, this marker will be used to schedule an asynchronous event. In the following * asynchronous event, the marker is used to correctly pass the packet around to the different threads. *

* Note that if there are no asynchronous events that can receive this packet, the marker is NULL. @@ -165,19 +166,6 @@ public class PacketEvent extends EventObject implements Cancellable { public AsyncMarker getAsyncMarker() { return asyncMarker; } - - /** - * Set the asynchronous marker. - *

- * If the marker is non-null at the end of an synchronous event processing, the packet will be scheduled - * to be processed asynchronously with the given settings. - *

- * Note that if there are no asynchronous events that can receive this packet, the marker should be NULL. - * @param asyncMarker - the new asynchronous marker, or NULL. - */ - public void setAsyncMarker(AsyncMarker asyncMarker) { - this.asyncMarker = asyncMarker; - } /** * Determine if the packet event has been executed asynchronously or not. diff --git a/ProtocolLib/src/com/comphenix/protocol/injector/PacketFilterManager.java b/ProtocolLib/src/com/comphenix/protocol/injector/PacketFilterManager.java index 75016015..5b138624 100644 --- a/ProtocolLib/src/com/comphenix/protocol/injector/PacketFilterManager.java +++ b/ProtocolLib/src/com/comphenix/protocol/injector/PacketFilterManager.java @@ -137,10 +137,7 @@ public final class PacketFilterManager implements ProtocolManager { } } - /** - * Retrieve the current async packet filter manager. - * @return Async filter manager. - */ + @Override public AsyncFilterManager getAsyncFilterManager() { return asyncFilterManager; } @@ -313,9 +310,11 @@ public final class PacketFilterManager implements ProtocolManager { // Process synchronous events packetListeners.invokePacketRecieving(logger, event); - // To cancel the asynchronous processing, use the async marker + // To cancel asynchronous processing, use the async marker if (!event.isCancelled() && !hasAsyncCancelled(event.getAsyncMarker())) { asyncFilterManager.enqueueSyncPacket(event, event.getAsyncMarker()); + + // The above makes a copy of the event, so it's safe to cancel it event.setCancelled(true); } }