Add a base interface for events

This commit is contained in:
Andrew Steinborn
2021-05-14 12:24:43 -04:00
parent e65c4102a6
commit e6e35d3754
26 changed files with 100 additions and 39 deletions

View File

@@ -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 {
}

View File

@@ -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<E> {
public interface EventHandler<E extends Event> {
@Nullable EventTask execute(E event);
}

View File

@@ -32,7 +32,8 @@ public interface EventManager {
* @param handler the handler to register
* @param <E> the event type to handle
*/
default <E> void register(Object plugin, Class<E> eventClass, EventHandler<E> handler) {
default <E extends Event> void register(Object plugin, Class<E> eventClass,
EventHandler<E> handler) {
register(plugin, eventClass, PostOrder.NORMAL, handler);
}
@@ -46,7 +47,7 @@ public interface EventManager {
* @param handler the handler to register
* @param <E> the event type to handle
*/
<E> void register(Object plugin, Class<E> eventClass, short postOrder,
<E extends Event> void register(Object plugin, Class<E> eventClass, short postOrder,
EventHandler<E> handler);
/**
@@ -57,7 +58,7 @@ public interface EventManager {
* @param event the event to fire
* @return a {@link CompletableFuture} representing the posted event
*/
<E> CompletableFuture<E> fire(E event);
<E extends Event> CompletableFuture<E> 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 <E> the event type to handle
*/
<E> void unregister(Object plugin, EventHandler<E> handler);
<E extends Event> void unregister(Object plugin, EventHandler<E> handler);
}

View File

@@ -16,7 +16,7 @@ import org.checkerframework.checker.nullness.qual.Nullable;
/**
* Indicates an event that has a result attached to it.
*/
public interface ResultedEvent<R extends ResultedEvent.Result> {
public interface ResultedEvent<R extends ResultedEvent.Result> extends Event {
/**
* Returns the result associated with this event.

View File

@@ -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();

View File

@@ -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();

View File

@@ -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.

View File

@@ -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 {
}

View File

@@ -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 {
}

View File

@@ -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 {
}

View File

@@ -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();

View File

@@ -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();

View File

@@ -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;
*
* <p>This event is only called once per subject, on initialisation.</p>
*/
public interface PermissionsSetupEvent {
public interface PermissionsSetupEvent extends Event {
PermissionSubject subject();

View File

@@ -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();

View File

@@ -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();

View File

@@ -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();

View File

@@ -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();

View File

@@ -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();

View File

@@ -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();

View File

@@ -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.

View File

@@ -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();
}

View File

@@ -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();

View File

@@ -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();

View File

@@ -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.

View File

@@ -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().