From cc9bb34873edb834a13f0546d5646f5d9b9d5188 Mon Sep 17 00:00:00 2001 From: Luck Date: Mon, 13 Aug 2018 20:03:57 +0100 Subject: [PATCH] Update kyori/event dependency --- common/build.gradle | 2 +- .../common/dependencies/Dependency.java | 4 +-- .../common/event/AbstractEventBus.java | 29 ++++++------------- 3 files changed, 12 insertions(+), 23 deletions(-) diff --git a/common/build.gradle b/common/build.gradle index f7d97072..95571e8c 100644 --- a/common/build.gradle +++ b/common/build.gradle @@ -7,7 +7,7 @@ dependencies { exclude(module: 'guava') exclude(module: 'gson') } - compile('net.kyori:event-api:2.0.1') { + compile('net.kyori:event-api:2.0.2') { exclude(module: 'checker-qual') exclude(module: 'guava') } diff --git a/common/src/main/java/me/lucko/luckperms/common/dependencies/Dependency.java b/common/src/main/java/me/lucko/luckperms/common/dependencies/Dependency.java index c71e2863..0e4142c4 100644 --- a/common/src/main/java/me/lucko/luckperms/common/dependencies/Dependency.java +++ b/common/src/main/java/me/lucko/luckperms/common/dependencies/Dependency.java @@ -70,8 +70,8 @@ public enum Dependency { EVENT( "net{}kyori", "event-api", - "2.0.1", - "4XVmowvKHCmO38ZO2jeZKh/mD00xBg73zau79s4kTe4=", + "2.0.2", + "+69FXQhgPlBtg/OvEiB+hvpbdGyUquj4cORHV1gnN1w=", Relocation.of("eventbus", "net{}kyori{}event") ), CAFFEINE( diff --git a/common/src/main/java/me/lucko/luckperms/common/event/AbstractEventBus.java b/common/src/main/java/me/lucko/luckperms/common/event/AbstractEventBus.java index 304abb4b..591ce1ee 100644 --- a/common/src/main/java/me/lucko/luckperms/common/event/AbstractEventBus.java +++ b/common/src/main/java/me/lucko/luckperms/common/event/AbstractEventBus.java @@ -25,23 +25,20 @@ package me.lucko.luckperms.common.event; -import com.google.common.collect.ImmutableSet; - import me.lucko.luckperms.api.event.EventBus; import me.lucko.luckperms.api.event.EventHandler; import me.lucko.luckperms.api.event.LuckPermsEvent; import me.lucko.luckperms.common.api.LuckPermsApiProvider; import me.lucko.luckperms.common.plugin.LuckPermsPlugin; -import me.lucko.luckperms.common.utils.Predicates; import net.kyori.event.EventSubscriber; import net.kyori.event.SimpleEventBus; -import java.util.HashSet; import java.util.Objects; import java.util.Set; import java.util.function.Consumer; import java.util.function.Predicate; +import java.util.stream.Collectors; import javax.annotation.Nonnull; @@ -122,11 +119,7 @@ public abstract class AbstractEventBus

implements EventBus, AutoCloseable { @Nonnull @Override public Set> getHandlers(@Nonnull Class eventClass) { - Set> handlers = this.bus.getHandlers(); - handlers.removeIf(h -> !h.getEventClass().isAssignableFrom(eventClass)); - - //noinspection unchecked - return (Set) ImmutableSet.copyOf(handlers); + return this.bus.getHandlers(eventClass); } /** @@ -160,19 +153,15 @@ public abstract class AbstractEventBus

implements EventBus, AutoCloseable { } public void unregisterAll() { - unregisterMatching(Predicates.alwaysTrue()); + super.unregisterAll(); } - public Set> getHandlers() { - Set> handlers = new HashSet<>(); - - // bit of a hack - unregisterMatching(sub -> { - handlers.add((LuckPermsEventHandler) sub); - return false; - }); - - return handlers; + public Set> getHandlers(Class eventClass) { + //noinspection unchecked + return super.subscribers().values().stream() + .filter(s -> s instanceof EventHandler && ((EventHandler) s).getEventClass().isAssignableFrom(eventClass)) + .map(s -> ((EventHandler) s)) + .collect(Collectors.toSet()); } } }