From d9b26f84d35436a19b342ee9045c1747323943ce Mon Sep 17 00:00:00 2001 From: TheMode Date: Fri, 4 Jun 2021 04:54:07 +0200 Subject: [PATCH] Keep using GlobalEventHandler --- .../net/minestom/server/MinecraftServer.java | 12 +-------- .../net/minestom/server/entity/Entity.java | 2 +- .../server/event/EventDispatcher.java | 4 +-- .../server/event/GlobalEventHandler.java | 26 +++++++++---------- .../minestom/server/instance/Instance.java | 2 +- 5 files changed, 17 insertions(+), 29 deletions(-) diff --git a/src/main/java/net/minestom/server/MinecraftServer.java b/src/main/java/net/minestom/server/MinecraftServer.java index 0780c0e4b..cc1b63a8c 100644 --- a/src/main/java/net/minestom/server/MinecraftServer.java +++ b/src/main/java/net/minestom/server/MinecraftServer.java @@ -8,8 +8,6 @@ import net.minestom.server.data.DataType; import net.minestom.server.data.SerializableData; import net.minestom.server.entity.EntityType; import net.minestom.server.entity.Player; -import net.minestom.server.event.Event; -import net.minestom.server.event.EventNode; import net.minestom.server.event.GlobalEventHandler; import net.minestom.server.exception.ExceptionManager; import net.minestom.server.extensions.Extension; @@ -125,7 +123,6 @@ public final class MinecraftServer { private static ExtensionManager extensionManager; - private static final EventNode GLOBAL_EVENT_NODE = EventNode.all("global"); private static final GlobalEventHandler GLOBAL_EVENT_HANDLER = new GlobalEventHandler(); private static UpdateManager updateManager; @@ -300,18 +297,11 @@ public final class MinecraftServer { * Used to register event callback at a global scale. * * @return the global event handler - * @deprecated use {@link #getGlobalEventNode()} */ - @NotNull - @Deprecated - public static GlobalEventHandler getGlobalEventHandler() { + public static @NotNull GlobalEventHandler getGlobalEventHandler() { return GLOBAL_EVENT_HANDLER; } - public static @NotNull EventNode getGlobalEventNode() { - return GLOBAL_EVENT_NODE; - } - /** * Gets the manager handling all incoming packets * diff --git a/src/main/java/net/minestom/server/entity/Entity.java b/src/main/java/net/minestom/server/entity/Entity.java index 0a4334fb2..db8afd81c 100644 --- a/src/main/java/net/minestom/server/entity/Entity.java +++ b/src/main/java/net/minestom/server/entity/Entity.java @@ -157,7 +157,7 @@ public class Entity implements Viewable, Tickable, EventHandler, Da Entity.ENTITY_BY_UUID.put(uuid, this); this.eventNode = EventNode.type("entity-" + uuid, EventFilter.ENTITY); - MinecraftServer.getGlobalEventNode().map(this, eventNode); + MinecraftServer.getGlobalEventHandler().map(this, eventNode); } public Entity(@NotNull EntityType entityType) { diff --git a/src/main/java/net/minestom/server/event/EventDispatcher.java b/src/main/java/net/minestom/server/event/EventDispatcher.java index 83de820ee..1b3a38737 100644 --- a/src/main/java/net/minestom/server/event/EventDispatcher.java +++ b/src/main/java/net/minestom/server/event/EventDispatcher.java @@ -6,10 +6,10 @@ import org.jetbrains.annotations.NotNull; public class EventDispatcher { public static void call(@NotNull Event event) { - MinecraftServer.getGlobalEventNode().call(event); + MinecraftServer.getGlobalEventHandler().call(event); } public static void callCancellable(@NotNull CancellableEvent event, @NotNull Runnable successCallback) { - MinecraftServer.getGlobalEventNode().callCancellable(event, successCallback); + MinecraftServer.getGlobalEventHandler().callCancellable(event, successCallback); } } diff --git a/src/main/java/net/minestom/server/event/GlobalEventHandler.java b/src/main/java/net/minestom/server/event/GlobalEventHandler.java index 351ab08ba..0e1a8c94f 100644 --- a/src/main/java/net/minestom/server/event/GlobalEventHandler.java +++ b/src/main/java/net/minestom/server/event/GlobalEventHandler.java @@ -1,25 +1,23 @@ package net.minestom.server.event; -import net.minestom.server.MinecraftServer; -import net.minestom.server.event.handler.EventHandler; import org.jetbrains.annotations.NotNull; +import java.util.function.Consumer; + /** * Object containing all the global event listeners. - * - * @deprecated use {@link MinecraftServer#getGlobalEventNode()} */ -@Deprecated -public final class GlobalEventHandler implements EventHandler { - - private final EventNode node = EventNode.all("global-handler"); - - { - MinecraftServer.getGlobalEventNode().addChild(node); +public final class GlobalEventHandler extends EventNode { + public GlobalEventHandler() { + super("global", EventFilter.ALL, null); } - @Override - public @NotNull EventNode getEventNode() { - return node; + /** + * @deprecated use {@link #addListener(Class, Consumer)} + */ + @Deprecated + public boolean addEventCallback(@NotNull Class eventClass, @NotNull EventCallback eventCallback) { + addListener(eventClass, eventCallback::run); + return true; } } diff --git a/src/main/java/net/minestom/server/instance/Instance.java b/src/main/java/net/minestom/server/instance/Instance.java index 020423513..030e67b3a 100644 --- a/src/main/java/net/minestom/server/instance/Instance.java +++ b/src/main/java/net/minestom/server/instance/Instance.java @@ -121,7 +121,7 @@ public abstract class Instance implements BlockModifier, Tickable, EventHandler< this.worldBorder = new WorldBorder(this); this.eventNode = EventNode.type("instance-" + uniqueId, EventFilter.INSTANCE); - MinecraftServer.getGlobalEventNode().map(this, eventNode); + MinecraftServer.getGlobalEventHandler().map(this, eventNode); } /**