Rename EventNode#create methods

This commit is contained in:
TheMode 2021-06-02 19:44:44 +02:00
parent f6fe41cfe9
commit 8fa4c22d1f
2 changed files with 10 additions and 5 deletions

View File

@ -10,12 +10,12 @@ import java.util.function.Predicate;
public interface EventNode<T extends Event> { public interface EventNode<T extends Event> {
static <E extends Event> EventNode<E> create(@NotNull Class<E> type) { static <E extends Event> EventNode<E> type(@NotNull Class<E> type) {
return new EventNodeImpl<>(type); return new EventNodeImpl<>(type);
} }
static EventNode<Event> create() { static EventNode<Event> all() {
return create(Event.class); return type(Event.class);
} }
static <E extends Event> EventNodeConditional<E> conditional(@NotNull Class<E> type, static <E extends Event> EventNodeConditional<E> conditional(@NotNull Class<E> type,

View File

@ -137,16 +137,21 @@ public class PlayerInit {
// EVENT REGISTERING // EVENT REGISTERING
var node = EventNode.create(PlayerEvent.class); var node = EventNode.type(PlayerEvent.class);
node.addListener(EventListener.of(PlayerTickEvent.class) node.addListener(EventListener.of(PlayerTickEvent.class)
.handler(playerTickEvent -> System.out.println("Player tick!")) .handler(playerTickEvent -> System.out.println("Player tick!"))
.expirationCount(2) .expirationCount(2)
.build()); .build());
var empty = EventNode.create(); var empty = EventNode.all();
empty.addListener(PlayerMoveEvent.class, (event) -> { empty.addListener(PlayerMoveEvent.class, (event) -> {
}); });
var map = EventNode.list(PlayerEvent.class, Player.class, PlayerEvent::getPlayer);
map.addListener(PlayerMoveEvent.class, playerMoveEvent -> {
System.out.println("move");
});
GlobalEventHandler globalEventHandler = MinecraftServer.getGlobalEventHandler(); GlobalEventHandler globalEventHandler = MinecraftServer.getGlobalEventHandler();
globalEventHandler.addEventCallback(EntityAttackEvent.class, event -> { globalEventHandler.addEventCallback(EntityAttackEvent.class, event -> {
final Entity source = event.getEntity(); final Entity source = event.getEntity();