diff --git a/src/main/java/net/minestom/server/event/EventListener.java b/src/main/java/net/minestom/server/event/EventListener.java index 56beca997..550cd79e2 100644 --- a/src/main/java/net/minestom/server/event/EventListener.java +++ b/src/main/java/net/minestom/server/event/EventListener.java @@ -20,10 +20,14 @@ public class EventListener { this.executor = executor; } - public static EventListener.Builder of(@NotNull Class eventType) { + public static EventListener.Builder builder(@NotNull Class eventType) { return new EventListener.Builder<>(eventType); } + public static EventListener of(@NotNull Class eventType, @NotNull Consumer<@NotNull T> listener) { + return EventListener.builder(eventType).handler(listener).build(); + } + public static class Builder { private final Class eventType; diff --git a/src/main/java/net/minestom/server/event/EventNode.java b/src/main/java/net/minestom/server/event/EventNode.java index 8fd69009c..d7dc8dcbc 100644 --- a/src/main/java/net/minestom/server/event/EventNode.java +++ b/src/main/java/net/minestom/server/event/EventNode.java @@ -4,7 +4,6 @@ import net.minestom.server.event.handler.EventHandler; import org.jetbrains.annotations.NotNull; import java.util.List; -import java.util.function.Consumer; import java.util.function.Predicate; public interface EventNode { @@ -36,10 +35,6 @@ public interface EventNode { void removeListener(@NotNull EventListener listener); - default void addListener(@NotNull Class eventClass, @NotNull Consumer<@NotNull E> listener) { - addListener(EventListener.of(eventClass).handler(listener).build()); - } - @NotNull String getName(); @NotNull List<@NotNull EventNode> getChildren(); diff --git a/src/test/java/demo/PlayerInit.java b/src/test/java/demo/PlayerInit.java index 0b2800a9b..125858c99 100644 --- a/src/test/java/demo/PlayerInit.java +++ b/src/test/java/demo/PlayerInit.java @@ -138,19 +138,19 @@ public class PlayerInit { // EVENT REGISTERING var node = EventNode.type(EventFilter.PLAYER); - node.addListener(EventListener.of(PlayerTickEvent.class) + node.addListener(EventListener.builder(PlayerTickEvent.class) .handler(playerTickEvent -> System.out.println("Player tick!")) .expirationCount(2) .build()); var empty = EventNode.all(); - empty.addListener(PlayerMoveEvent.class, (event) -> { - }); + empty.addListener(EventListener.of(PlayerMoveEvent.class, (event) -> { + })); var list = EventNode.list(EventFilter.PLAYER); - list.addListener(PlayerMoveEvent.class, playerMoveEvent -> { + list.addListener(EventListener.of(PlayerMoveEvent.class, playerMoveEvent -> { System.out.println("move"); - }); + })); GlobalEventHandler globalEventHandler = MinecraftServer.getGlobalEventHandler(); globalEventHandler.addEventCallback(EntityAttackEvent.class, event -> {