From 3ec67a7d4dddab20493b6e843c57e6ba56608dbd Mon Sep 17 00:00:00 2001 From: Andrew Steinborn Date: Thu, 16 May 2019 17:09:31 -0400 Subject: [PATCH] Optimize VelocityEventManager#fireAndForget() There isn't a need to create a CompletableFuture when firing an event and we do not want to know when it is completed. --- .../proxy/plugin/VelocityEventManager.java | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/proxy/src/main/java/com/velocitypowered/proxy/plugin/VelocityEventManager.java b/proxy/src/main/java/com/velocitypowered/proxy/plugin/VelocityEventManager.java index 51e625733..24c3c5b90 100644 --- a/proxy/src/main/java/com/velocitypowered/proxy/plugin/VelocityEventManager.java +++ b/proxy/src/main/java/com/velocitypowered/proxy/plugin/VelocityEventManager.java @@ -118,6 +118,18 @@ public class VelocityEventManager implements EventManager { return eventFuture; } + @Override + public void fireAndForget(Object event) { + if (event == null) { + throw new NullPointerException("event"); + } + if (!bus.hasSubscribers(event.getClass())) { + // Optimization: nobody's listening. + return; + } + service.execute(() -> fireEvent(event)); + } + private void fireEvent(Object event) { PostResult result = bus.post(event); if (!result.exceptions().isEmpty()) {