From e6e35d3754e4cac3edfb1d11678dec2cfc27ce7b Mon Sep 17 00:00:00 2001 From: Andrew Steinborn Date: Fri, 14 May 2021 12:24:43 -0400 Subject: [PATCH] Add a base interface for events --- .../com/velocitypowered/api/event/Event.java | 9 ++++++ .../api/event/EventHandler.java | 2 +- .../api/event/EventManager.java | 11 +++---- .../api/event/ResultedEvent.java | 2 +- .../command/PlayerAvailableCommandsEvent.java | 3 +- .../api/event/connection/ProxyPingEvent.java | 3 +- .../api/event/connection/ProxyQueryEvent.java | 3 +- .../event/lifecycle/ProxyInitializeEvent.java | 4 ++- .../api/event/lifecycle/ProxyReloadEvent.java | 4 ++- .../event/lifecycle/ProxyShutdownEvent.java | 4 ++- .../lifecycle/network/ListenerBoundEvent.java | 3 +- .../network/ListenerClosedEvent.java | 3 +- .../permission/PermissionsSetupEvent.java | 3 +- .../api/event/player/DisconnectEvent.java | 3 +- .../event/player/GameProfileRequestEvent.java | 3 +- .../player/PlayerChannelRegisterEvent.java | 3 +- .../PlayerChooseInitialServerEvent.java | 3 +- .../PlayerClientSettingsChangedEvent.java | 3 +- .../api/event/player/PlayerModInfoEvent.java | 3 +- .../player/PlayerResourcePackStatusEvent.java | 3 +- .../api/event/player/PostLoginEvent.java | 3 +- .../event/player/ServerConnectedEvent.java | 3 +- .../event/player/ServerPostConnectEvent.java | 3 +- .../api/event/player/TabCompleteEvent.java | 3 +- .../api/util/FastUuidSansHyphens.java | 29 ++++++++++++++++++- .../proxy/event/VelocityEventManager.java | 23 ++++++++------- 26 files changed, 100 insertions(+), 39 deletions(-) create mode 100644 api/src/main/java/com/velocitypowered/api/event/Event.java diff --git a/api/src/main/java/com/velocitypowered/api/event/Event.java b/api/src/main/java/com/velocitypowered/api/event/Event.java new file mode 100644 index 000000000..4d0568f55 --- /dev/null +++ b/api/src/main/java/com/velocitypowered/api/event/Event.java @@ -0,0 +1,9 @@ +package com.velocitypowered.api.event; + +/** + * Base class for all events in the Velocity API. This interface primarily exists to mark which + * classes are events in the API. + */ +public interface Event { + +} diff --git a/api/src/main/java/com/velocitypowered/api/event/EventHandler.java b/api/src/main/java/com/velocitypowered/api/event/EventHandler.java index 2817fca8d..946a622c2 100644 --- a/api/src/main/java/com/velocitypowered/api/event/EventHandler.java +++ b/api/src/main/java/com/velocitypowered/api/event/EventHandler.java @@ -15,7 +15,7 @@ import org.checkerframework.checker.nullness.qual.Nullable; * similar), or pass events through to an external system to be handled. */ @FunctionalInterface -public interface EventHandler { +public interface EventHandler { @Nullable EventTask execute(E event); } diff --git a/api/src/main/java/com/velocitypowered/api/event/EventManager.java b/api/src/main/java/com/velocitypowered/api/event/EventManager.java index 81c9c7c6d..51704d0d1 100644 --- a/api/src/main/java/com/velocitypowered/api/event/EventManager.java +++ b/api/src/main/java/com/velocitypowered/api/event/EventManager.java @@ -32,7 +32,8 @@ public interface EventManager { * @param handler the handler to register * @param the event type to handle */ - default void register(Object plugin, Class eventClass, EventHandler handler) { + default void register(Object plugin, Class eventClass, + EventHandler handler) { register(plugin, eventClass, PostOrder.NORMAL, handler); } @@ -46,7 +47,7 @@ public interface EventManager { * @param handler the handler to register * @param the event type to handle */ - void register(Object plugin, Class eventClass, short postOrder, + void register(Object plugin, Class eventClass, short postOrder, EventHandler handler); /** @@ -57,7 +58,7 @@ public interface EventManager { * @param event the event to fire * @return a {@link CompletableFuture} representing the posted event */ - CompletableFuture fire(E event); + CompletableFuture fire(E event); /** * Posts the specified event to the event bus and discards the result. @@ -65,7 +66,7 @@ public interface EventManager { * @param event the event to fire */ @SuppressWarnings("FutureReturnValueIgnored") - default void fireAndForget(Object event) { + default void fireAndForget(Event event) { // Calling fire(Object) and not handling it is intentional. fire(event); } @@ -92,5 +93,5 @@ public interface EventManager { * @param handler the handler to register * @param the event type to handle */ - void unregister(Object plugin, EventHandler handler); + void unregister(Object plugin, EventHandler handler); } diff --git a/api/src/main/java/com/velocitypowered/api/event/ResultedEvent.java b/api/src/main/java/com/velocitypowered/api/event/ResultedEvent.java index 9be0d2eb7..4ca9295a8 100644 --- a/api/src/main/java/com/velocitypowered/api/event/ResultedEvent.java +++ b/api/src/main/java/com/velocitypowered/api/event/ResultedEvent.java @@ -16,7 +16,7 @@ import org.checkerframework.checker.nullness.qual.Nullable; /** * Indicates an event that has a result attached to it. */ -public interface ResultedEvent { +public interface ResultedEvent extends Event { /** * Returns the result associated with this event. diff --git a/api/src/main/java/com/velocitypowered/api/event/command/PlayerAvailableCommandsEvent.java b/api/src/main/java/com/velocitypowered/api/event/command/PlayerAvailableCommandsEvent.java index 9cc5b560d..ea7d5b972 100644 --- a/api/src/main/java/com/velocitypowered/api/event/command/PlayerAvailableCommandsEvent.java +++ b/api/src/main/java/com/velocitypowered/api/event/command/PlayerAvailableCommandsEvent.java @@ -8,13 +8,14 @@ package com.velocitypowered.api.event.command; import com.mojang.brigadier.tree.RootCommandNode; +import com.velocitypowered.api.event.Event; import com.velocitypowered.api.proxy.connection.Player; /** * Allows plugins to modify the packet indicating commands available on the server to a * Minecraft 1.13+ client. */ -public interface PlayerAvailableCommandsEvent { +public interface PlayerAvailableCommandsEvent extends Event { Player player(); diff --git a/api/src/main/java/com/velocitypowered/api/event/connection/ProxyPingEvent.java b/api/src/main/java/com/velocitypowered/api/event/connection/ProxyPingEvent.java index fb16908bb..06e89a96c 100644 --- a/api/src/main/java/com/velocitypowered/api/event/connection/ProxyPingEvent.java +++ b/api/src/main/java/com/velocitypowered/api/event/connection/ProxyPingEvent.java @@ -7,13 +7,14 @@ package com.velocitypowered.api.event.connection; +import com.velocitypowered.api.event.Event; import com.velocitypowered.api.proxy.connection.InboundConnection; import com.velocitypowered.api.proxy.server.ServerPing; /** * This event is fired when a server list ping request is sent by a remote client. */ -public interface ProxyPingEvent { +public interface ProxyPingEvent extends Event { InboundConnection connection(); diff --git a/api/src/main/java/com/velocitypowered/api/event/connection/ProxyQueryEvent.java b/api/src/main/java/com/velocitypowered/api/event/connection/ProxyQueryEvent.java index 058d357f7..f73f137bc 100644 --- a/api/src/main/java/com/velocitypowered/api/event/connection/ProxyQueryEvent.java +++ b/api/src/main/java/com/velocitypowered/api/event/connection/ProxyQueryEvent.java @@ -7,13 +7,14 @@ package com.velocitypowered.api.event.connection; +import com.velocitypowered.api.event.Event; import com.velocitypowered.api.proxy.server.QueryResponse; import java.net.InetAddress; /** * This event is fired if proxy is getting queried over GS4 Query protocol. */ -public interface ProxyQueryEvent { +public interface ProxyQueryEvent extends Event { /** * Returns the kind of query the remote client is performing. diff --git a/api/src/main/java/com/velocitypowered/api/event/lifecycle/ProxyInitializeEvent.java b/api/src/main/java/com/velocitypowered/api/event/lifecycle/ProxyInitializeEvent.java index 046ff239a..bee4c30c4 100644 --- a/api/src/main/java/com/velocitypowered/api/event/lifecycle/ProxyInitializeEvent.java +++ b/api/src/main/java/com/velocitypowered/api/event/lifecycle/ProxyInitializeEvent.java @@ -7,10 +7,12 @@ package com.velocitypowered.api.event.lifecycle; +import com.velocitypowered.api.event.Event; + /** * This event is fired by the proxy after plugins have been loaded but before the proxy starts * accepting connections. */ -public interface ProxyInitializeEvent { +public interface ProxyInitializeEvent extends Event { } diff --git a/api/src/main/java/com/velocitypowered/api/event/lifecycle/ProxyReloadEvent.java b/api/src/main/java/com/velocitypowered/api/event/lifecycle/ProxyReloadEvent.java index 763cee952..356db832c 100644 --- a/api/src/main/java/com/velocitypowered/api/event/lifecycle/ProxyReloadEvent.java +++ b/api/src/main/java/com/velocitypowered/api/event/lifecycle/ProxyReloadEvent.java @@ -7,9 +7,11 @@ package com.velocitypowered.api.event.lifecycle; +import com.velocitypowered.api.event.Event; + /** * This event is fired when the proxy is reloaded by the user using {@code /velocity reload}. */ -public interface ProxyReloadEvent { +public interface ProxyReloadEvent extends Event { } diff --git a/api/src/main/java/com/velocitypowered/api/event/lifecycle/ProxyShutdownEvent.java b/api/src/main/java/com/velocitypowered/api/event/lifecycle/ProxyShutdownEvent.java index cb0118907..899d8f0a0 100644 --- a/api/src/main/java/com/velocitypowered/api/event/lifecycle/ProxyShutdownEvent.java +++ b/api/src/main/java/com/velocitypowered/api/event/lifecycle/ProxyShutdownEvent.java @@ -7,10 +7,12 @@ package com.velocitypowered.api.event.lifecycle; +import com.velocitypowered.api.event.Event; + /** * This event is fired by the proxy after the proxy has stopped accepting connections but before the * proxy process exits. */ -public interface ProxyShutdownEvent { +public interface ProxyShutdownEvent extends Event { } diff --git a/api/src/main/java/com/velocitypowered/api/event/lifecycle/network/ListenerBoundEvent.java b/api/src/main/java/com/velocitypowered/api/event/lifecycle/network/ListenerBoundEvent.java index e53ed6277..3ee9f9501 100644 --- a/api/src/main/java/com/velocitypowered/api/event/lifecycle/network/ListenerBoundEvent.java +++ b/api/src/main/java/com/velocitypowered/api/event/lifecycle/network/ListenerBoundEvent.java @@ -7,13 +7,14 @@ package com.velocitypowered.api.event.lifecycle.network; +import com.velocitypowered.api.event.Event; import com.velocitypowered.api.network.ListenerType; import java.net.SocketAddress; /** * This event is fired by the proxy after a listener starts accepting connections. */ -public interface ListenerBoundEvent { +public interface ListenerBoundEvent extends Event { SocketAddress address(); diff --git a/api/src/main/java/com/velocitypowered/api/event/lifecycle/network/ListenerClosedEvent.java b/api/src/main/java/com/velocitypowered/api/event/lifecycle/network/ListenerClosedEvent.java index 78595935c..5832df58b 100644 --- a/api/src/main/java/com/velocitypowered/api/event/lifecycle/network/ListenerClosedEvent.java +++ b/api/src/main/java/com/velocitypowered/api/event/lifecycle/network/ListenerClosedEvent.java @@ -7,13 +7,14 @@ package com.velocitypowered.api.event.lifecycle.network; +import com.velocitypowered.api.event.Event; import com.velocitypowered.api.network.ListenerType; import java.net.SocketAddress; /** * This event is fired by the proxy before the proxy stops accepting connections. */ -public interface ListenerClosedEvent { +public interface ListenerClosedEvent extends Event { SocketAddress address(); diff --git a/api/src/main/java/com/velocitypowered/api/event/permission/PermissionsSetupEvent.java b/api/src/main/java/com/velocitypowered/api/event/permission/PermissionsSetupEvent.java index 99241271a..8b89f0460 100644 --- a/api/src/main/java/com/velocitypowered/api/event/permission/PermissionsSetupEvent.java +++ b/api/src/main/java/com/velocitypowered/api/event/permission/PermissionsSetupEvent.java @@ -7,6 +7,7 @@ package com.velocitypowered.api.event.permission; +import com.velocitypowered.api.event.Event; import com.velocitypowered.api.permission.PermissionFunction; import com.velocitypowered.api.permission.PermissionProvider; import com.velocitypowered.api.permission.PermissionSubject; @@ -17,7 +18,7 @@ import org.checkerframework.checker.nullness.qual.Nullable; * *

This event is only called once per subject, on initialisation.

*/ -public interface PermissionsSetupEvent { +public interface PermissionsSetupEvent extends Event { PermissionSubject subject(); diff --git a/api/src/main/java/com/velocitypowered/api/event/player/DisconnectEvent.java b/api/src/main/java/com/velocitypowered/api/event/player/DisconnectEvent.java index 85f0744e8..7fb39d02b 100644 --- a/api/src/main/java/com/velocitypowered/api/event/player/DisconnectEvent.java +++ b/api/src/main/java/com/velocitypowered/api/event/player/DisconnectEvent.java @@ -7,13 +7,14 @@ package com.velocitypowered.api.event.player; +import com.velocitypowered.api.event.Event; import com.velocitypowered.api.proxy.connection.Player; /** * This event is fired when a player disconnects from the proxy. Operations on the provided player, * aside from basic data retrieval operations, may behave in undefined ways. */ -public interface DisconnectEvent { +public interface DisconnectEvent extends Event { Player player(); diff --git a/api/src/main/java/com/velocitypowered/api/event/player/GameProfileRequestEvent.java b/api/src/main/java/com/velocitypowered/api/event/player/GameProfileRequestEvent.java index cb6efa4c4..96ad98cfc 100644 --- a/api/src/main/java/com/velocitypowered/api/event/player/GameProfileRequestEvent.java +++ b/api/src/main/java/com/velocitypowered/api/event/player/GameProfileRequestEvent.java @@ -7,6 +7,7 @@ package com.velocitypowered.api.event.player; +import com.velocitypowered.api.event.Event; import com.velocitypowered.api.proxy.connection.InboundConnection; import com.velocitypowered.api.util.GameProfile; import org.checkerframework.checker.nullness.qual.Nullable; @@ -15,7 +16,7 @@ import org.checkerframework.checker.nullness.qual.Nullable; * This event is fired after the {@link PreLoginEventImpl} in order to set up the game profile for * the user. This can be used to configure a custom profile for a user, i.e. skin replacement. */ -public interface GameProfileRequestEvent { +public interface GameProfileRequestEvent extends Event { InboundConnection connection(); diff --git a/api/src/main/java/com/velocitypowered/api/event/player/PlayerChannelRegisterEvent.java b/api/src/main/java/com/velocitypowered/api/event/player/PlayerChannelRegisterEvent.java index 891c29bb6..481f0a65e 100644 --- a/api/src/main/java/com/velocitypowered/api/event/player/PlayerChannelRegisterEvent.java +++ b/api/src/main/java/com/velocitypowered/api/event/player/PlayerChannelRegisterEvent.java @@ -7,6 +7,7 @@ package com.velocitypowered.api.event.player; +import com.velocitypowered.api.event.Event; import com.velocitypowered.api.proxy.connection.Player; import com.velocitypowered.api.proxy.messages.PluginChannelId; import java.util.List; @@ -15,7 +16,7 @@ import java.util.List; * This event is fired when a client ({@link Player}) sends a plugin message through the * register channel. */ -public interface PlayerChannelRegisterEvent { +public interface PlayerChannelRegisterEvent extends Event { Player player(); diff --git a/api/src/main/java/com/velocitypowered/api/event/player/PlayerChooseInitialServerEvent.java b/api/src/main/java/com/velocitypowered/api/event/player/PlayerChooseInitialServerEvent.java index 193b0a99b..ee4785ad0 100644 --- a/api/src/main/java/com/velocitypowered/api/event/player/PlayerChooseInitialServerEvent.java +++ b/api/src/main/java/com/velocitypowered/api/event/player/PlayerChooseInitialServerEvent.java @@ -7,6 +7,7 @@ package com.velocitypowered.api.event.player; +import com.velocitypowered.api.event.Event; import com.velocitypowered.api.proxy.connection.Player; import com.velocitypowered.api.proxy.server.RegisteredServer; import org.checkerframework.checker.nullness.qual.Nullable; @@ -15,7 +16,7 @@ import org.checkerframework.checker.nullness.qual.Nullable; * Fired when a player has finished connecting to the proxy and we need to choose the first server * to connect to. */ -public interface PlayerChooseInitialServerEvent { +public interface PlayerChooseInitialServerEvent extends Event { Player player(); diff --git a/api/src/main/java/com/velocitypowered/api/event/player/PlayerClientSettingsChangedEvent.java b/api/src/main/java/com/velocitypowered/api/event/player/PlayerClientSettingsChangedEvent.java index 8b12d268a..d9eb94da0 100644 --- a/api/src/main/java/com/velocitypowered/api/event/player/PlayerClientSettingsChangedEvent.java +++ b/api/src/main/java/com/velocitypowered/api/event/player/PlayerClientSettingsChangedEvent.java @@ -7,10 +7,11 @@ package com.velocitypowered.api.event.player; +import com.velocitypowered.api.event.Event; import com.velocitypowered.api.proxy.connection.Player; import com.velocitypowered.api.proxy.player.ClientSettings; -public interface PlayerClientSettingsChangedEvent { +public interface PlayerClientSettingsChangedEvent extends Event { Player player(); diff --git a/api/src/main/java/com/velocitypowered/api/event/player/PlayerModInfoEvent.java b/api/src/main/java/com/velocitypowered/api/event/player/PlayerModInfoEvent.java index 020fd4c9e..d02f3e910 100644 --- a/api/src/main/java/com/velocitypowered/api/event/player/PlayerModInfoEvent.java +++ b/api/src/main/java/com/velocitypowered/api/event/player/PlayerModInfoEvent.java @@ -7,6 +7,7 @@ package com.velocitypowered.api.event.player; +import com.velocitypowered.api.event.Event; import com.velocitypowered.api.proxy.connection.Player; import com.velocitypowered.api.util.ModInfo; @@ -14,7 +15,7 @@ import com.velocitypowered.api.util.ModInfo; * This event is fired when a modded client sends its mods to the proxy while connecting to a * server. */ -public interface PlayerModInfoEvent { +public interface PlayerModInfoEvent extends Event { Player player(); diff --git a/api/src/main/java/com/velocitypowered/api/event/player/PlayerResourcePackStatusEvent.java b/api/src/main/java/com/velocitypowered/api/event/player/PlayerResourcePackStatusEvent.java index 1e3a75a39..1f92c5d12 100644 --- a/api/src/main/java/com/velocitypowered/api/event/player/PlayerResourcePackStatusEvent.java +++ b/api/src/main/java/com/velocitypowered/api/event/player/PlayerResourcePackStatusEvent.java @@ -7,13 +7,14 @@ package com.velocitypowered.api.event.player; +import com.velocitypowered.api.event.Event; import com.velocitypowered.api.proxy.connection.Player; /** * This event is fired when the status of a resource pack sent to the player by the server is * changed. */ -public interface PlayerResourcePackStatusEvent { +public interface PlayerResourcePackStatusEvent extends Event { /** * Returns the player affected by the change in resource pack status. diff --git a/api/src/main/java/com/velocitypowered/api/event/player/PostLoginEvent.java b/api/src/main/java/com/velocitypowered/api/event/player/PostLoginEvent.java index 47348ae29..14245f7bc 100644 --- a/api/src/main/java/com/velocitypowered/api/event/player/PostLoginEvent.java +++ b/api/src/main/java/com/velocitypowered/api/event/player/PostLoginEvent.java @@ -7,13 +7,14 @@ package com.velocitypowered.api.event.player; +import com.velocitypowered.api.event.Event; import com.velocitypowered.api.proxy.connection.Player; /** * This event is fired once the player has been fully initialized and is about to connect to their * first server. */ -public interface PostLoginEvent { +public interface PostLoginEvent extends Event { Player player(); } diff --git a/api/src/main/java/com/velocitypowered/api/event/player/ServerConnectedEvent.java b/api/src/main/java/com/velocitypowered/api/event/player/ServerConnectedEvent.java index f65e1fb3d..35820a261 100644 --- a/api/src/main/java/com/velocitypowered/api/event/player/ServerConnectedEvent.java +++ b/api/src/main/java/com/velocitypowered/api/event/player/ServerConnectedEvent.java @@ -7,6 +7,7 @@ package com.velocitypowered.api.event.player; +import com.velocitypowered.api.event.Event; import com.velocitypowered.api.proxy.connection.Player; import com.velocitypowered.api.proxy.server.RegisteredServer; import org.checkerframework.checker.nullness.qual.Nullable; @@ -15,7 +16,7 @@ import org.checkerframework.checker.nullness.qual.Nullable; * This event is fired once the player has successfully connected to the target server and the * connection to the previous server has been de-established. */ -public interface ServerConnectedEvent { +public interface ServerConnectedEvent extends Event { Player player(); diff --git a/api/src/main/java/com/velocitypowered/api/event/player/ServerPostConnectEvent.java b/api/src/main/java/com/velocitypowered/api/event/player/ServerPostConnectEvent.java index 3eaf6a068..450686b9a 100644 --- a/api/src/main/java/com/velocitypowered/api/event/player/ServerPostConnectEvent.java +++ b/api/src/main/java/com/velocitypowered/api/event/player/ServerPostConnectEvent.java @@ -7,6 +7,7 @@ package com.velocitypowered.api.event.player; +import com.velocitypowered.api.event.Event; import com.velocitypowered.api.proxy.connection.Player; import com.velocitypowered.api.proxy.server.RegisteredServer; import org.checkerframework.checker.nullness.qual.Nullable; @@ -15,7 +16,7 @@ import org.checkerframework.checker.nullness.qual.Nullable; * Fired after the player has connected to a server. The server the player is now connected to is * available in {@link Player#connectedServer()}. */ -public interface ServerPostConnectEvent { +public interface ServerPostConnectEvent extends Event { Player player(); diff --git a/api/src/main/java/com/velocitypowered/api/event/player/TabCompleteEvent.java b/api/src/main/java/com/velocitypowered/api/event/player/TabCompleteEvent.java index d15e8efa6..a6056e597 100644 --- a/api/src/main/java/com/velocitypowered/api/event/player/TabCompleteEvent.java +++ b/api/src/main/java/com/velocitypowered/api/event/player/TabCompleteEvent.java @@ -7,6 +7,7 @@ package com.velocitypowered.api.event.player; +import com.velocitypowered.api.event.Event; import com.velocitypowered.api.proxy.connection.Player; import java.util.List; @@ -14,7 +15,7 @@ import java.util.List; * This event is fired after a tab complete response is sent by the remote server, for clients on * 1.12.2 and below. You have the opportunity to modify the response sent to the remote player. */ -public interface TabCompleteEvent { +public interface TabCompleteEvent extends Event { /** * Returns the player requesting the tab completion. diff --git a/api/src/main/java/com/velocitypowered/api/util/FastUuidSansHyphens.java b/api/src/main/java/com/velocitypowered/api/util/FastUuidSansHyphens.java index feba60464..dc001ea6f 100644 --- a/api/src/main/java/com/velocitypowered/api/util/FastUuidSansHyphens.java +++ b/api/src/main/java/com/velocitypowered/api/util/FastUuidSansHyphens.java @@ -10,7 +10,34 @@ package com.velocitypowered.api.util; import java.util.Arrays; import java.util.UUID; -/** +/* + * This file is derived from the FastUUID project (https://github.com/jchambers/fast-uuid). The + * original copyright notice is reproduced below: + * + * The MIT License (MIT) + * + * Copyright (c) 2018 Jon Chambers + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + +/* * This is a modified FastUUID implementation. The primary difference is that it does not dash its * UUIDs. As the native Java 9+ UUID.toString() implementation dashes its UUIDs, we use the FastUUID * internal method, which ought to be faster than a String.replace(). diff --git a/proxy/src/main/java/com/velocitypowered/proxy/event/VelocityEventManager.java b/proxy/src/main/java/com/velocitypowered/proxy/event/VelocityEventManager.java index e544deb68..5b738a5ca 100644 --- a/proxy/src/main/java/com/velocitypowered/proxy/event/VelocityEventManager.java +++ b/proxy/src/main/java/com/velocitypowered/proxy/event/VelocityEventManager.java @@ -27,6 +27,7 @@ import com.google.common.collect.Multimap; import com.google.common.reflect.TypeToken; import com.google.common.util.concurrent.ThreadFactoryBuilder; import com.velocitypowered.api.event.Continuation; +import com.velocitypowered.api.event.Event; import com.velocitypowered.api.event.EventHandler; import com.velocitypowered.api.event.EventManager; import com.velocitypowered.api.event.EventTask; @@ -107,7 +108,7 @@ public class VelocityEventManager implements EventManager { final PluginContainer plugin; final short order; final Class eventType; - final EventHandler handler; + final EventHandler handler; final AsyncType asyncType; /** @@ -117,7 +118,7 @@ public class VelocityEventManager implements EventManager { final Object instance; public HandlerRegistration(final PluginContainer plugin, final short order, - final Class eventType, final Object instance, final EventHandler handler, + final Class eventType, final Object instance, final EventHandler handler, final AsyncType asyncType) { this.plugin = plugin; this.order = order; @@ -320,14 +321,14 @@ public class VelocityEventManager implements EventManager { @Override @SuppressWarnings("unchecked") - public void register(final Object plugin, final Class eventClass, + public void register(final Object plugin, final Class eventClass, final short order, final EventHandler handler) { final PluginContainer pluginContainer = pluginManager.ensurePluginContainer(plugin); requireNonNull(eventClass, "eventClass"); requireNonNull(handler, "handler"); final HandlerRegistration registration = new HandlerRegistration(pluginContainer, order, - eventClass, handler, (EventHandler) handler, AsyncType.SOMETIMES); + eventClass, handler, (EventHandler) handler, AsyncType.SOMETIMES); register(Collections.singletonList(registration)); } @@ -349,7 +350,7 @@ public class VelocityEventManager implements EventManager { throw new VerifyException("Event type is not present and there are no errors"); } - final EventHandler handler = event -> untargetedHandler.execute(listener, event); + final EventHandler handler = event -> untargetedHandler.execute(listener, event); registrations.add(new HandlerRegistration(pluginContainer, info.order, info.eventType, listener, handler, info.asyncType)); } @@ -372,7 +373,7 @@ public class VelocityEventManager implements EventManager { } @Override - public void unregister(final Object plugin, final EventHandler handler) { + public void unregister(final Object plugin, final EventHandler handler) { unregisterListener(plugin, handler); } @@ -400,7 +401,7 @@ public class VelocityEventManager implements EventManager { } @Override - public void fireAndForget(final Object event) { + public void fireAndForget(final Event event) { requireNonNull(event, "event"); final HandlersCache handlersCache = this.handlersCache.get(event.getClass()); if (handlersCache == null) { @@ -411,7 +412,7 @@ public class VelocityEventManager implements EventManager { } @Override - public CompletableFuture fire(final E event) { + public CompletableFuture fire(final E event) { requireNonNull(event, "event"); final HandlersCache handlersCache = this.handlersCache.get(event.getClass()); if (handlersCache == null) { @@ -423,7 +424,7 @@ public class VelocityEventManager implements EventManager { return future; } - private void fire(final @Nullable CompletableFuture future, + private void fire(final @Nullable CompletableFuture future, final E event, final HandlersCache handlersCache) { if (handlersCache.asyncType == AsyncType.ALWAYS) { // We already know that the event needs to be handled async, so @@ -452,7 +453,7 @@ public class VelocityEventManager implements EventManager { } } - final class ContinuationTask implements Continuation, Runnable { + final class ContinuationTask implements Continuation, Runnable { private final EventTask.WithContinuation task; private final int index; @@ -545,7 +546,7 @@ public class VelocityEventManager implements EventManager { } } - private void fire(final @Nullable CompletableFuture future, final E event, + private void fire(final @Nullable CompletableFuture future, final E event, final int offset, final boolean currentlyAsync, final HandlerRegistration[] registrations) { for (int i = offset; i < registrations.length; i++) { final HandlerRegistration registration = registrations[i];