From 75a5efcaa103bc3e4078bc3dda4e94824c54ebe9 Mon Sep 17 00:00:00 2001 From: "Kristian S. Stangeland" Date: Thu, 13 Mar 2014 23:55:33 +0100 Subject: [PATCH] Add the ability to see registered asynchronous listeners. --- .../com/comphenix/protocol/AsynchronousManager.java | 10 ++++++++-- .../com/comphenix/protocol/CommandProtocol.java | 9 ++++++++- .../com/comphenix/protocol/PacketTypeLookup.java | 2 -- .../protocol/async/AsyncFilterManager.java | 13 +++++++++++++ 4 files changed, 29 insertions(+), 5 deletions(-) diff --git a/ProtocolLib/src/main/java/com/comphenix/protocol/AsynchronousManager.java b/ProtocolLib/src/main/java/com/comphenix/protocol/AsynchronousManager.java index c722da39..9067b144 100644 --- a/ProtocolLib/src/main/java/com/comphenix/protocol/AsynchronousManager.java +++ b/ProtocolLib/src/main/java/com/comphenix/protocol/AsynchronousManager.java @@ -136,8 +136,14 @@ public interface AsynchronousManager { public abstract void unregisterTimeoutHandler(PacketListener listener); /** - * Get a immutable list of every registered timeout handler. - * @return List of every registered timeout handler. + * Get a immutable set of every registered timeout handler. + * @return Set of every registered timeout handler. */ public abstract Set getTimeoutHandlers(); + + /** + * Get an immutable set of every registered asynchronous packet listener. + * @return Set of every asynchronous packet listener. + */ + public abstract Set getAsyncHandlers(); } \ No newline at end of file diff --git a/ProtocolLib/src/main/java/com/comphenix/protocol/CommandProtocol.java b/ProtocolLib/src/main/java/com/comphenix/protocol/CommandProtocol.java index 7ee56020..d2f8f957 100644 --- a/ProtocolLib/src/main/java/com/comphenix/protocol/CommandProtocol.java +++ b/ProtocolLib/src/main/java/com/comphenix/protocol/CommandProtocol.java @@ -82,10 +82,17 @@ class CommandProtocol extends CommandBase { // Display every listener on the server private void printListeners(final CommandSender sender, String[] args) { - for (PacketListener listener : ProtocolLibrary.getProtocolManager().getPacketListeners()) { + ProtocolManager manager = ProtocolLibrary.getProtocolManager(); + + for (PacketListener listener : manager.getPacketListeners()) { sender.sendMessage(ChatColor.GOLD + "Packet listeners:"); sender.sendMessage(ChatColor.GOLD + " " + listener); } + // Along with every asynchronous listener + for (PacketListener listener : manager.getAsynchronousManager().getAsyncHandlers()) { + sender.sendMessage(ChatColor.GOLD + "Asynchronous listeners:"); + sender.sendMessage(ChatColor.GOLD + " " + listener); + } } private void performUpdate(final CommandSender sender, UpdateType type) { diff --git a/ProtocolLib/src/main/java/com/comphenix/protocol/PacketTypeLookup.java b/ProtocolLib/src/main/java/com/comphenix/protocol/PacketTypeLookup.java index 1f3e42cd..796d81ea 100644 --- a/ProtocolLib/src/main/java/com/comphenix/protocol/PacketTypeLookup.java +++ b/ProtocolLib/src/main/java/com/comphenix/protocol/PacketTypeLookup.java @@ -7,8 +7,6 @@ import com.comphenix.protocol.PacketType.Protocol; import com.comphenix.protocol.PacketType.Sender; import com.comphenix.protocol.collections.IntegerMap; import com.google.common.base.Preconditions; -import com.google.common.collect.BiMap; -import com.google.common.collect.HashBiMap; import com.google.common.collect.HashMultimap; import com.google.common.collect.Multimap; diff --git a/ProtocolLib/src/main/java/com/comphenix/protocol/async/AsyncFilterManager.java b/ProtocolLib/src/main/java/com/comphenix/protocol/async/AsyncFilterManager.java index 58691dcb..f05100b4 100644 --- a/ProtocolLib/src/main/java/com/comphenix/protocol/async/AsyncFilterManager.java +++ b/ProtocolLib/src/main/java/com/comphenix/protocol/async/AsyncFilterManager.java @@ -41,6 +41,7 @@ import com.comphenix.protocol.injector.SortedPacketListenerList; import com.comphenix.protocol.injector.packet.PacketRegistry; import com.google.common.base.Objects; import com.google.common.collect.ImmutableSet; +import com.google.common.collect.Iterables; import com.google.common.collect.Sets; /** @@ -142,6 +143,18 @@ public class AsyncFilterManager implements AsynchronousManager { return ImmutableSet.copyOf(timeoutListeners); } + @Override + public Set getAsyncHandlers() { + ImmutableSet.Builder builder = ImmutableSet.builder(); + + // Add every asynchronous packet listener + for (PrioritizedListener handler : + Iterables.concat(serverProcessingQueue.values(), clientProcessingQueue.values())) { + builder.add(handler.getListener().getAsyncListener()); + } + return builder.build(); + } + /** * Registers an asynchronous packet handler. *