diff --git a/ProtocolLib/src/com/comphenix/protocol/async/AsyncListenerHandler.java b/ProtocolLib/src/com/comphenix/protocol/async/AsyncListenerHandler.java index 4521831d..72c04470 100644 --- a/ProtocolLib/src/com/comphenix/protocol/async/AsyncListenerHandler.java +++ b/ProtocolLib/src/com/comphenix/protocol/async/AsyncListenerHandler.java @@ -86,12 +86,22 @@ public class AsyncListenerHandler { } /** - * Entry point for the background thread that will be processing the packet asynchronously. + * Create a runnable that will initiate the listener loop. *

- * WARNING: - * Never call this method from the main thread. Doing so will block Minecraft. + * Warning: Never call the run() method in the main thread. */ - public void listenerLoop() { + public Runnable getListenerLoop() { + return new Runnable() { + @Override + public void run() { + listenerLoop(); + } + }; + } + + // DO NOT call this method from the main thread + private void listenerLoop() { + // Danger, danger! if (Thread.currentThread().getId() == mainThread.getId()) throw new IllegalStateException("Do not call this method from the main thread."); diff --git a/ProtocolLib/src/com/comphenix/protocol/async/PacketSendingQueue.java b/ProtocolLib/src/com/comphenix/protocol/async/PacketSendingQueue.java index 2c894dbd..9ab9fb7e 100644 --- a/ProtocolLib/src/com/comphenix/protocol/async/PacketSendingQueue.java +++ b/ProtocolLib/src/com/comphenix/protocol/async/PacketSendingQueue.java @@ -27,7 +27,13 @@ class PacketSendingQueue { public synchronized void signalPacketUpdate(PacketEvent packetUpdated) { // Mark this packet as finished packetUpdated.getAsyncMarker().setProcessed(true); + trySendPackets(); + } + /** + * Attempt to send any remaining packets. + */ + public synchronized void trySendPackets() { // Transmit as many packets as we can while (true) { PacketEvent current = sendingQueue.peek();