From f4db18ea6ce5cb101fa2db0835b5dfb8b362b3ce Mon Sep 17 00:00:00 2001 From: TheMode Date: Wed, 2 Jun 2021 10:19:23 +0200 Subject: [PATCH] Start EventNode implementation --- .../net/minestom/server/event/EventNode.java | 42 +++++++++++++++---- 1 file changed, 33 insertions(+), 9 deletions(-) diff --git a/src/main/java/net/minestom/server/event/EventNode.java b/src/main/java/net/minestom/server/event/EventNode.java index dae9c512c..674c7f6b0 100644 --- a/src/main/java/net/minestom/server/event/EventNode.java +++ b/src/main/java/net/minestom/server/event/EventNode.java @@ -1,12 +1,21 @@ package net.minestom.server.event; import net.minestom.server.event.handler.EventHandler; +import org.jetbrains.annotations.NotNull; +import java.util.Collections; +import java.util.List; +import java.util.concurrent.CopyOnWriteArrayList; import java.util.function.Consumer; import java.util.function.Predicate; public class EventNode { + private final String name = "debug"; + private final List> listeners = new CopyOnWriteArrayList<>(); + private final List> children = new CopyOnWriteArrayList<>(); + private final Predicate condition = t -> true; + private EventNode() { } @@ -14,26 +23,41 @@ public class EventNode { return new EventNode<>(); } - public static EventNode conditional(Class eventType, - Class handlerType, - Predicate predicate) { + public static EventNode conditional(@NotNull Class type, + @NotNull Predicate predicate) { return new EventNode<>(); } - public static EventNode conditional(Class eventType) { + public static EventNode conditional(@NotNull Class eventType) { + return conditional(eventType, t -> true); + } + + public static EventNode unique(@NotNull Class eventType, + @NotNull EventHandler handler) { return new EventNode<>(); } - public static EventNode unique(Class eventType, EventHandler handler) { - return new EventNode<>(); + public void addChild(@NotNull EventNode child) { + this.children.add(child); } - public void addChild(EventNode child) { + public void addListener(@NotNull EventListener listener) { + this.listeners.add(listener); } - public void addListener(EventListener listener) { + public void addListener(@NotNull Class eventClass, @NotNull Consumer<@NotNull E> listener) { + addListener(EventListener.of(eventClass).handler(listener).build()); } - public void addListener(Class eventClass, Consumer listener) { + public @NotNull String getName() { + return name; + } + + public @NotNull List<@NotNull EventNode> getChildren() { + return Collections.unmodifiableList(children); + } + + public @NotNull Predicate<@NotNull T> getCondition() { + return condition; } }