Add EventNode#removeListener

This commit is contained in:
TheMode 2021-06-02 19:50:23 +02:00
parent 8fa4c22d1f
commit 11bdcdf92a
2 changed files with 10 additions and 0 deletions

View File

@ -35,6 +35,8 @@ public interface EventNode<T extends Event> {
void addListener(@NotNull EventListener<? extends T> listener);
void removeListener(@NotNull EventListener<? extends T> listener);
default <E extends T> void addListener(@NotNull Class<E> eventClass, @NotNull Consumer<@NotNull E> listener) {
addListener(EventListener.of(eventClass).handler(listener).build());
}

View File

@ -58,6 +58,14 @@ class EventNodeImpl<T extends Event> implements EventNode<T> {
.add((EventListener<T>) listener);
}
@Override
public void removeListener(@NotNull EventListener<? extends T> listener) {
var listeners = listenerMap.get(listener.type);
if (listeners == null || listeners.isEmpty())
return;
listeners.remove(listener);
}
@Override
public @NotNull String getName() {
return name;