From 5e4af20992ac4d48480548819b00c32f5b189934 Mon Sep 17 00:00:00 2001 From: LeoDog896 Date: Tue, 6 Apr 2021 22:29:24 -0400 Subject: [PATCH] And handle event exceptions --- .../server/event/handler/EventHandler.java | 33 +++++++++++-------- 1 file changed, 19 insertions(+), 14 deletions(-) diff --git a/src/main/java/net/minestom/server/event/handler/EventHandler.java b/src/main/java/net/minestom/server/event/handler/EventHandler.java index 5bb0bf40a..071ad043d 100644 --- a/src/main/java/net/minestom/server/event/handler/EventHandler.java +++ b/src/main/java/net/minestom/server/event/handler/EventHandler.java @@ -109,22 +109,27 @@ public interface EventHandler extends IExtensionObserver { */ default void callEvent(@NotNull Class eventClass, @NotNull E event) { - // Global listeners - if (!(this instanceof GlobalEventHandler)) { - final GlobalEventHandler globalEventHandler = MinecraftServer.getGlobalEventHandler(); - runEvent(globalEventHandler.getEventCallbacks(eventClass), event); - } + try { - // Local listeners - final Collection eventCallbacks = getEventCallbacks(eventClass); - runEvent(eventCallbacks, event); - - // Call the same event for the current entity instance - if (this instanceof Entity) { - final Instance instance = ((Entity) this).getInstance(); - if (instance != null) { - runEvent(instance.getEventCallbacks(eventClass), event); + // Global listeners + if (!(this instanceof GlobalEventHandler)) { + final GlobalEventHandler globalEventHandler = MinecraftServer.getGlobalEventHandler(); + runEvent(globalEventHandler.getEventCallbacks(eventClass), event); } + + // Local listeners + final Collection eventCallbacks = getEventCallbacks(eventClass); + runEvent(eventCallbacks, event); + + // Call the same event for the current entity instance + if (this instanceof Entity) { + final Instance instance = ((Entity) this).getInstance(); + if (instance != null) { + runEvent(instance.getEventCallbacks(eventClass), event); + } + } + } catch (Exception exception) { + MinecraftServer.getExceptionManager().handleException(exception); } }