mirror of
https://github.com/Minestom/Minestom.git
synced 2025-01-21 15:41:38 +01:00
Add EventNode#removeListener
This commit is contained in:
parent
8fa4c22d1f
commit
11bdcdf92a
@ -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());
|
||||
}
|
||||
|
@ -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;
|
||||
|
Loading…
Reference in New Issue
Block a user