Always create the NullPacketListener (unless otherwise stated).
This functions like a crude "counter" that automatically unregisters the packet injectors when every asynchronous listener has been removed.
Dieser Commit ist enthalten in:
Ursprung
961b34da38
Commit
f4f28023fa
@ -20,7 +20,6 @@ public interface AsynchronousManager {
|
||||
* Registers an asynchronous packet handler.
|
||||
* <p>
|
||||
* To start listening asynchronously, pass the getListenerLoop() runnable to a different thread.
|
||||
* @param plugin - the plugin that is registering the handler.
|
||||
* @param listener - the packet listener that will recieve these asynchronous events.
|
||||
* @return An asynchrouns handler.
|
||||
*/
|
||||
|
@ -68,28 +68,40 @@ public class AsyncFilterManager implements AsynchronousManager {
|
||||
|
||||
@Override
|
||||
public AsyncListenerHandler registerAsyncHandler(PacketListener listener) {
|
||||
return registerAsyncHandler(listener, true);
|
||||
}
|
||||
|
||||
/**
|
||||
* Registers an asynchronous packet handler.
|
||||
* <p>
|
||||
* To start listening asynchronously, pass the getListenerLoop() runnable to a different thread.
|
||||
* <p>
|
||||
* Asynchronous events will only be executed if a synchronous listener with the same packets is registered.
|
||||
* If you already have a synchronous event, call this method with autoInject set to FALSE.
|
||||
*
|
||||
* @param listener - the packet listener that will recieve these asynchronous events.
|
||||
* @param autoInject - whether or not to automatically create the corresponding synchronous listener,
|
||||
* @return An asynchrouns handler.
|
||||
*/
|
||||
public AsyncListenerHandler registerAsyncHandler(PacketListener listener, boolean autoInject) {
|
||||
AsyncListenerHandler handler = new AsyncListenerHandler(mainThread, this, listener);
|
||||
|
||||
ListeningWhitelist sendingWhitelist = listener.getSendingWhitelist();
|
||||
ListeningWhitelist receivingWhitelist = listener.getReceivingWhitelist();
|
||||
|
||||
// We need a synchronized listener to get the ball rolling
|
||||
boolean hasListener = true;
|
||||
|
||||
// Add listener to either or both processing queue
|
||||
if (hasValidWhitelist(sendingWhitelist)) {
|
||||
PacketFilterManager.verifyWhitelist(listener, sendingWhitelist);
|
||||
serverProcessingQueue.addListener(handler, sendingWhitelist);
|
||||
hasListener &= hasPacketListener(sendingWhitelist);
|
||||
}
|
||||
|
||||
if (hasValidWhitelist(receivingWhitelist)) {
|
||||
PacketFilterManager.verifyWhitelist(listener, receivingWhitelist);
|
||||
clientProcessingQueue.addListener(handler, receivingWhitelist);
|
||||
hasListener &= hasPacketListener(receivingWhitelist);
|
||||
}
|
||||
|
||||
if (!hasListener) {
|
||||
// We need a synchronized listener to get the ball rolling
|
||||
if (autoInject) {
|
||||
handler.setNullPacketListener(new NullPacketListener(listener));
|
||||
manager.addPacketListener(handler.getNullPacketListener());
|
||||
}
|
||||
@ -97,15 +109,6 @@ public class AsyncFilterManager implements AsynchronousManager {
|
||||
return handler;
|
||||
}
|
||||
|
||||
/**
|
||||
* Determine if the given packets are represented.
|
||||
* @param whitelist - list of packets.
|
||||
* @return TRUE if they are all registered, FALSE otherwise.
|
||||
*/
|
||||
private boolean hasPacketListener(ListeningWhitelist whitelist) {
|
||||
return manager.getSendingFilters().containsAll(whitelist.getWhitelist());
|
||||
}
|
||||
|
||||
private boolean hasValidWhitelist(ListeningWhitelist whitelist) {
|
||||
return whitelist != null && whitelist.getWhitelist().size() > 0;
|
||||
}
|
||||
|
In neuem Issue referenzieren
Einen Benutzer sperren