Add the ability to see registered asynchronous listeners.

This commit is contained in:
Kristian S. Stangeland 2014-03-13 23:55:33 +01:00
parent f4f8817fd5
commit 75a5efcaa1
4 changed files with 29 additions and 5 deletions

View File

@ -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<PacketListener> getTimeoutHandlers();
/**
* Get an immutable set of every registered asynchronous packet listener.
* @return Set of every asynchronous packet listener.
*/
public abstract Set<PacketListener> getAsyncHandlers();
}

View File

@ -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) {

View File

@ -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;

View File

@ -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<PacketListener> getAsyncHandlers() {
ImmutableSet.Builder<PacketListener> builder = ImmutableSet.builder();
// Add every asynchronous packet listener
for (PrioritizedListener<AsyncListenerHandler> handler :
Iterables.concat(serverProcessingQueue.values(), clientProcessingQueue.values())) {
builder.add(handler.getListener().getAsyncListener());
}
return builder.build();
}
/**
* Registers an asynchronous packet handler.
* <p>