From 5b42ce4a522c0e1d6f0e4818742d5a107cb5fe56 Mon Sep 17 00:00:00 2001 From: TheMode Date: Wed, 2 Jun 2021 22:55:24 +0200 Subject: [PATCH] Reuse EventFilter code --- .../minestom/server/event/EventFilter.java | 20 +++++-------------- 1 file changed, 5 insertions(+), 15 deletions(-) diff --git a/src/main/java/net/minestom/server/event/EventFilter.java b/src/main/java/net/minestom/server/event/EventFilter.java index c6f591109..2ece64c1d 100644 --- a/src/main/java/net/minestom/server/event/EventFilter.java +++ b/src/main/java/net/minestom/server/event/EventFilter.java @@ -13,7 +13,7 @@ import java.util.function.Function; public interface EventFilter { - EventFilter ALL = from(Event.class); + EventFilter ALL = from(Event.class); EventFilter ENTITY = from(EntityEvent.class, Entity.class, EntityEvent::getEntity); EventFilter PLAYER = from(PlayerEvent.class, Player.class, PlayerEvent::getPlayer); EventFilter ITEM = from(ItemEvent.class, ItemStack.class, ItemEvent::getItemStack); @@ -21,12 +21,12 @@ public interface EventFilter { EventFilter INVENTORY = from(InventoryEvent.class, Inventory.class, InventoryEvent::getInventory); static EventFilter from(@NotNull Class eventType, - @NotNull Class handlerType, - @NotNull Function handlerGetter) { + @Nullable Class handlerType, + @Nullable Function handlerGetter) { return new EventFilter<>() { @Override public @Nullable H getHandler(@NotNull E event) { - return handlerGetter.apply(event); + return handlerGetter != null ? handlerGetter.apply(event) : null; } @Override @@ -37,17 +37,7 @@ public interface EventFilter { } static EventFilter from(@NotNull Class type) { - return new EventFilter<>() { - @Override - public @Nullable H getHandler(@NotNull E event) { - return null; - } - - @Override - public @NotNull Class getEventType() { - return type; - } - }; + return from(type, null, null); } @Nullable H getHandler(@NotNull E event);