From 6cbc31b11427c0e83676fc05cc536ed43f338e3d Mon Sep 17 00:00:00 2001 From: TheMode Date: Wed, 2 Jun 2021 21:18:18 +0200 Subject: [PATCH] Allow filtering on more than just EventHandler --- .../net/minestom/server/event/EventFilter.java | 10 +++++----- .../net/minestom/server/event/EventNode.java | 17 ++++++++--------- .../server/event/EventNodeConditional.java | 3 +-- .../minestom/server/event/EventNodeImpl.java | 3 +-- .../minestom/server/event/EventNodeList.java | 3 +-- 5 files changed, 16 insertions(+), 20 deletions(-) diff --git a/src/main/java/net/minestom/server/event/EventFilter.java b/src/main/java/net/minestom/server/event/EventFilter.java index d3a9577b7..afcc0a167 100644 --- a/src/main/java/net/minestom/server/event/EventFilter.java +++ b/src/main/java/net/minestom/server/event/EventFilter.java @@ -10,15 +10,15 @@ import org.jetbrains.annotations.Nullable; import java.util.function.Function; -public interface EventFilter { +public interface EventFilter { EventFilter ALL = from(Event.class); EventFilter ENTITY = from(EntityEvent.class, Entity.class, EntityEvent::getEntity); EventFilter PLAYER = from(PlayerEvent.class, Player.class, PlayerEvent::getPlayer); - static EventFilter from(@NotNull Class eventType, - @NotNull Class handlerType, - @NotNull Function handlerGetter) { + static EventFilter from(@NotNull Class eventType, + @NotNull Class handlerType, + @NotNull Function handlerGetter) { return new EventFilter<>() { @Override public @Nullable H getHandler(@NotNull E event) { @@ -32,7 +32,7 @@ public interface EventFilter { }; } - static EventFilter from(@NotNull Class type) { + static EventFilter from(@NotNull Class type) { return new EventFilter<>() { @Override public @Nullable H getHandler(@NotNull E event) { diff --git a/src/main/java/net/minestom/server/event/EventNode.java b/src/main/java/net/minestom/server/event/EventNode.java index 67d6358b1..33dfb854e 100644 --- a/src/main/java/net/minestom/server/event/EventNode.java +++ b/src/main/java/net/minestom/server/event/EventNode.java @@ -1,6 +1,5 @@ package net.minestom.server.event; -import net.minestom.server.event.handler.EventHandler; import org.jetbrains.annotations.NotNull; import java.util.List; @@ -9,7 +8,7 @@ import java.util.function.Predicate; public interface EventNode { - static EventNode type(@NotNull EventFilter filter) { + static EventNode type(@NotNull EventFilter filter) { return new EventNodeImpl<>(filter); } @@ -17,22 +16,22 @@ public interface EventNode { return type(EventFilter.ALL); } - static EventNodeConditional conditional(@NotNull EventFilter filter, - @NotNull BiPredicate predicate) { + static EventNodeConditional conditional(@NotNull EventFilter filter, + @NotNull BiPredicate predicate) { return new EventNodeConditional<>(filter, predicate); } - static EventNodeConditional conditionalEvent(@NotNull EventFilter filter, - @NotNull Predicate predicate) { + static EventNodeConditional conditionalEvent(@NotNull EventFilter filter, + @NotNull Predicate predicate) { return conditional(filter, (e, h) -> predicate.test(e)); } - static EventNodeConditional conditionalHandler(@NotNull EventFilter filter, - @NotNull Predicate predicate) { + static EventNodeConditional conditionalHandler(@NotNull EventFilter filter, + @NotNull Predicate predicate) { return conditional(filter, (e, h) -> predicate.test(h)); } - static EventNodeList list(@NotNull EventFilter filter) { + static EventNodeList list(@NotNull EventFilter filter) { return new EventNodeList<>(filter); } diff --git a/src/main/java/net/minestom/server/event/EventNodeConditional.java b/src/main/java/net/minestom/server/event/EventNodeConditional.java index 308a0a4a1..4f0d5d68a 100644 --- a/src/main/java/net/minestom/server/event/EventNodeConditional.java +++ b/src/main/java/net/minestom/server/event/EventNodeConditional.java @@ -1,11 +1,10 @@ package net.minestom.server.event; -import net.minestom.server.event.handler.EventHandler; import org.jetbrains.annotations.NotNull; import java.util.function.BiPredicate; -public class EventNodeConditional extends EventNodeImpl { +public class EventNodeConditional extends EventNodeImpl { private volatile BiPredicate predicate; diff --git a/src/main/java/net/minestom/server/event/EventNodeImpl.java b/src/main/java/net/minestom/server/event/EventNodeImpl.java index a50ff0088..b29c88aca 100644 --- a/src/main/java/net/minestom/server/event/EventNodeImpl.java +++ b/src/main/java/net/minestom/server/event/EventNodeImpl.java @@ -1,6 +1,5 @@ package net.minestom.server.event; -import net.minestom.server.event.handler.EventHandler; import org.jetbrains.annotations.NotNull; import java.util.Collections; @@ -9,7 +8,7 @@ import java.util.Map; import java.util.concurrent.ConcurrentHashMap; import java.util.concurrent.CopyOnWriteArrayList; -class EventNodeImpl implements EventNode { +class EventNodeImpl implements EventNode { private final String name = "debug"; diff --git a/src/main/java/net/minestom/server/event/EventNodeList.java b/src/main/java/net/minestom/server/event/EventNodeList.java index b7e383509..fe482591f 100644 --- a/src/main/java/net/minestom/server/event/EventNodeList.java +++ b/src/main/java/net/minestom/server/event/EventNodeList.java @@ -1,12 +1,11 @@ package net.minestom.server.event; -import net.minestom.server.event.handler.EventHandler; import org.jetbrains.annotations.NotNull; import java.util.List; import java.util.concurrent.CopyOnWriteArrayList; -public class EventNodeList extends EventNodeImpl { +public class EventNodeList extends EventNodeImpl { private final List entries = new CopyOnWriteArrayList<>();