13
0
geforkt von Mirrors/Velocity

Allow the same EventHandler to be registered with different PostOrders

The #equals implementations in KyoriToVelocityHandler silently prevented this previously.
Dieser Commit ist enthalten in:
Luck 2018-12-03 23:53:06 +00:00
Ursprung 5b9a8f160b
Commit 43da3d4541
Es konnte kein GPG-Schlüssel zu dieser Signatur gefunden werden
GPG-Schlüssel-ID: EFA9B3EC5FD90F8B

Datei anzeigen

@ -123,14 +123,18 @@ public class VelocityEventManager implements EventManager {
return eventFuture; return eventFuture;
} }
private void unregisterHandler(EventHandler<?> handler) {
bus.unregister(s -> s instanceof KyoriToVelocityHandler &&
((KyoriToVelocityHandler<?>) s).handler == handler);
}
@Override @Override
public void unregisterListeners(Object plugin) { public void unregisterListeners(Object plugin) {
ensurePlugin(plugin); ensurePlugin(plugin);
Collection<Object> listeners = registeredListenersByPlugin.removeAll(plugin); Collection<Object> listeners = registeredListenersByPlugin.removeAll(plugin);
listeners.forEach(methodAdapter::unregister); listeners.forEach(methodAdapter::unregister);
Collection<EventHandler<?>> handlers = registeredHandlersByPlugin.removeAll(plugin); Collection<EventHandler<?>> handlers = registeredHandlersByPlugin.removeAll(plugin);
handlers handlers.forEach(this::unregisterHandler);
.forEach(handler -> bus.unregister(new KyoriToVelocityHandler<>(handler, PostOrder.LAST)));
} }
@Override @Override
@ -146,7 +150,7 @@ public class VelocityEventManager implements EventManager {
ensurePlugin(plugin); ensurePlugin(plugin);
Preconditions.checkNotNull(handler, "listener"); Preconditions.checkNotNull(handler, "listener");
registeredHandlersByPlugin.remove(plugin, handler); registeredHandlersByPlugin.remove(plugin, handler);
bus.unregister(new KyoriToVelocityHandler<>(handler, PostOrder.LAST)); unregisterHandler(handler);
} }
public boolean shutdown() throws InterruptedException { public boolean shutdown() throws InterruptedException {
@ -196,26 +200,5 @@ public class VelocityEventManager implements EventManager {
public int postOrder() { public int postOrder() {
return postOrder; return postOrder;
} }
public EventHandler<E> getHandler() {
return handler;
}
@Override
public boolean equals(@Nullable Object o) {
if (this == o) {
return true;
}
if (o == null || getClass() != o.getClass()) {
return false;
}
KyoriToVelocityHandler<?> that = (KyoriToVelocityHandler<?>) o;
return Objects.equals(handler, that.handler);
}
@Override
public int hashCode() {
return Objects.hash(handler);
}
} }
} }