From f1623e9eab4602dd8f4efef008592c675cd61d63 Mon Sep 17 00:00:00 2001 From: KingRainbow44 Date: Tue, 26 Apr 2022 20:28:13 -0400 Subject: [PATCH] Use a custom consumer instead of the built-in one --- .../emu/grasscutter/plugin/PluginManager.java | 4 ++-- .../grasscutter/server/event/EventHandler.java | 15 +++++---------- .../java/emu/grasscutter/utils/EventConsumer.java | 7 +++++++ 3 files changed, 14 insertions(+), 12 deletions(-) create mode 100644 src/main/java/emu/grasscutter/utils/EventConsumer.java diff --git a/src/main/java/emu/grasscutter/plugin/PluginManager.java b/src/main/java/emu/grasscutter/plugin/PluginManager.java index b82cf6e90..53ac467f3 100644 --- a/src/main/java/emu/grasscutter/plugin/PluginManager.java +++ b/src/main/java/emu/grasscutter/plugin/PluginManager.java @@ -4,6 +4,7 @@ import emu.grasscutter.Grasscutter; import emu.grasscutter.server.event.Event; import emu.grasscutter.server.event.EventHandler; import emu.grasscutter.server.event.HandlerPriority; +import emu.grasscutter.utils.EventConsumer; import emu.grasscutter.utils.Utils; import java.io.File; @@ -14,7 +15,6 @@ import java.net.URLClassLoader; import java.util.*; import java.util.jar.JarEntry; import java.util.jar.JarFile; -import java.util.stream.Stream; /** * Manages the server's plugins and the event system. @@ -164,6 +164,6 @@ public final class PluginManager { private void invokeHandler(Event event, EventHandler handler) { if(!event.isCanceled() || (event.isCanceled() && handler.ignoresCanceled()) - ) handler.getCallback().accept(event); + ) handler.getCallback().consume(event); } } \ No newline at end of file diff --git a/src/main/java/emu/grasscutter/server/event/EventHandler.java b/src/main/java/emu/grasscutter/server/event/EventHandler.java index f24bc2dee..14da6f6a1 100644 --- a/src/main/java/emu/grasscutter/server/event/EventHandler.java +++ b/src/main/java/emu/grasscutter/server/event/EventHandler.java @@ -1,8 +1,7 @@ package emu.grasscutter.server.event; import emu.grasscutter.Grasscutter; - -import java.util.function.Consumer; +import emu.grasscutter.utils.EventConsumer; public final class EventHandler { private final Class event; @@ -16,15 +15,11 @@ public final class EventHandler { return new EventHandler(event); } - /** - * @deprecated Will be replaced with a private constructor instead. Use {@link #forEvent(Class)} instead. - */ - @Deprecated(forRemoval = true, since = "1.0.1") - public EventHandler(Class event) { + private EventHandler(Class event) { this.event = event; } - private Consumer listener; + private EventConsumer listener; private HandlerPriority priority; private boolean handleCanceled; @@ -40,7 +35,7 @@ public final class EventHandler { * Returns the callback for the handler. * @return A consumer callback. */ - public Consumer getCallback() { + public EventConsumer getCallback() { return this.listener; } @@ -65,7 +60,7 @@ public final class EventHandler { * @param listener An event handler method. * @return Method chaining. */ - public EventHandler listener(Consumer listener) { + public EventHandler listener(EventConsumer listener) { this.listener = listener; return this; } diff --git a/src/main/java/emu/grasscutter/utils/EventConsumer.java b/src/main/java/emu/grasscutter/utils/EventConsumer.java new file mode 100644 index 000000000..ae8bb5a9b --- /dev/null +++ b/src/main/java/emu/grasscutter/utils/EventConsumer.java @@ -0,0 +1,7 @@ +package emu.grasscutter.utils; + +import emu.grasscutter.server.event.Event; + +public interface EventConsumer { + void consume(T event); +}