Start EventNode implementation

This commit is contained in:
TheMode 2021-06-02 10:19:23 +02:00
parent 5474116e7a
commit f4db18ea6c

View File

@ -1,12 +1,21 @@
package net.minestom.server.event; package net.minestom.server.event;
import net.minestom.server.event.handler.EventHandler; 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.Consumer;
import java.util.function.Predicate; import java.util.function.Predicate;
public class EventNode<T extends Event> { public class EventNode<T extends Event> {
private final String name = "debug";
private final List<EventListener<? extends T>> listeners = new CopyOnWriteArrayList<>();
private final List<EventNode<? extends T>> children = new CopyOnWriteArrayList<>();
private final Predicate<T> condition = t -> true;
private EventNode() { private EventNode() {
} }
@ -14,26 +23,41 @@ public class EventNode<T extends Event> {
return new EventNode<>(); return new EventNode<>();
} }
public static <T extends Event, E> EventNode<T> conditional(Class<T> eventType, public static <E extends Event> EventNode<E> conditional(@NotNull Class<E> type,
Class<E> handlerType, @NotNull Predicate<E> predicate) {
Predicate<E> predicate) {
return new EventNode<>(); return new EventNode<>();
} }
public static <T extends Event> EventNode<T> conditional(Class<T> eventType) { public static <E extends Event> EventNode<E> conditional(@NotNull Class<E> eventType) {
return conditional(eventType, t -> true);
}
public static <E extends Event> EventNode<E> unique(@NotNull Class<E> eventType,
@NotNull EventHandler handler) {
return new EventNode<>(); return new EventNode<>();
} }
public static <T extends Event> EventNode<T> unique(Class<T> eventType, EventHandler handler) { public void addChild(@NotNull EventNode<? extends T> child) {
return new EventNode<>(); this.children.add(child);
} }
public void addChild(EventNode<? extends T> child) { public void addListener(@NotNull EventListener<? extends T> listener) {
this.listeners.add(listener);
} }
public void addListener(EventListener<? extends T> listener) { public <E extends T> void addListener(@NotNull Class<E> eventClass, @NotNull Consumer<@NotNull E> listener) {
addListener(EventListener.of(eventClass).handler(listener).build());
} }
public <E extends T> void addListener(Class<E> eventClass, Consumer<E> listener) { public @NotNull String getName() {
return name;
}
public @NotNull List<@NotNull EventNode<? extends T>> getChildren() {
return Collections.unmodifiableList(children);
}
public @NotNull Predicate<@NotNull T> getCondition() {
return condition;
} }
} }