From 730d385f02a86f4d34734c54ce46074eecd8272f Mon Sep 17 00:00:00 2001 From: Andrew Steinborn Date: Sat, 17 Apr 2021 03:50:10 -0400 Subject: [PATCH] Extract interfaces for all events. This is in preparation for moving to event-impl-gen. --- api/build.gradle | 4 - .../api/command/CommandManager.java | 4 +- .../event/command/CommandExecuteEvent.java | 63 +++---------- .../command/CommandExecuteEventImpl.java | 66 ++++++++++++++ .../command/PlayerAvailableCommandsEvent.java | 28 +----- .../PlayerAvailableCommandsEventImpl.java | 46 ++++++++++ .../connection/ConnectionHandshakeEvent.java | 21 +---- .../ConnectionHandshakeEventImpl.java | 34 +++++++ .../api/event/connection/ProxyPingEvent.java | 31 +------ .../event/connection/ProxyPingEventImpl.java | 49 ++++++++++ .../api/event/connection/ProxyQueryEvent.java | 47 ++-------- .../event/connection/ProxyQueryEventImpl.java | 85 ++++++++++++++++++ .../event/lifecycle/ProxyInitializeEvent.java | 6 +- .../lifecycle/ProxyInitializeEventImpl.java | 20 +++++ .../api/event/lifecycle/ProxyReloadEvent.java | 6 +- .../event/lifecycle/ProxyReloadEventImpl.java | 19 ++++ .../event/lifecycle/ProxyShutdownEvent.java | 6 +- .../lifecycle/ProxyShutdownEventImpl.java | 16 ++++ .../lifecycle/network/ListenerBoundEvent.java | 30 +------ .../network/ListenerBoundEventImpl.java | 44 +++++++++ .../network/ListenerClosedEvent.java | 30 +------ .../network/ListenerClosedEventImpl.java | 44 +++++++++ .../permission/PermissionsSetupEvent.java | 37 ++------ .../permission/PermissionsSetupEventImpl.java | 74 +++++++++++++++ .../api/event/player/DisconnectEvent.java | 31 +------ .../api/event/player/DisconnectEventImpl.java | 45 ++++++++++ .../event/player/GameProfileRequestEvent.java | 2 +- .../event/player/KickedFromServerEvent.java | 64 +++---------- .../player/KickedFromServerEventImpl.java | 89 +++++++++++++++++++ .../api/event/player/LoginEvent.java | 31 +------ .../api/event/player/LoginEventImpl.java | 49 ++++++++++ .../player/PlayerChannelRegisterEvent.java | 27 +----- .../PlayerChannelRegisterEventImpl.java | 46 ++++++++++ .../api/event/player/PlayerChatEvent.java | 50 ++--------- .../api/event/player/PlayerChatEventImpl.java | 62 +++++++++++++ .../PlayerChooseInitialServerEvent.java | 38 ++------ .../PlayerChooseInitialServerEventImpl.java | 61 +++++++++++++ .../api/event/player/PlayerModInfoEvent.java | 31 ++----- .../event/player/PlayerModInfoEventImpl.java | 42 +++++++++ .../player/PlayerResourcePackStatusEvent.java | 29 +----- .../PlayerResourcePackStatusEventImpl.java | 55 ++++++++++++ .../player/PlayerSettingsChangedEvent.java | 28 +----- .../PlayerSettingsChangedEventImpl.java | 42 +++++++++ .../api/event/player/PostLoginEvent.java | 20 +---- .../api/event/player/PostLoginEventImpl.java | 36 ++++++++ .../api/event/player/PreLoginEvent.java | 44 ++------- .../api/event/player/PreLoginEventImpl.java | 65 ++++++++++++++ .../event/player/ServerConnectedEvent.java | 42 +-------- .../player/ServerConnectedEventImpl.java | 62 +++++++++++++ .../event/player/ServerPostConnectEvent.java | 29 +----- .../player/ServerPostConnectEventImpl.java | 47 ++++++++++ .../event/player/ServerPreConnectEvent.java | 59 ++++-------- .../player/ServerPreConnectEventImpl.java | 73 +++++++++++++++ .../api/event/player/TabCompleteEvent.java | 44 ++------- .../event/player/TabCompleteEventImpl.java | 72 +++++++++++++++ .../api/proxy/connection/Player.java | 6 +- .../velocitypowered/proxy/VelocityServer.java | 12 +-- .../proxy/command/VelocityCommandManager.java | 5 +- .../backend/BackendPlaySessionHandler.java | 4 +- .../backend/TransitionSessionHandler.java | 8 +- .../client/ClientPlaySessionHandler.java | 17 ++-- .../connection/client/ConnectedPlayer.java | 20 +++-- .../client/HandshakeSessionHandler.java | 4 +- .../client/LoginSessionHandler.java | 22 ++--- .../client/StatusSessionHandler.java | 6 +- .../proxy/console/VelocityConsole.java | 3 +- .../proxy/network/ConnectionManager.java | 12 +-- .../network/pipeline/GS4QueryHandler.java | 4 +- 68 files changed, 1539 insertions(+), 809 deletions(-) create mode 100644 api/src/main/java/com/velocitypowered/api/event/command/CommandExecuteEventImpl.java create mode 100644 api/src/main/java/com/velocitypowered/api/event/command/PlayerAvailableCommandsEventImpl.java create mode 100644 api/src/main/java/com/velocitypowered/api/event/connection/ConnectionHandshakeEventImpl.java create mode 100644 api/src/main/java/com/velocitypowered/api/event/connection/ProxyPingEventImpl.java create mode 100644 api/src/main/java/com/velocitypowered/api/event/connection/ProxyQueryEventImpl.java create mode 100644 api/src/main/java/com/velocitypowered/api/event/lifecycle/ProxyInitializeEventImpl.java create mode 100644 api/src/main/java/com/velocitypowered/api/event/lifecycle/ProxyReloadEventImpl.java create mode 100644 api/src/main/java/com/velocitypowered/api/event/lifecycle/ProxyShutdownEventImpl.java create mode 100644 api/src/main/java/com/velocitypowered/api/event/lifecycle/network/ListenerBoundEventImpl.java create mode 100644 api/src/main/java/com/velocitypowered/api/event/lifecycle/network/ListenerClosedEventImpl.java create mode 100644 api/src/main/java/com/velocitypowered/api/event/permission/PermissionsSetupEventImpl.java create mode 100644 api/src/main/java/com/velocitypowered/api/event/player/DisconnectEventImpl.java create mode 100644 api/src/main/java/com/velocitypowered/api/event/player/KickedFromServerEventImpl.java create mode 100644 api/src/main/java/com/velocitypowered/api/event/player/LoginEventImpl.java create mode 100644 api/src/main/java/com/velocitypowered/api/event/player/PlayerChannelRegisterEventImpl.java create mode 100644 api/src/main/java/com/velocitypowered/api/event/player/PlayerChatEventImpl.java create mode 100644 api/src/main/java/com/velocitypowered/api/event/player/PlayerChooseInitialServerEventImpl.java create mode 100644 api/src/main/java/com/velocitypowered/api/event/player/PlayerModInfoEventImpl.java create mode 100644 api/src/main/java/com/velocitypowered/api/event/player/PlayerResourcePackStatusEventImpl.java create mode 100644 api/src/main/java/com/velocitypowered/api/event/player/PlayerSettingsChangedEventImpl.java create mode 100644 api/src/main/java/com/velocitypowered/api/event/player/PostLoginEventImpl.java create mode 100644 api/src/main/java/com/velocitypowered/api/event/player/PreLoginEventImpl.java create mode 100644 api/src/main/java/com/velocitypowered/api/event/player/ServerConnectedEventImpl.java create mode 100644 api/src/main/java/com/velocitypowered/api/event/player/ServerPostConnectEventImpl.java create mode 100644 api/src/main/java/com/velocitypowered/api/event/player/ServerPreConnectEventImpl.java create mode 100644 api/src/main/java/com/velocitypowered/api/event/player/TabCompleteEventImpl.java diff --git a/api/build.gradle b/api/build.gradle index 3a518caef..a7e2c2298 100644 --- a/api/build.gradle +++ b/api/build.gradle @@ -100,10 +100,6 @@ test { useJUnitPlatform() } -test { - useJUnitPlatform() -} - publishing { publications { mavenJava(MavenPublication) { diff --git a/api/src/main/java/com/velocitypowered/api/command/CommandManager.java b/api/src/main/java/com/velocitypowered/api/command/CommandManager.java index b8f14fe8e..1ee80e97b 100644 --- a/api/src/main/java/com/velocitypowered/api/command/CommandManager.java +++ b/api/src/main/java/com/velocitypowered/api/command/CommandManager.java @@ -7,7 +7,7 @@ package com.velocitypowered.api.command; -import com.velocitypowered.api.event.command.CommandExecuteEvent; +import com.velocitypowered.api.event.command.CommandExecuteEventImpl; import java.util.concurrent.CompletableFuture; /** @@ -81,7 +81,7 @@ public interface CommandManager { /** * Attempts to asynchronously execute a command from the given {@code cmdLine} - * without firing a {@link CommandExecuteEvent}. + * without firing a {@link CommandExecuteEventImpl}. * * @param source the source to execute the command for * @param cmdLine the command to run diff --git a/api/src/main/java/com/velocitypowered/api/event/command/CommandExecuteEvent.java b/api/src/main/java/com/velocitypowered/api/event/command/CommandExecuteEvent.java index 72ee2f8cd..94dc9c1d3 100644 --- a/api/src/main/java/com/velocitypowered/api/event/command/CommandExecuteEvent.java +++ b/api/src/main/java/com/velocitypowered/api/event/command/CommandExecuteEvent.java @@ -16,63 +16,22 @@ import org.checkerframework.checker.nullness.qual.NonNull; import org.checkerframework.checker.nullness.qual.Nullable; /** - * This event is fired when someone executing command. + * This event is fired when someone executes a command. */ -public final class CommandExecuteEvent implements ResultedEvent { +public interface CommandExecuteEvent extends ResultedEvent { - private final CommandSource commandSource; - private final String command; - private CommandResult result; + CommandSource getCommandSource(); /** - * Constructs a CommandExecuteEvent. - * @param commandSource the source executing the command - * @param command the command being executed without first slash - */ - public CommandExecuteEvent(CommandSource commandSource, String command) { - this.commandSource = Preconditions.checkNotNull(commandSource, "commandSource"); - this.command = Preconditions.checkNotNull(command, "command"); - this.result = CommandResult.allowed(); - } - - public CommandSource getCommandSource() { - return commandSource; - } - - /** - * Gets the original command being executed without first slash. + * Gets the original command being executed without the first slash. * @return the original command being executed */ - public String getCommand() { - return command; - } + String getCommand(); - @Override - public CommandResult getResult() { - return result; - } + final class CommandResult implements ResultedEvent.Result { - @Override - public void setResult(CommandResult result) { - this.result = Preconditions.checkNotNull(result, "result"); - } - - @Override - public String toString() { - return "CommandExecuteEvent{" - + "commandSource=" + commandSource - + ", command=" + command - + ", result=" + result - + '}'; - } - - /** - * Represents the result of the {@link CommandExecuteEvent}. - */ - public static final class CommandResult implements ResultedEvent.Result { - - private static final CommandResult ALLOWED = new CommandResult(true, false,null); - private static final CommandResult DENIED = new CommandResult(false, false,null); + private static final CommandResult ALLOWED = new CommandResult(true, false, null); + private static final CommandResult DENIED = new CommandResult(false, false, null); private static final CommandResult FORWARD_TO_SERVER = new CommandResult(false, true, null); private @Nullable String command; @@ -105,6 +64,7 @@ public final class CommandExecuteEvent implements ResultedEvent { /** * Allows the command to be sent, without modification. + * * @return the allowed result */ public static CommandResult allowed() { @@ -113,6 +73,7 @@ public final class CommandExecuteEvent implements ResultedEvent { /** * Prevents the command from being executed. + * * @return the denied result */ public static CommandResult denied() { @@ -121,6 +82,7 @@ public final class CommandExecuteEvent implements ResultedEvent { /** * Prevents the command from being executed, but forward command to server. + * * @return the forward result */ public static CommandResult forwardToServer() { @@ -129,6 +91,7 @@ public final class CommandExecuteEvent implements ResultedEvent { /** * Prevents the command from being executed on proxy, but forward command to server. + * * @param newCommand the command without first slash to use instead * @return a result with a new command being forwarded to server */ @@ -139,6 +102,7 @@ public final class CommandExecuteEvent implements ResultedEvent { /** * Allows the command to be executed, but silently replaced old command with another. + * * @param newCommand the command to use instead without first slash * @return a result with a new command */ @@ -147,4 +111,5 @@ public final class CommandExecuteEvent implements ResultedEvent { return new CommandResult(true, false, newCommand); } } + } diff --git a/api/src/main/java/com/velocitypowered/api/event/command/CommandExecuteEventImpl.java b/api/src/main/java/com/velocitypowered/api/event/command/CommandExecuteEventImpl.java new file mode 100644 index 000000000..672b93522 --- /dev/null +++ b/api/src/main/java/com/velocitypowered/api/event/command/CommandExecuteEventImpl.java @@ -0,0 +1,66 @@ +/* + * Copyright (C) 2018 Velocity Contributors + * + * The Velocity API is licensed under the terms of the MIT License. For more details, + * reference the LICENSE file in the api top-level directory. + */ + +package com.velocitypowered.api.event.command; + +import com.google.common.base.Preconditions; +import com.velocitypowered.api.command.CommandSource; + +/** + * This event is fired when someone executing command. + */ +public final class CommandExecuteEventImpl implements CommandExecuteEvent { + + private final CommandSource commandSource; + private final String command; + private CommandResult result; + + /** + * Constructs a CommandExecuteEvent. + * @param commandSource the source executing the command + * @param command the command being executed without first slash + */ + public CommandExecuteEventImpl(CommandSource commandSource, String command) { + this.commandSource = Preconditions.checkNotNull(commandSource, "commandSource"); + this.command = Preconditions.checkNotNull(command, "command"); + this.result = CommandResult.allowed(); + } + + @Override + public CommandSource getCommandSource() { + return commandSource; + } + + /** + * Gets the original command being executed without first slash. + * @return the original command being executed + */ + @Override + public String getCommand() { + return command; + } + + @Override + public CommandResult getResult() { + return result; + } + + @Override + public void setResult(CommandResult result) { + this.result = Preconditions.checkNotNull(result, "result"); + } + + @Override + public String toString() { + return "CommandExecuteEvent{" + + "commandSource=" + commandSource + + ", command=" + command + + ", result=" + result + + '}'; + } + +} 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 e0aa0eeb5..1948beec2 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 @@ -7,9 +7,6 @@ package com.velocitypowered.api.event.command; -import static com.google.common.base.Preconditions.checkNotNull; - -import com.google.common.annotations.Beta; import com.mojang.brigadier.tree.RootCommandNode; import com.velocitypowered.api.proxy.connection.Player; @@ -17,28 +14,9 @@ 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. */ -@Beta -public class PlayerAvailableCommandsEvent { +public interface PlayerAvailableCommandsEvent { - private final Player player; - private final RootCommandNode rootNode; + Player getPlayer(); - /** - * Constructs an available commands event. - * @param player the targeted player - * @param rootNode the Brigadier root node - */ - public PlayerAvailableCommandsEvent(Player player, - RootCommandNode rootNode) { - this.player = checkNotNull(player, "player"); - this.rootNode = checkNotNull(rootNode, "rootNode"); - } - - public Player getPlayer() { - return player; - } - - public RootCommandNode getRootNode() { - return rootNode; - } + RootCommandNode getRootNode(); } diff --git a/api/src/main/java/com/velocitypowered/api/event/command/PlayerAvailableCommandsEventImpl.java b/api/src/main/java/com/velocitypowered/api/event/command/PlayerAvailableCommandsEventImpl.java new file mode 100644 index 000000000..926d94c17 --- /dev/null +++ b/api/src/main/java/com/velocitypowered/api/event/command/PlayerAvailableCommandsEventImpl.java @@ -0,0 +1,46 @@ +/* + * Copyright (C) 2018 Velocity Contributors + * + * The Velocity API is licensed under the terms of the MIT License. For more details, + * reference the LICENSE file in the api top-level directory. + */ + +package com.velocitypowered.api.event.command; + +import static com.google.common.base.Preconditions.checkNotNull; + +import com.google.common.annotations.Beta; +import com.mojang.brigadier.tree.RootCommandNode; +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. + */ +@Beta +public class PlayerAvailableCommandsEventImpl implements PlayerAvailableCommandsEvent { + + private final Player player; + private final RootCommandNode rootNode; + + /** + * Constructs an available commands event. + * @param player the targeted player + * @param rootNode the Brigadier root node + */ + public PlayerAvailableCommandsEventImpl(Player player, + RootCommandNode rootNode) { + this.player = checkNotNull(player, "player"); + this.rootNode = checkNotNull(rootNode, "rootNode"); + } + + @Override + public Player getPlayer() { + return player; + } + + @Override + public RootCommandNode getRootNode() { + return rootNode; + } +} diff --git a/api/src/main/java/com/velocitypowered/api/event/connection/ConnectionHandshakeEvent.java b/api/src/main/java/com/velocitypowered/api/event/connection/ConnectionHandshakeEvent.java index baa008286..166981316 100644 --- a/api/src/main/java/com/velocitypowered/api/event/connection/ConnectionHandshakeEvent.java +++ b/api/src/main/java/com/velocitypowered/api/event/connection/ConnectionHandshakeEvent.java @@ -7,28 +7,9 @@ package com.velocitypowered.api.event.connection; -import com.google.common.base.Preconditions; -import com.velocitypowered.api.proxy.connection.InboundConnection; - /** * This event is fired when a handshake is established between a client and the proxy. */ -public final class ConnectionHandshakeEvent { +public interface ConnectionHandshakeEvent { - private final InboundConnection connection; - - public ConnectionHandshakeEvent(InboundConnection connection) { - this.connection = Preconditions.checkNotNull(connection, "connection"); - } - - public InboundConnection getConnection() { - return connection; - } - - @Override - public String toString() { - return "ConnectionHandshakeEvent{" - + "connection=" + connection - + '}'; - } } diff --git a/api/src/main/java/com/velocitypowered/api/event/connection/ConnectionHandshakeEventImpl.java b/api/src/main/java/com/velocitypowered/api/event/connection/ConnectionHandshakeEventImpl.java new file mode 100644 index 000000000..a87dbb926 --- /dev/null +++ b/api/src/main/java/com/velocitypowered/api/event/connection/ConnectionHandshakeEventImpl.java @@ -0,0 +1,34 @@ +/* + * Copyright (C) 2018 Velocity Contributors + * + * The Velocity API is licensed under the terms of the MIT License. For more details, + * reference the LICENSE file in the api top-level directory. + */ + +package com.velocitypowered.api.event.connection; + +import com.google.common.base.Preconditions; +import com.velocitypowered.api.proxy.connection.InboundConnection; + +/** + * This event is fired when a handshake is established between a client and the proxy. + */ +public final class ConnectionHandshakeEventImpl implements ConnectionHandshakeEvent { + + private final InboundConnection connection; + + public ConnectionHandshakeEventImpl(InboundConnection connection) { + this.connection = Preconditions.checkNotNull(connection, "connection"); + } + + public InboundConnection getConnection() { + return connection; + } + + @Override + public String toString() { + return "ConnectionHandshakeEvent{" + + "connection=" + connection + + '}'; + } +} 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 edf76f260..be31a0098 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,40 +7,17 @@ package com.velocitypowered.api.event.connection; -import com.google.common.base.Preconditions; 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 final class ProxyPingEvent { +public interface ProxyPingEvent { - private final InboundConnection connection; - private ServerPing ping; + InboundConnection getConnection(); - public ProxyPingEvent(InboundConnection connection, ServerPing ping) { - this.connection = Preconditions.checkNotNull(connection, "connection"); - this.ping = Preconditions.checkNotNull(ping, "ping"); - } + ServerPing getPing(); - public InboundConnection getConnection() { - return connection; - } - - public ServerPing getPing() { - return ping; - } - - public void setPing(ServerPing ping) { - this.ping = Preconditions.checkNotNull(ping, "ping"); - } - - @Override - public String toString() { - return "ProxyPingEvent{" - + "connection=" + connection - + ", ping=" + ping - + '}'; - } + void setPing(ServerPing ping); } diff --git a/api/src/main/java/com/velocitypowered/api/event/connection/ProxyPingEventImpl.java b/api/src/main/java/com/velocitypowered/api/event/connection/ProxyPingEventImpl.java new file mode 100644 index 000000000..49284e165 --- /dev/null +++ b/api/src/main/java/com/velocitypowered/api/event/connection/ProxyPingEventImpl.java @@ -0,0 +1,49 @@ +/* + * Copyright (C) 2018 Velocity Contributors + * + * The Velocity API is licensed under the terms of the MIT License. For more details, + * reference the LICENSE file in the api top-level directory. + */ + +package com.velocitypowered.api.event.connection; + +import com.google.common.base.Preconditions; +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 final class ProxyPingEventImpl implements ProxyPingEvent { + + private final InboundConnection connection; + private ServerPing ping; + + public ProxyPingEventImpl(InboundConnection connection, ServerPing ping) { + this.connection = Preconditions.checkNotNull(connection, "connection"); + this.ping = Preconditions.checkNotNull(ping, "ping"); + } + + @Override + public InboundConnection getConnection() { + return connection; + } + + @Override + public ServerPing getPing() { + return ping; + } + + @Override + public void setPing(ServerPing ping) { + this.ping = Preconditions.checkNotNull(ping, "ping"); + } + + @Override + public String toString() { + return "ProxyPingEvent{" + + "connection=" + connection + + ", ping=" + ping + + '}'; + } +} 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 daba17517..4f2b1b2c2 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,81 +7,46 @@ package com.velocitypowered.api.event.connection; -import com.google.common.base.Preconditions; 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 final class ProxyQueryEvent { - - private final QueryType queryType; - private final InetAddress querierAddress; - private QueryResponse response; - - /** - * Creates a new event. - * - * @param queryType the type of query - * @param querierAddress the remote address for the query - * @param response the current query response - */ - public ProxyQueryEvent(QueryType queryType, InetAddress querierAddress, QueryResponse response) { - this.queryType = Preconditions.checkNotNull(queryType, "queryType"); - this.querierAddress = Preconditions.checkNotNull(querierAddress, "querierAddress"); - this.response = Preconditions.checkNotNull(response, "response"); - } +public interface ProxyQueryEvent { /** * Returns the kind of query the remote client is performing. * * @return query type */ - public QueryType getQueryType() { - return queryType; - } + QueryType getQueryType(); /** * Get the address of the client that sent this query. * * @return querier address */ - public InetAddress getQuerierAddress() { - return querierAddress; - } + InetAddress getQuerierAddress(); /** * Returns the current query response. * * @return the current query response */ - public QueryResponse getResponse() { - return response; - } + QueryResponse getResponse(); /** * Sets a new query response. * * @param response the new non-null query response */ - public void setResponse(QueryResponse response) { - this.response = Preconditions.checkNotNull(response, "response"); - } - - @Override - public String toString() { - return "ProxyQueryEvent{" - + "queryType=" + queryType - + ", querierAddress=" + querierAddress - + ", response=" + response - + '}'; - } + void setResponse(QueryResponse response); /** * Represents the type of query the client is asking for. */ - public enum QueryType { + enum QueryType { /** * Basic query asks only a subset of information, such as hostname, game type (hardcoded to *
MINECRAFT
), map, current players, max players, proxy port and proxy hostname. diff --git a/api/src/main/java/com/velocitypowered/api/event/connection/ProxyQueryEventImpl.java b/api/src/main/java/com/velocitypowered/api/event/connection/ProxyQueryEventImpl.java new file mode 100644 index 000000000..7d7b23ea2 --- /dev/null +++ b/api/src/main/java/com/velocitypowered/api/event/connection/ProxyQueryEventImpl.java @@ -0,0 +1,85 @@ +/* + * Copyright (C) 2018 Velocity Contributors + * + * The Velocity API is licensed under the terms of the MIT License. For more details, + * reference the LICENSE file in the api top-level directory. + */ + +package com.velocitypowered.api.event.connection; + +import com.google.common.base.Preconditions; +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 final class ProxyQueryEventImpl implements ProxyQueryEvent { + + private final QueryType queryType; + private final InetAddress querierAddress; + private QueryResponse response; + + /** + * Creates a new event. + * + * @param queryType the type of query + * @param querierAddress the remote address for the query + * @param response the current query response + */ + public ProxyQueryEventImpl(QueryType queryType, InetAddress querierAddress, QueryResponse response) { + this.queryType = Preconditions.checkNotNull(queryType, "queryType"); + this.querierAddress = Preconditions.checkNotNull(querierAddress, "querierAddress"); + this.response = Preconditions.checkNotNull(response, "response"); + } + + /** + * Returns the kind of query the remote client is performing. + * + * @return query type + */ + @Override + public QueryType getQueryType() { + return queryType; + } + + /** + * Get the address of the client that sent this query. + * + * @return querier address + */ + @Override + public InetAddress getQuerierAddress() { + return querierAddress; + } + + /** + * Returns the current query response. + * + * @return the current query response + */ + @Override + public QueryResponse getResponse() { + return response; + } + + /** + * Sets a new query response. + * + * @param response the new non-null query response + */ + @Override + public void setResponse(QueryResponse response) { + this.response = Preconditions.checkNotNull(response, "response"); + } + + @Override + public String toString() { + return "ProxyQueryEvent{" + + "queryType=" + queryType + + ", querierAddress=" + querierAddress + + ", response=" + response + + '}'; + } + +} 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 bb4ee1aa1..046ff239a 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 @@ -11,10 +11,6 @@ package com.velocitypowered.api.event.lifecycle; * This event is fired by the proxy after plugins have been loaded but before the proxy starts * accepting connections. */ -public final class ProxyInitializeEvent { +public interface ProxyInitializeEvent { - @Override - public String toString() { - return "ProxyInitializeEvent"; - } } diff --git a/api/src/main/java/com/velocitypowered/api/event/lifecycle/ProxyInitializeEventImpl.java b/api/src/main/java/com/velocitypowered/api/event/lifecycle/ProxyInitializeEventImpl.java new file mode 100644 index 000000000..a03c85167 --- /dev/null +++ b/api/src/main/java/com/velocitypowered/api/event/lifecycle/ProxyInitializeEventImpl.java @@ -0,0 +1,20 @@ +/* + * Copyright (C) 2018 Velocity Contributors + * + * The Velocity API is licensed under the terms of the MIT License. For more details, + * reference the LICENSE file in the api top-level directory. + */ + +package com.velocitypowered.api.event.lifecycle; + +/** + * This event is fired by the proxy after plugins have been loaded but before the proxy starts + * accepting connections. + */ +public final class ProxyInitializeEventImpl implements ProxyInitializeEvent { + + @Override + public String toString() { + return "ProxyInitializeEvent"; + } +} 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 063aede14..763cee952 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 @@ -10,10 +10,6 @@ package com.velocitypowered.api.event.lifecycle; /** * This event is fired when the proxy is reloaded by the user using {@code /velocity reload}. */ -public class ProxyReloadEvent { +public interface ProxyReloadEvent { - @Override - public String toString() { - return "ProxyReloadEvent"; - } } diff --git a/api/src/main/java/com/velocitypowered/api/event/lifecycle/ProxyReloadEventImpl.java b/api/src/main/java/com/velocitypowered/api/event/lifecycle/ProxyReloadEventImpl.java new file mode 100644 index 000000000..4e79a7be4 --- /dev/null +++ b/api/src/main/java/com/velocitypowered/api/event/lifecycle/ProxyReloadEventImpl.java @@ -0,0 +1,19 @@ +/* + * Copyright (C) 2018 Velocity Contributors + * + * The Velocity API is licensed under the terms of the MIT License. For more details, + * reference the LICENSE file in the api top-level directory. + */ + +package com.velocitypowered.api.event.lifecycle; + +/** + * This event is fired when the proxy is reloaded by the user using {@code /velocity reload}. + */ +public class ProxyReloadEventImpl implements ProxyReloadEvent { + + @Override + public String toString() { + return "ProxyReloadEvent"; + } +} 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 3a540b989..cb0118907 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 @@ -11,10 +11,6 @@ package com.velocitypowered.api.event.lifecycle; * This event is fired by the proxy after the proxy has stopped accepting connections but before the * proxy process exits. */ -public final class ProxyShutdownEvent { +public interface ProxyShutdownEvent { - @Override - public String toString() { - return "ProxyShutdownEvent"; - } } diff --git a/api/src/main/java/com/velocitypowered/api/event/lifecycle/ProxyShutdownEventImpl.java b/api/src/main/java/com/velocitypowered/api/event/lifecycle/ProxyShutdownEventImpl.java new file mode 100644 index 000000000..15b35ce39 --- /dev/null +++ b/api/src/main/java/com/velocitypowered/api/event/lifecycle/ProxyShutdownEventImpl.java @@ -0,0 +1,16 @@ +/* + * Copyright (C) 2018 Velocity Contributors + * + * The Velocity API is licensed under the terms of the MIT License. For more details, + * reference the LICENSE file in the api top-level directory. + */ + +package com.velocitypowered.api.event.lifecycle; + +public final class ProxyShutdownEventImpl implements ProxyShutdownEvent { + + @Override + public String toString() { + return "ProxyShutdownEvent"; + } +} 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 2c226820f..e43fd51ed 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,37 +7,15 @@ package com.velocitypowered.api.event.lifecycle.network; -import com.google.common.base.Preconditions; import com.velocitypowered.api.network.ListenerType; -import java.net.InetSocketAddress; import java.net.SocketAddress; /** * This event is fired by the proxy after a listener starts accepting connections. */ -public final class ListenerBoundEvent { +public interface ListenerBoundEvent { - private final SocketAddress address; - private final ListenerType listenerType; + SocketAddress getAddress(); - public ListenerBoundEvent(SocketAddress address, ListenerType listenerType) { - this.address = Preconditions.checkNotNull(address, "address"); - this.listenerType = Preconditions.checkNotNull(listenerType, "listenerType"); - } - - public SocketAddress getAddress() { - return address; - } - - public ListenerType getListenerType() { - return listenerType; - } - - @Override - public String toString() { - return "ListenerBoundEvent{" - + "address=" + address - + ", listenerType=" + listenerType - + '}'; - } -} \ No newline at end of file + ListenerType getListenerType(); +} diff --git a/api/src/main/java/com/velocitypowered/api/event/lifecycle/network/ListenerBoundEventImpl.java b/api/src/main/java/com/velocitypowered/api/event/lifecycle/network/ListenerBoundEventImpl.java new file mode 100644 index 000000000..c4a498a67 --- /dev/null +++ b/api/src/main/java/com/velocitypowered/api/event/lifecycle/network/ListenerBoundEventImpl.java @@ -0,0 +1,44 @@ +/* + * Copyright (C) 2018 Velocity Contributors + * + * The Velocity API is licensed under the terms of the MIT License. For more details, + * reference the LICENSE file in the api top-level directory. + */ + +package com.velocitypowered.api.event.lifecycle.network; + +import com.google.common.base.Preconditions; +import com.velocitypowered.api.network.ListenerType; +import java.net.SocketAddress; + +/** + * This event is fired by the proxy after a listener starts accepting connections. + */ +public final class ListenerBoundEventImpl implements ListenerBoundEvent { + + private final SocketAddress address; + private final ListenerType listenerType; + + public ListenerBoundEventImpl(SocketAddress address, ListenerType listenerType) { + this.address = Preconditions.checkNotNull(address, "address"); + this.listenerType = Preconditions.checkNotNull(listenerType, "listenerType"); + } + + @Override + public SocketAddress getAddress() { + return address; + } + + @Override + public ListenerType getListenerType() { + return listenerType; + } + + @Override + public String toString() { + return "ListenerBoundEvent{" + + "address=" + address + + ", listenerType=" + listenerType + + '}'; + } +} \ No newline at end of file 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 96eeffaa4..3a607a0af 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,37 +7,15 @@ package com.velocitypowered.api.event.lifecycle.network; -import com.google.common.base.Preconditions; import com.velocitypowered.api.network.ListenerType; -import java.net.InetSocketAddress; import java.net.SocketAddress; /** * This event is fired by the proxy before the proxy stops accepting connections. */ -public final class ListenerClosedEvent { +public interface ListenerClosedEvent { - private final SocketAddress address; - private final ListenerType listenerType; + SocketAddress getAddress(); - public ListenerClosedEvent(SocketAddress address, ListenerType listenerType) { - this.address = Preconditions.checkNotNull(address, "address"); - this.listenerType = Preconditions.checkNotNull(listenerType, "listenerType"); - } - - public SocketAddress getAddress() { - return address; - } - - public ListenerType getListenerType() { - return listenerType; - } - - @Override - public String toString() { - return "ListenerCloseEvent{" - + "address=" + address - + ", listenerType=" + listenerType - + '}'; - } -} \ No newline at end of file + ListenerType getListenerType(); +} diff --git a/api/src/main/java/com/velocitypowered/api/event/lifecycle/network/ListenerClosedEventImpl.java b/api/src/main/java/com/velocitypowered/api/event/lifecycle/network/ListenerClosedEventImpl.java new file mode 100644 index 000000000..eec5f56e7 --- /dev/null +++ b/api/src/main/java/com/velocitypowered/api/event/lifecycle/network/ListenerClosedEventImpl.java @@ -0,0 +1,44 @@ +/* + * Copyright (C) 2018 Velocity Contributors + * + * The Velocity API is licensed under the terms of the MIT License. For more details, + * reference the LICENSE file in the api top-level directory. + */ + +package com.velocitypowered.api.event.lifecycle.network; + +import com.google.common.base.Preconditions; +import com.velocitypowered.api.network.ListenerType; +import java.net.SocketAddress; + +/** + * This event is fired by the proxy before the proxy stops accepting connections. + */ +public final class ListenerClosedEventImpl implements ListenerClosedEvent { + + private final SocketAddress address; + private final ListenerType listenerType; + + public ListenerClosedEventImpl(SocketAddress address, ListenerType listenerType) { + this.address = Preconditions.checkNotNull(address, "address"); + this.listenerType = Preconditions.checkNotNull(listenerType, "listenerType"); + } + + @Override + public SocketAddress getAddress() { + return address; + } + + @Override + public ListenerType getListenerType() { + return listenerType; + } + + @Override + public String toString() { + return "ListenerCloseEvent{" + + "address=" + address + + ", listenerType=" + listenerType + + '}'; + } +} \ No newline at end of file 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 99ba8c841..915e65944 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,7 +7,6 @@ package com.velocitypowered.api.event.permission; -import com.google.common.base.Preconditions; import com.velocitypowered.api.permission.PermissionFunction; import com.velocitypowered.api.permission.PermissionProvider; import com.velocitypowered.api.permission.PermissionSubject; @@ -18,20 +17,9 @@ import org.checkerframework.checker.nullness.qual.Nullable; * *

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

*/ -public final class PermissionsSetupEvent { +public interface PermissionsSetupEvent { - private final PermissionSubject subject; - private final PermissionProvider defaultProvider; - private PermissionProvider provider; - - public PermissionsSetupEvent(PermissionSubject subject, PermissionProvider provider) { - this.subject = Preconditions.checkNotNull(subject, "subject"); - this.provider = this.defaultProvider = Preconditions.checkNotNull(provider, "provider"); - } - - public PermissionSubject getSubject() { - return this.subject; - } + PermissionSubject getSubject(); /** * Uses the provider function to obtain a {@link PermissionFunction} for the subject. @@ -39,13 +27,9 @@ public final class PermissionsSetupEvent { * @param subject the subject * @return the obtained permission function */ - public PermissionFunction createFunction(PermissionSubject subject) { - return this.provider.createFunction(subject); - } + PermissionFunction createFunction(PermissionSubject subject); - public PermissionProvider getProvider() { - return this.provider; - } + PermissionProvider getProvider(); /** * Sets the {@link PermissionFunction} that should be used for the subject. @@ -55,16 +39,5 @@ public final class PermissionsSetupEvent { * * @param provider the provider */ - public void setProvider(@Nullable PermissionProvider provider) { - this.provider = provider == null ? this.defaultProvider : provider; - } - - @Override - public String toString() { - return "PermissionsSetupEvent{" - + "subject=" + subject - + ", defaultProvider=" + defaultProvider - + ", provider=" + provider - + '}'; - } + void setProvider(@Nullable PermissionProvider provider); } diff --git a/api/src/main/java/com/velocitypowered/api/event/permission/PermissionsSetupEventImpl.java b/api/src/main/java/com/velocitypowered/api/event/permission/PermissionsSetupEventImpl.java new file mode 100644 index 000000000..4921470db --- /dev/null +++ b/api/src/main/java/com/velocitypowered/api/event/permission/PermissionsSetupEventImpl.java @@ -0,0 +1,74 @@ +/* + * Copyright (C) 2018 Velocity Contributors + * + * The Velocity API is licensed under the terms of the MIT License. For more details, + * reference the LICENSE file in the api top-level directory. + */ + +package com.velocitypowered.api.event.permission; + +import com.google.common.base.Preconditions; +import com.velocitypowered.api.permission.PermissionFunction; +import com.velocitypowered.api.permission.PermissionProvider; +import com.velocitypowered.api.permission.PermissionSubject; +import org.checkerframework.checker.nullness.qual.Nullable; + +/** + * Called when a {@link PermissionSubject}'s permissions are being setup. + * + *

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

+ */ +public final class PermissionsSetupEventImpl implements PermissionsSetupEvent { + + private final PermissionSubject subject; + private final PermissionProvider defaultProvider; + private PermissionProvider provider; + + public PermissionsSetupEventImpl(PermissionSubject subject, PermissionProvider provider) { + this.subject = Preconditions.checkNotNull(subject, "subject"); + this.provider = this.defaultProvider = Preconditions.checkNotNull(provider, "provider"); + } + + @Override + public PermissionSubject getSubject() { + return this.subject; + } + + /** + * Uses the provider function to obtain a {@link PermissionFunction} for the subject. + * + * @param subject the subject + * @return the obtained permission function + */ + @Override + public PermissionFunction createFunction(PermissionSubject subject) { + return this.provider.createFunction(subject); + } + + @Override + public PermissionProvider getProvider() { + return this.provider; + } + + /** + * Sets the {@link PermissionFunction} that should be used for the subject. + * + *

Specifying null will reset the provider to the default + * instance given when the event was posted.

+ * + * @param provider the provider + */ + @Override + public void setProvider(@Nullable PermissionProvider provider) { + this.provider = provider == null ? this.defaultProvider : provider; + } + + @Override + public String toString() { + return "PermissionsSetupEvent{" + + "subject=" + subject + + ", defaultProvider=" + defaultProvider + + ", provider=" + provider + + '}'; + } +} 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 5aa6e4820..ffb49ee02 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,38 +7,13 @@ package com.velocitypowered.api.event.player; -import com.google.common.base.Preconditions; 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 final class DisconnectEvent { +public interface DisconnectEvent { - private final Player player; - private final LoginStatus loginStatus; + Player getPlayer(); - public DisconnectEvent(Player player, LoginStatus loginStatus) { - this.player = Preconditions.checkNotNull(player, "player"); - this.loginStatus = Preconditions.checkNotNull(loginStatus, "loginStatus"); - } - - public Player getPlayer() { - return player; - } - - public LoginStatus getLoginStatus() { - return loginStatus; - } - - @Override - public String toString() { - return "DisconnectEvent{" - + "player=" + player + ", " - + "loginStatus=" + loginStatus - + '}'; - } + LoginStatus getLoginStatus(); public enum LoginStatus { diff --git a/api/src/main/java/com/velocitypowered/api/event/player/DisconnectEventImpl.java b/api/src/main/java/com/velocitypowered/api/event/player/DisconnectEventImpl.java new file mode 100644 index 000000000..abfaa4d53 --- /dev/null +++ b/api/src/main/java/com/velocitypowered/api/event/player/DisconnectEventImpl.java @@ -0,0 +1,45 @@ +/* + * Copyright (C) 2018 Velocity Contributors + * + * The Velocity API is licensed under the terms of the MIT License. For more details, + * reference the LICENSE file in the api top-level directory. + */ + +package com.velocitypowered.api.event.player; + +import com.google.common.base.Preconditions; +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 final class DisconnectEventImpl implements DisconnectEvent { + + private final Player player; + private final LoginStatus loginStatus; + + public DisconnectEventImpl(Player player, LoginStatus loginStatus) { + this.player = Preconditions.checkNotNull(player, "player"); + this.loginStatus = Preconditions.checkNotNull(loginStatus, "loginStatus"); + } + + @Override + public Player getPlayer() { + return player; + } + + @Override + public LoginStatus getLoginStatus() { + return loginStatus; + } + + @Override + public String toString() { + return "DisconnectEvent{" + + "player=" + player + ", " + + "loginStatus=" + loginStatus + + '}'; + } + +} 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 065442a23..8609d91bb 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 @@ -13,7 +13,7 @@ import com.velocitypowered.api.util.GameProfile; import org.checkerframework.checker.nullness.qual.Nullable; /** - * This event is fired after the {@link PreLoginEvent} in + * 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. */ diff --git a/api/src/main/java/com/velocitypowered/api/event/player/KickedFromServerEvent.java b/api/src/main/java/com/velocitypowered/api/event/player/KickedFromServerEvent.java index 938a17ef7..2990dea11 100644 --- a/api/src/main/java/com/velocitypowered/api/event/player/KickedFromServerEvent.java +++ b/api/src/main/java/com/velocitypowered/api/event/player/KickedFromServerEvent.java @@ -13,7 +13,6 @@ import com.velocitypowered.api.proxy.connection.Player; import com.velocitypowered.api.proxy.server.RegisteredServer; import java.util.Optional; import net.kyori.adventure.text.Component; -import org.checkerframework.checker.nullness.qual.NonNull; import org.checkerframework.checker.nullness.qual.Nullable; /** @@ -22,79 +21,38 @@ import org.checkerframework.checker.nullness.qual.Nullable; * Velocity will notify the user (if they are already connected to a server) or disconnect them * (if they are not on a server and no other servers are available). */ -public final class KickedFromServerEvent implements +public interface KickedFromServerEvent extends ResultedEvent { - private final Player player; - private final RegisteredServer server; - private final @Nullable Component originalReason; - private final boolean duringServerConnect; - private ServerKickResult result; + Player getPlayer(); - /** - * Creates a {@code KickedFromServerEvent} instance. - * @param player the player affected - * @param server the server the player disconnected from - * @param originalReason the reason for being kicked, optional - * @param duringServerConnect whether or not the player was kicked during the connection process - * @param result the initial result - */ - public KickedFromServerEvent(Player player, RegisteredServer server, - net.kyori.adventure.text.@Nullable Component originalReason, - boolean duringServerConnect, ServerKickResult result) { - this.player = Preconditions.checkNotNull(player, "player"); - this.server = Preconditions.checkNotNull(server, "server"); - this.originalReason = originalReason; - this.duringServerConnect = duringServerConnect; - this.result = Preconditions.checkNotNull(result, "result"); - } - - @Override - public ServerKickResult getResult() { - return result; - } - - @Override - public void setResult(@NonNull ServerKickResult result) { - this.result = Preconditions.checkNotNull(result, "result"); - } - - public Player getPlayer() { - return player; - } - - public RegisteredServer getServer() { - return server; - } + RegisteredServer getServer(); /** * Gets the reason the server kicked the player from the server. + * * @return the server kicked the player from the server */ - public Optional getServerKickReason() { - return Optional.ofNullable(originalReason); - } + Optional getServerKickReason(); /** * Returns whether or not the player got kicked while connecting to another server. * * @return whether or not the player got kicked */ - public boolean kickedDuringServerConnect() { - return duringServerConnect; - } + boolean kickedDuringServerConnect(); /** * Represents the base interface for {@link KickedFromServerEvent} results. */ - public interface ServerKickResult extends ResultedEvent.Result { + public interface ServerKickResult extends Result { } /** * Tells the proxy to disconnect the player with the specified reason. */ - public static final class DisconnectPlayer implements ServerKickResult { + final class DisconnectPlayer implements ServerKickResult { private final Component component; @@ -126,13 +84,13 @@ public final class KickedFromServerEvent implements * Tells the proxy to redirect the player to another server. No messages will be sent from the * proxy when this result is used. */ - public static final class RedirectPlayer implements ServerKickResult { + final class RedirectPlayer implements ServerKickResult { private final Component message; private final RegisteredServer server; private RedirectPlayer(RegisteredServer server, - net.kyori.adventure.text.@Nullable Component message) { + @Nullable Component message) { this.server = Preconditions.checkNotNull(server, "server"); this.message = message; } @@ -171,7 +129,7 @@ public final class KickedFromServerEvent implements * result to use if the player was trying to connect to a different server, otherwise it is * treated like a {@link DisconnectPlayer} result. */ - public static final class Notify implements ServerKickResult { + final class Notify implements ServerKickResult { private final Component message; diff --git a/api/src/main/java/com/velocitypowered/api/event/player/KickedFromServerEventImpl.java b/api/src/main/java/com/velocitypowered/api/event/player/KickedFromServerEventImpl.java new file mode 100644 index 000000000..49271db4b --- /dev/null +++ b/api/src/main/java/com/velocitypowered/api/event/player/KickedFromServerEventImpl.java @@ -0,0 +1,89 @@ +/* + * Copyright (C) 2018 Velocity Contributors + * + * The Velocity API is licensed under the terms of the MIT License. For more details, + * reference the LICENSE file in the api top-level directory. + */ + +package com.velocitypowered.api.event.player; + +import com.google.common.base.Preconditions; +import com.velocitypowered.api.proxy.connection.Player; +import com.velocitypowered.api.proxy.server.RegisteredServer; +import java.util.Optional; +import net.kyori.adventure.text.Component; +import org.checkerframework.checker.nullness.qual.NonNull; +import org.checkerframework.checker.nullness.qual.Nullable; + +/** + * Fired when a player is kicked from a server. You may either allow Velocity to kick the player + * (with an optional reason override) or redirect the player to a separate server. By default, + * Velocity will notify the user (if they are already connected to a server) or disconnect them + * (if they are not on a server and no other servers are available). + */ +public final class KickedFromServerEventImpl implements KickedFromServerEvent { + + private final Player player; + private final RegisteredServer server; + private final @Nullable Component originalReason; + private final boolean duringServerConnect; + private ServerKickResult result; + + /** + * Creates a {@code KickedFromServerEvent} instance. + * @param player the player affected + * @param server the server the player disconnected from + * @param originalReason the reason for being kicked, optional + * @param duringServerConnect whether or not the player was kicked during the connection process + * @param result the initial result + */ + public KickedFromServerEventImpl(Player player, RegisteredServer server, + net.kyori.adventure.text.@Nullable Component originalReason, + boolean duringServerConnect, ServerKickResult result) { + this.player = Preconditions.checkNotNull(player, "player"); + this.server = Preconditions.checkNotNull(server, "server"); + this.originalReason = originalReason; + this.duringServerConnect = duringServerConnect; + this.result = Preconditions.checkNotNull(result, "result"); + } + + @Override + public ServerKickResult getResult() { + return result; + } + + @Override + public void setResult(@NonNull ServerKickResult result) { + this.result = Preconditions.checkNotNull(result, "result"); + } + + @Override + public Player getPlayer() { + return player; + } + + @Override + public RegisteredServer getServer() { + return server; + } + + /** + * Gets the reason the server kicked the player from the server. + * @return the server kicked the player from the server + */ + @Override + public Optional getServerKickReason() { + return Optional.ofNullable(originalReason); + } + + /** + * Returns whether or not the player got kicked while connecting to another server. + * + * @return whether or not the player got kicked + */ + @Override + public boolean kickedDuringServerConnect() { + return duringServerConnect; + } + +} diff --git a/api/src/main/java/com/velocitypowered/api/event/player/LoginEvent.java b/api/src/main/java/com/velocitypowered/api/event/player/LoginEvent.java index 77b243111..6eea91911 100644 --- a/api/src/main/java/com/velocitypowered/api/event/player/LoginEvent.java +++ b/api/src/main/java/com/velocitypowered/api/event/player/LoginEvent.java @@ -7,7 +7,6 @@ package com.velocitypowered.api.event.player; -import com.google.common.base.Preconditions; import com.velocitypowered.api.event.ResultedEvent; import com.velocitypowered.api.proxy.connection.Player; @@ -15,35 +14,13 @@ import com.velocitypowered.api.proxy.connection.Player; * This event is fired once the player has been authenticated but before they connect to a server on * the proxy. */ -public final class LoginEvent implements ResultedEvent { +public interface LoginEvent extends ResultedEvent { - private final Player player; - private ComponentResult result; - - public LoginEvent(Player player) { - this.player = Preconditions.checkNotNull(player, "player"); - this.result = ComponentResult.allowed(); - } - - public Player getPlayer() { - return player; - } + Player getPlayer(); @Override - public ComponentResult getResult() { - return result; - } + ComponentResult getResult(); @Override - public void setResult(ComponentResult result) { - this.result = Preconditions.checkNotNull(result, "result"); - } - - @Override - public String toString() { - return "LoginEvent{" - + "player=" + player - + ", result=" + result - + '}'; - } + void setResult(ComponentResult result); } diff --git a/api/src/main/java/com/velocitypowered/api/event/player/LoginEventImpl.java b/api/src/main/java/com/velocitypowered/api/event/player/LoginEventImpl.java new file mode 100644 index 000000000..9daf5cef2 --- /dev/null +++ b/api/src/main/java/com/velocitypowered/api/event/player/LoginEventImpl.java @@ -0,0 +1,49 @@ +/* + * Copyright (C) 2018 Velocity Contributors + * + * The Velocity API is licensed under the terms of the MIT License. For more details, + * reference the LICENSE file in the api top-level directory. + */ + +package com.velocitypowered.api.event.player; + +import com.google.common.base.Preconditions; +import com.velocitypowered.api.proxy.connection.Player; + +/** + * This event is fired once the player has been authenticated but before they connect to a server on + * the proxy. + */ +public final class LoginEventImpl implements LoginEvent { + + private final Player player; + private ComponentResult result; + + public LoginEventImpl(Player player) { + this.player = Preconditions.checkNotNull(player, "player"); + this.result = ComponentResult.allowed(); + } + + @Override + public Player getPlayer() { + return player; + } + + @Override + public ComponentResult getResult() { + return result; + } + + @Override + public void setResult(ComponentResult result) { + this.result = Preconditions.checkNotNull(result, "result"); + } + + @Override + public String toString() { + return "LoginEvent{" + + "player=" + player + + ", result=" + result + + '}'; + } +} 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 3f979f4c6..401bba506 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,7 +7,6 @@ package com.velocitypowered.api.event.player; -import com.google.common.base.Preconditions; import com.velocitypowered.api.proxy.connection.Player; import com.velocitypowered.api.proxy.messages.ChannelIdentifier; import java.util.List; @@ -16,29 +15,9 @@ import java.util.List; * This event is fired when a client ({@link Player}) sends a plugin message through the * register channel. */ -public final class PlayerChannelRegisterEvent { +public interface PlayerChannelRegisterEvent { - private final Player player; - private final List channels; + Player getPlayer(); - public PlayerChannelRegisterEvent(Player player, List channels) { - this.player = Preconditions.checkNotNull(player, "player"); - this.channels = Preconditions.checkNotNull(channels, "channels"); - } - - public Player getPlayer() { - return player; - } - - public List getChannels() { - return channels; - } - - @Override - public String toString() { - return "PlayerChannelRegisterEvent{" - + "player=" + player - + ", channels=" + channels - + '}'; - } + List getChannels(); } diff --git a/api/src/main/java/com/velocitypowered/api/event/player/PlayerChannelRegisterEventImpl.java b/api/src/main/java/com/velocitypowered/api/event/player/PlayerChannelRegisterEventImpl.java new file mode 100644 index 000000000..3782d13e3 --- /dev/null +++ b/api/src/main/java/com/velocitypowered/api/event/player/PlayerChannelRegisterEventImpl.java @@ -0,0 +1,46 @@ +/* + * Copyright (C) 2018 Velocity Contributors + * + * The Velocity API is licensed under the terms of the MIT License. For more details, + * reference the LICENSE file in the api top-level directory. + */ + +package com.velocitypowered.api.event.player; + +import com.google.common.base.Preconditions; +import com.velocitypowered.api.proxy.connection.Player; +import com.velocitypowered.api.proxy.messages.ChannelIdentifier; +import java.util.List; + +/** + * This event is fired when a client ({@link Player}) sends a plugin message through the + * register channel. + */ +public final class PlayerChannelRegisterEventImpl implements PlayerChannelRegisterEvent { + + private final Player player; + private final List channels; + + public PlayerChannelRegisterEventImpl(Player player, List channels) { + this.player = Preconditions.checkNotNull(player, "player"); + this.channels = Preconditions.checkNotNull(channels, "channels"); + } + + @Override + public Player getPlayer() { + return player; + } + + @Override + public List getChannels() { + return channels; + } + + @Override + public String toString() { + return "PlayerChannelRegisterEvent{" + + "player=" + player + + ", channels=" + channels + + '}'; + } +} diff --git a/api/src/main/java/com/velocitypowered/api/event/player/PlayerChatEvent.java b/api/src/main/java/com/velocitypowered/api/event/player/PlayerChatEvent.java index 90f796adc..7fec00e40 100644 --- a/api/src/main/java/com/velocitypowered/api/event/player/PlayerChatEvent.java +++ b/api/src/main/java/com/velocitypowered/api/event/player/PlayerChatEvent.java @@ -14,57 +14,22 @@ import java.util.Optional; import org.checkerframework.checker.nullness.qual.NonNull; import org.checkerframework.checker.nullness.qual.Nullable; -/** - * This event is fired when a player types in a chat message. - */ -public final class PlayerChatEvent implements ResultedEvent { +public interface PlayerChatEvent extends ResultedEvent { - private final Player player; - private final String message; - private ChatResult result; + Player getPlayer(); - /** - * Constructs a PlayerChatEvent. - * @param player the player sending the message - * @param message the message being sent - */ - public PlayerChatEvent(Player player, String message) { - this.player = Preconditions.checkNotNull(player, "player"); - this.message = Preconditions.checkNotNull(message, "message"); - this.result = ChatResult.allowed(); - } - - public Player getPlayer() { - return player; - } - - public String getMessage() { - return message; - } + String getMessage(); @Override - public ChatResult getResult() { - return result; - } + ChatResult getResult(); @Override - public void setResult(ChatResult result) { - this.result = Preconditions.checkNotNull(result, "result"); - } - - @Override - public String toString() { - return "PlayerChatEvent{" - + "player=" + player - + ", message=" + message - + ", result=" + result - + '}'; - } + void setResult(ChatResult result); /** * Represents the result of the {@link PlayerChatEvent}. */ - public static final class ChatResult implements ResultedEvent.Result { + final class ChatResult implements Result { private static final ChatResult ALLOWED = new ChatResult(true, null); private static final ChatResult DENIED = new ChatResult(false, null); @@ -93,6 +58,7 @@ public final class PlayerChatEvent implements ResultedEvent getInitialServer() { - return Optional.ofNullable(initialServer); - } + Optional getInitialServer(); /** * Sets the new initial server. + * * @param server the initial server the player should connect to */ - public void setInitialServer(RegisteredServer server) { - this.initialServer = server; - } - - @Override - public String toString() { - return "PlayerChooseInitialServerEvent{" - + "player=" + player - + ", initialServer=" + initialServer - + '}'; - } + void setInitialServer(RegisteredServer server); } diff --git a/api/src/main/java/com/velocitypowered/api/event/player/PlayerChooseInitialServerEventImpl.java b/api/src/main/java/com/velocitypowered/api/event/player/PlayerChooseInitialServerEventImpl.java new file mode 100644 index 000000000..c89e9be75 --- /dev/null +++ b/api/src/main/java/com/velocitypowered/api/event/player/PlayerChooseInitialServerEventImpl.java @@ -0,0 +1,61 @@ +/* + * Copyright (C) 2018 Velocity Contributors + * + * The Velocity API is licensed under the terms of the MIT License. For more details, + * reference the LICENSE file in the api top-level directory. + */ + +package com.velocitypowered.api.event.player; + +import com.google.common.base.Preconditions; +import com.velocitypowered.api.proxy.connection.Player; +import com.velocitypowered.api.proxy.server.RegisteredServer; +import java.util.Optional; +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 class PlayerChooseInitialServerEventImpl implements PlayerChooseInitialServerEvent { + + private final Player player; + private @Nullable RegisteredServer initialServer; + + /** + * Constructs a PlayerChooseInitialServerEvent. + * @param player the player that was connected + * @param initialServer the initial server selected, may be {@code null} + */ + public PlayerChooseInitialServerEventImpl(Player player, @Nullable RegisteredServer initialServer) { + this.player = Preconditions.checkNotNull(player, "player"); + this.initialServer = initialServer; + } + + @Override + public Player getPlayer() { + return player; + } + + @Override + public Optional getInitialServer() { + return Optional.ofNullable(initialServer); + } + + /** + * Sets the new initial server. + * @param server the initial server the player should connect to + */ + @Override + public void setInitialServer(RegisteredServer server) { + this.initialServer = server; + } + + @Override + public String toString() { + return "PlayerChooseInitialServerEvent{" + + "player=" + player + + ", initialServer=" + initialServer + + '}'; + } +} 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 75afb7093..245de58f0 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,37 +7,16 @@ package com.velocitypowered.api.event.player; -import com.google.common.base.MoreObjects; -import com.google.common.base.Preconditions; import com.velocitypowered.api.proxy.connection.Player; import com.velocitypowered.api.util.ModInfo; /** - * This event is fired when a Forge client sends its mods to the proxy while connecting to a server. + * This event is fired when a modded client sends its mods to the proxy while connecting to a + * server. */ -public final class PlayerModInfoEvent { +public interface PlayerModInfoEvent { - private final Player player; - private final ModInfo modInfo; + Player getPlayer(); - public PlayerModInfoEvent(Player player, ModInfo modInfo) { - this.player = Preconditions.checkNotNull(player, "player"); - this.modInfo = Preconditions.checkNotNull(modInfo, "modInfo"); - } - - public Player getPlayer() { - return player; - } - - public ModInfo getModInfo() { - return modInfo; - } - - @Override - public String toString() { - return MoreObjects.toStringHelper(this) - .add("player", player) - .add("modInfo", modInfo) - .toString(); - } + ModInfo getModInfo(); } diff --git a/api/src/main/java/com/velocitypowered/api/event/player/PlayerModInfoEventImpl.java b/api/src/main/java/com/velocitypowered/api/event/player/PlayerModInfoEventImpl.java new file mode 100644 index 000000000..9b3db009a --- /dev/null +++ b/api/src/main/java/com/velocitypowered/api/event/player/PlayerModInfoEventImpl.java @@ -0,0 +1,42 @@ +/* + * Copyright (C) 2018 Velocity Contributors + * + * The Velocity API is licensed under the terms of the MIT License. For more details, + * reference the LICENSE file in the api top-level directory. + */ + +package com.velocitypowered.api.event.player; + +import com.google.common.base.MoreObjects; +import com.google.common.base.Preconditions; +import com.velocitypowered.api.proxy.connection.Player; +import com.velocitypowered.api.util.ModInfo; + +public final class PlayerModInfoEventImpl implements PlayerModInfoEvent { + + private final Player player; + private final ModInfo modInfo; + + public PlayerModInfoEventImpl(Player player, ModInfo modInfo) { + this.player = Preconditions.checkNotNull(player, "player"); + this.modInfo = Preconditions.checkNotNull(modInfo, "modInfo"); + } + + @Override + public Player getPlayer() { + return player; + } + + @Override + public ModInfo getModInfo() { + return modInfo; + } + + @Override + public String toString() { + return MoreObjects.toStringHelper(this) + .add("player", player) + .add("modInfo", modInfo) + .toString(); + } +} 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 2b4c5f797..e088a5786 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,53 +7,32 @@ package com.velocitypowered.api.event.player; -import com.google.common.base.Preconditions; 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 class PlayerResourcePackStatusEvent { - - private final Player player; - private final Status status; - - public PlayerResourcePackStatusEvent(Player player, Status status) { - this.player = Preconditions.checkNotNull(player, "player"); - this.status = Preconditions.checkNotNull(status, "status"); - } +public interface PlayerResourcePackStatusEvent { /** * Returns the player affected by the change in resource pack status. * * @return the player */ - public Player getPlayer() { - return player; - } + Player getPlayer(); /** * Returns the new status for the resource pack. * * @return the new status */ - public Status getStatus() { - return status; - } - - @Override - public String toString() { - return "PlayerResourcePackStatusEvent{" - + "player=" + player - + ", status=" + status - + '}'; - } + Status getStatus(); /** * Represents the possible statuses for the resource pack. */ - public enum Status { + enum Status { /** * The resource pack was applied successfully. */ diff --git a/api/src/main/java/com/velocitypowered/api/event/player/PlayerResourcePackStatusEventImpl.java b/api/src/main/java/com/velocitypowered/api/event/player/PlayerResourcePackStatusEventImpl.java new file mode 100644 index 000000000..ea4bee51f --- /dev/null +++ b/api/src/main/java/com/velocitypowered/api/event/player/PlayerResourcePackStatusEventImpl.java @@ -0,0 +1,55 @@ +/* + * Copyright (C) 2018 Velocity Contributors + * + * The Velocity API is licensed under the terms of the MIT License. For more details, + * reference the LICENSE file in the api top-level directory. + */ + +package com.velocitypowered.api.event.player; + +import com.google.common.base.Preconditions; +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 class PlayerResourcePackStatusEventImpl implements PlayerResourcePackStatusEvent { + + private final Player player; + private final Status status; + + public PlayerResourcePackStatusEventImpl(Player player, Status status) { + this.player = Preconditions.checkNotNull(player, "player"); + this.status = Preconditions.checkNotNull(status, "status"); + } + + /** + * Returns the player affected by the change in resource pack status. + * + * @return the player + */ + @Override + public Player getPlayer() { + return player; + } + + /** + * Returns the new status for the resource pack. + * + * @return the new status + */ + @Override + public Status getStatus() { + return status; + } + + @Override + public String toString() { + return "PlayerResourcePackStatusEvent{" + + "player=" + player + + ", status=" + status + + '}'; + } + +} diff --git a/api/src/main/java/com/velocitypowered/api/event/player/PlayerSettingsChangedEvent.java b/api/src/main/java/com/velocitypowered/api/event/player/PlayerSettingsChangedEvent.java index 5175c3773..8277952c3 100644 --- a/api/src/main/java/com/velocitypowered/api/event/player/PlayerSettingsChangedEvent.java +++ b/api/src/main/java/com/velocitypowered/api/event/player/PlayerSettingsChangedEvent.java @@ -7,34 +7,12 @@ package com.velocitypowered.api.event.player; -import com.google.common.base.MoreObjects; -import com.google.common.base.Preconditions; import com.velocitypowered.api.proxy.connection.Player; import com.velocitypowered.api.proxy.player.PlayerSettings; -public final class PlayerSettingsChangedEvent { +public interface PlayerSettingsChangedEvent { - private final Player player; - private final PlayerSettings playerSettings; + Player getPlayer(); - public PlayerSettingsChangedEvent(Player player, PlayerSettings playerSettings) { - this.player = Preconditions.checkNotNull(player, "player"); - this.playerSettings = Preconditions.checkNotNull(playerSettings, "playerSettings"); - } - - public Player getPlayer() { - return player; - } - - public PlayerSettings getPlayerSettings() { - return playerSettings; - } - - @Override - public String toString() { - return MoreObjects.toStringHelper(this) - .add("player", player) - .add("playerSettings", playerSettings) - .toString(); - } + PlayerSettings getPlayerSettings(); } diff --git a/api/src/main/java/com/velocitypowered/api/event/player/PlayerSettingsChangedEventImpl.java b/api/src/main/java/com/velocitypowered/api/event/player/PlayerSettingsChangedEventImpl.java new file mode 100644 index 000000000..207f3c9a1 --- /dev/null +++ b/api/src/main/java/com/velocitypowered/api/event/player/PlayerSettingsChangedEventImpl.java @@ -0,0 +1,42 @@ +/* + * Copyright (C) 2018 Velocity Contributors + * + * The Velocity API is licensed under the terms of the MIT License. For more details, + * reference the LICENSE file in the api top-level directory. + */ + +package com.velocitypowered.api.event.player; + +import com.google.common.base.MoreObjects; +import com.google.common.base.Preconditions; +import com.velocitypowered.api.proxy.connection.Player; +import com.velocitypowered.api.proxy.player.PlayerSettings; + +public final class PlayerSettingsChangedEventImpl implements PlayerSettingsChangedEvent { + + private final Player player; + private final PlayerSettings playerSettings; + + public PlayerSettingsChangedEventImpl(Player player, PlayerSettings playerSettings) { + this.player = Preconditions.checkNotNull(player, "player"); + this.playerSettings = Preconditions.checkNotNull(playerSettings, "playerSettings"); + } + + @Override + public Player getPlayer() { + return player; + } + + @Override + public PlayerSettings getPlayerSettings() { + return playerSettings; + } + + @Override + public String toString() { + return MoreObjects.toStringHelper(this) + .add("player", player) + .add("playerSettings", playerSettings) + .toString(); + } +} 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 509c5bb51..3c12c5480 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,29 +7,13 @@ package com.velocitypowered.api.event.player; -import com.google.common.base.Preconditions; 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 final class PostLoginEvent { +public interface PostLoginEvent { - private final Player player; - - public PostLoginEvent(Player player) { - this.player = Preconditions.checkNotNull(player, "player"); - } - - public Player getPlayer() { - return player; - } - - @Override - public String toString() { - return "PostLoginEvent{" - + "player=" + player - + '}'; - } + Player getPlayer(); } diff --git a/api/src/main/java/com/velocitypowered/api/event/player/PostLoginEventImpl.java b/api/src/main/java/com/velocitypowered/api/event/player/PostLoginEventImpl.java new file mode 100644 index 000000000..c627442a8 --- /dev/null +++ b/api/src/main/java/com/velocitypowered/api/event/player/PostLoginEventImpl.java @@ -0,0 +1,36 @@ +/* + * Copyright (C) 2018 Velocity Contributors + * + * The Velocity API is licensed under the terms of the MIT License. For more details, + * reference the LICENSE file in the api top-level directory. + */ + +package com.velocitypowered.api.event.player; + +import com.google.common.base.Preconditions; +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 final class PostLoginEventImpl implements PostLoginEvent { + + private final Player player; + + public PostLoginEventImpl(Player player) { + this.player = Preconditions.checkNotNull(player, "player"); + } + + @Override + public Player getPlayer() { + return player; + } + + @Override + public String toString() { + return "PostLoginEvent{" + + "player=" + player + + '}'; + } +} diff --git a/api/src/main/java/com/velocitypowered/api/event/player/PreLoginEvent.java b/api/src/main/java/com/velocitypowered/api/event/player/PreLoginEvent.java index bff5951d0..d0715bfb1 100644 --- a/api/src/main/java/com/velocitypowered/api/event/player/PreLoginEvent.java +++ b/api/src/main/java/com/velocitypowered/api/event/player/PreLoginEvent.java @@ -20,55 +20,23 @@ import org.checkerframework.checker.nullness.qual.Nullable; * authenticates the player with Mojang or before the player's proxy connection is fully established * (for offline mode). */ -public final class PreLoginEvent implements ResultedEvent { +public interface PreLoginEvent extends ResultedEvent { - private final InboundConnection connection; - private final String username; - private PreLoginComponentResult result; + InboundConnection getConnection(); - /** - * Creates a new instance. - * @param connection the connection logging into the proxy - * @param username the player's username - */ - public PreLoginEvent(InboundConnection connection, String username) { - this.connection = Preconditions.checkNotNull(connection, "connection"); - this.username = Preconditions.checkNotNull(username, "username"); - this.result = PreLoginComponentResult.allowed(); - } - - public InboundConnection getConnection() { - return connection; - } - - public String getUsername() { - return username; - } + String getUsername(); @Override - public PreLoginComponentResult getResult() { - return result; - } + PreLoginComponentResult getResult(); @Override - public void setResult(@NonNull PreLoginComponentResult result) { - this.result = Preconditions.checkNotNull(result, "result"); - } - - @Override - public String toString() { - return "PreLoginEvent{" - + "connection=" + connection - + ", username='" + username + '\'' - + ", result=" + result - + '}'; - } + void setResult(@NonNull PreLoginComponentResult result); /** * Represents an "allowed/allowed with forced online\offline mode/denied" result with a reason * allowed for denial. */ - public static final class PreLoginComponentResult implements ResultedEvent.Result { + final class PreLoginComponentResult implements Result { private static final PreLoginComponentResult ALLOWED = new PreLoginComponentResult( Result.ALLOWED, null); diff --git a/api/src/main/java/com/velocitypowered/api/event/player/PreLoginEventImpl.java b/api/src/main/java/com/velocitypowered/api/event/player/PreLoginEventImpl.java new file mode 100644 index 000000000..7888c5941 --- /dev/null +++ b/api/src/main/java/com/velocitypowered/api/event/player/PreLoginEventImpl.java @@ -0,0 +1,65 @@ +/* + * Copyright (C) 2018 Velocity Contributors + * + * The Velocity API is licensed under the terms of the MIT License. For more details, + * reference the LICENSE file in the api top-level directory. + */ + +package com.velocitypowered.api.event.player; + +import com.google.common.base.Preconditions; +import com.velocitypowered.api.proxy.connection.InboundConnection; +import org.checkerframework.checker.nullness.qual.NonNull; + +/** + * This event is fired when a player has initiated a connection with the proxy but before the proxy + * authenticates the player with Mojang or before the player's proxy connection is fully established + * (for offline mode). + */ +public final class PreLoginEventImpl implements PreLoginEvent { + + private final InboundConnection connection; + private final String username; + private PreLoginComponentResult result; + + /** + * Creates a new instance. + * @param connection the connection logging into the proxy + * @param username the player's username + */ + public PreLoginEventImpl(InboundConnection connection, String username) { + this.connection = Preconditions.checkNotNull(connection, "connection"); + this.username = Preconditions.checkNotNull(username, "username"); + this.result = PreLoginComponentResult.allowed(); + } + + @Override + public InboundConnection getConnection() { + return connection; + } + + @Override + public String getUsername() { + return username; + } + + @Override + public PreLoginComponentResult getResult() { + return result; + } + + @Override + public void setResult(@NonNull PreLoginComponentResult result) { + this.result = Preconditions.checkNotNull(result, "result"); + } + + @Override + public String toString() { + return "PreLoginEvent{" + + "connection=" + connection + + ", username='" + username + '\'' + + ", result=" + result + + '}'; + } + +} 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 caa8adb48..141bd13b4 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,53 +7,19 @@ package com.velocitypowered.api.event.player; -import com.google.common.base.Preconditions; import com.velocitypowered.api.proxy.connection.Player; import com.velocitypowered.api.proxy.server.RegisteredServer; import java.util.Optional; -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 final class ServerConnectedEvent { +public interface ServerConnectedEvent { - private final Player player; - private final RegisteredServer server; - private final @Nullable RegisteredServer previousServer; + Player getPlayer(); - /** - * Constructs a ServerConnectedEvent. - * @param player the player that was connected - * @param server the server the player was connected to - * @param previousServer the server the player was previously connected to, null if none - */ - public ServerConnectedEvent(Player player, RegisteredServer server, - @Nullable RegisteredServer previousServer) { - this.player = Preconditions.checkNotNull(player, "player"); - this.server = Preconditions.checkNotNull(server, "server"); - this.previousServer = previousServer; - } + RegisteredServer getServer(); - public Player getPlayer() { - return player; - } - - public RegisteredServer getServer() { - return server; - } - - public Optional getPreviousServer() { - return Optional.ofNullable(previousServer); - } - - @Override - public String toString() { - return "ServerConnectedEvent{" - + "player=" + player - + ", server=" + server - + ", previousServer=" + previousServer - + '}'; - } + Optional getPreviousServer(); } diff --git a/api/src/main/java/com/velocitypowered/api/event/player/ServerConnectedEventImpl.java b/api/src/main/java/com/velocitypowered/api/event/player/ServerConnectedEventImpl.java new file mode 100644 index 000000000..0c7a3cc2a --- /dev/null +++ b/api/src/main/java/com/velocitypowered/api/event/player/ServerConnectedEventImpl.java @@ -0,0 +1,62 @@ +/* + * Copyright (C) 2018 Velocity Contributors + * + * The Velocity API is licensed under the terms of the MIT License. For more details, + * reference the LICENSE file in the api top-level directory. + */ + +package com.velocitypowered.api.event.player; + +import com.google.common.base.Preconditions; +import com.velocitypowered.api.proxy.connection.Player; +import com.velocitypowered.api.proxy.server.RegisteredServer; +import java.util.Optional; +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 final class ServerConnectedEventImpl implements ServerConnectedEvent { + + private final Player player; + private final RegisteredServer server; + private final @Nullable RegisteredServer previousServer; + + /** + * Constructs a ServerConnectedEvent. + * @param player the player that was connected + * @param server the server the player was connected to + * @param previousServer the server the player was previously connected to, null if none + */ + public ServerConnectedEventImpl(Player player, RegisteredServer server, + @Nullable RegisteredServer previousServer) { + this.player = Preconditions.checkNotNull(player, "player"); + this.server = Preconditions.checkNotNull(server, "server"); + this.previousServer = previousServer; + } + + @Override + public Player getPlayer() { + return player; + } + + @Override + public RegisteredServer getServer() { + return server; + } + + @Override + public Optional getPreviousServer() { + return Optional.ofNullable(previousServer); + } + + @Override + public String toString() { + return "ServerConnectedEvent{" + + "player=" + player + + ", server=" + server + + ", previousServer=" + previousServer + + '}'; + } +} 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 a831ac86c..105e28bcb 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,8 +7,6 @@ package com.velocitypowered.api.event.player; -import com.google.common.annotations.Beta; -import com.google.common.base.Preconditions; import com.velocitypowered.api.proxy.connection.Player; import com.velocitypowered.api.proxy.server.RegisteredServer; import org.checkerframework.checker.nullness.qual.Nullable; @@ -17,30 +15,9 @@ 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#getCurrentServer()}. */ -@Beta -public class ServerPostConnectEvent { - private final Player player; - private final RegisteredServer previousServer; +public interface ServerPostConnectEvent { - public ServerPostConnectEvent(Player player, - @Nullable RegisteredServer previousServer) { - this.player = Preconditions.checkNotNull(player, "player"); - this.previousServer = previousServer; - } + Player getPlayer(); - public Player getPlayer() { - return player; - } - - public @Nullable RegisteredServer getPreviousServer() { - return previousServer; - } - - @Override - public String toString() { - return "ServerPostConnectEvent{" - + "player=" + player - + ", previousServer=" + previousServer - + '}'; - } + @Nullable RegisteredServer getPreviousServer(); } diff --git a/api/src/main/java/com/velocitypowered/api/event/player/ServerPostConnectEventImpl.java b/api/src/main/java/com/velocitypowered/api/event/player/ServerPostConnectEventImpl.java new file mode 100644 index 000000000..c97f07e93 --- /dev/null +++ b/api/src/main/java/com/velocitypowered/api/event/player/ServerPostConnectEventImpl.java @@ -0,0 +1,47 @@ +/* + * Copyright (C) 2018 Velocity Contributors + * + * The Velocity API is licensed under the terms of the MIT License. For more details, + * reference the LICENSE file in the api top-level directory. + */ + +package com.velocitypowered.api.event.player; + +import com.google.common.base.Preconditions; +import com.velocitypowered.api.proxy.connection.Player; +import com.velocitypowered.api.proxy.server.RegisteredServer; +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#getCurrentServer()}. + */ +public class ServerPostConnectEventImpl implements ServerPostConnectEvent { + + private final Player player; + private final RegisteredServer previousServer; + + public ServerPostConnectEventImpl(Player player, + @Nullable RegisteredServer previousServer) { + this.player = Preconditions.checkNotNull(player, "player"); + this.previousServer = previousServer; + } + + @Override + public Player getPlayer() { + return player; + } + + @Override + public @Nullable RegisteredServer getPreviousServer() { + return previousServer; + } + + @Override + public String toString() { + return "ServerPostConnectEvent{" + + "player=" + player + + ", previousServer=" + previousServer + + '}'; + } +} diff --git a/api/src/main/java/com/velocitypowered/api/event/player/ServerPreConnectEvent.java b/api/src/main/java/com/velocitypowered/api/event/player/ServerPreConnectEvent.java index d38100b6b..0e5d0f129 100644 --- a/api/src/main/java/com/velocitypowered/api/event/player/ServerPreConnectEvent.java +++ b/api/src/main/java/com/velocitypowered/api/event/player/ServerPreConnectEvent.java @@ -19,65 +19,34 @@ import org.checkerframework.checker.nullness.qual.Nullable; /** * This event is fired before the player connects to a server. */ -public final class ServerPreConnectEvent implements - ResultedEvent { - - private final Player player; - private final RegisteredServer originalServer; - private ServerResult result; - - /** - * Creates the ServerPreConnectEvent. - * @param player the player who is connecting to a server - * @param originalServer the server the player was trying to connect to - */ - public ServerPreConnectEvent(Player player, RegisteredServer originalServer) { - this.player = Preconditions.checkNotNull(player, "player"); - this.originalServer = Preconditions.checkNotNull(originalServer, "originalServer"); - this.result = ServerResult.allowed(originalServer); - } +public interface ServerPreConnectEvent extends ResultedEvent { /** * Returns the player connecting to the server. + * * @return the player connecting to the server */ - public Player getPlayer() { - return player; - } + Player getPlayer(); @Override - public ServerResult getResult() { - return result; - } + ServerResult getResult(); @Override - public void setResult(ServerResult result) { - this.result = Preconditions.checkNotNull(result, "result"); - } + void setResult(ServerResult result); /** - * Returns the server that the player originally tried to connect to. To get the server the - * player will connect to, see the {@link ServerResult} of this event. To get the server the - * player is currently on when this event is fired, use {@link Player#getCurrentServer()}. + * Returns the server that the player originally tried to connect to. To get the server the player + * will connect to, see the {@link ServerResult} of this event. To get the server the player is + * currently on when this event is fired, use {@link Player#getCurrentServer()}. + * * @return the server that the player originally tried to connect to */ - public RegisteredServer getOriginalServer() { - return originalServer; - } - - @Override - public String toString() { - return "ServerPreConnectEvent{" - + "player=" + player - + ", originalServer=" + originalServer - + ", result=" + result - + '}'; - } + RegisteredServer getOriginalServer(); /** * Represents the result of the {@link ServerPreConnectEvent}. */ - public static class ServerResult implements ResultedEvent.Result { + class ServerResult implements Result { private static final ServerResult DENIED = new ServerResult(null); @@ -106,8 +75,9 @@ public final class ServerPreConnectEvent implements /** * Returns a result that will prevent players from connecting to another server. If this result - * is used, then {@link ConnectionRequestBuilder#connect()}'s result will have the status - * {@link Status#CONNECTION_CANCELLED}. + * is used, then {@link ConnectionRequestBuilder#connect()}'s result will have the status {@link + * Status#CONNECTION_CANCELLED}. + * * @return a result to deny conneections */ public static ServerResult denied() { @@ -116,6 +86,7 @@ public final class ServerPreConnectEvent implements /** * Allows the player to connect to the specified server. + * * @param server the new server to connect to * @return a result to allow the player to connect to the specified server */ diff --git a/api/src/main/java/com/velocitypowered/api/event/player/ServerPreConnectEventImpl.java b/api/src/main/java/com/velocitypowered/api/event/player/ServerPreConnectEventImpl.java new file mode 100644 index 000000000..a1ea14512 --- /dev/null +++ b/api/src/main/java/com/velocitypowered/api/event/player/ServerPreConnectEventImpl.java @@ -0,0 +1,73 @@ +/* + * Copyright (C) 2018 Velocity Contributors + * + * The Velocity API is licensed under the terms of the MIT License. For more details, + * reference the LICENSE file in the api top-level directory. + */ + +package com.velocitypowered.api.event.player; + +import com.google.common.base.Preconditions; +import com.velocitypowered.api.proxy.connection.Player; +import com.velocitypowered.api.proxy.server.RegisteredServer; + +/** + * This event is fired before the player connects to a server. + */ +public final class ServerPreConnectEventImpl implements ServerPreConnectEvent { + + private final Player player; + private final RegisteredServer originalServer; + private ServerResult result; + + /** + * Creates the ServerPreConnectEvent. + * @param player the player who is connecting to a server + * @param originalServer the server the player was trying to connect to + */ + public ServerPreConnectEventImpl(Player player, RegisteredServer originalServer) { + this.player = Preconditions.checkNotNull(player, "player"); + this.originalServer = Preconditions.checkNotNull(originalServer, "originalServer"); + this.result = ServerResult.allowed(originalServer); + } + + /** + * Returns the player connecting to the server. + * @return the player connecting to the server + */ + @Override + public Player getPlayer() { + return player; + } + + @Override + public ServerResult getResult() { + return result; + } + + @Override + public void setResult(ServerResult result) { + this.result = Preconditions.checkNotNull(result, "result"); + } + + /** + * Returns the server that the player originally tried to connect to. To get the server the + * player will connect to, see the {@link ServerResult} of this event. To get the server the + * player is currently on when this event is fired, use {@link Player#getCurrentServer()}. + * @return the server that the player originally tried to connect to + */ + @Override + public RegisteredServer getOriginalServer() { + return originalServer; + } + + @Override + public String toString() { + return "ServerPreConnectEvent{" + + "player=" + player + + ", originalServer=" + originalServer + + ", result=" + result + + '}'; + } + +} 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 96efd694c..0871322cb 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,63 +7,33 @@ package com.velocitypowered.api.event.player; -import static com.google.common.base.Preconditions.checkNotNull; - import com.velocitypowered.api.proxy.connection.Player; -import java.util.ArrayList; 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 class TabCompleteEvent { - private final Player player; - private final String partialMessage; - private final List suggestions; - - /** - * Constructs a new TabCompleteEvent instance. - * @param player the player - * @param partialMessage the partial message - * @param suggestions the initial list of suggestions - */ - public TabCompleteEvent(Player player, String partialMessage, List suggestions) { - this.player = checkNotNull(player, "player"); - this.partialMessage = checkNotNull(partialMessage, "partialMessage"); - this.suggestions = new ArrayList<>(checkNotNull(suggestions, "suggestions")); - } +public interface TabCompleteEvent { /** * Returns the player requesting the tab completion. + * * @return the requesting player */ - public Player getPlayer() { - return player; - } + Player getPlayer(); /** * Returns the message being partially completed. + * * @return the partial message */ - public String getPartialMessage() { - return partialMessage; - } + String getPartialMessage(); /** * Returns all the suggestions provided to the user, as a mutable list. + * * @return the suggestions */ - public List getSuggestions() { - return suggestions; - } - - @Override - public String toString() { - return "TabCompleteEvent{" - + "player=" + player - + ", partialMessage='" + partialMessage + '\'' - + ", suggestions=" + suggestions - + '}'; - } + List getSuggestions(); } diff --git a/api/src/main/java/com/velocitypowered/api/event/player/TabCompleteEventImpl.java b/api/src/main/java/com/velocitypowered/api/event/player/TabCompleteEventImpl.java new file mode 100644 index 000000000..5f51ca1ac --- /dev/null +++ b/api/src/main/java/com/velocitypowered/api/event/player/TabCompleteEventImpl.java @@ -0,0 +1,72 @@ +/* + * Copyright (C) 2018 Velocity Contributors + * + * The Velocity API is licensed under the terms of the MIT License. For more details, + * reference the LICENSE file in the api top-level directory. + */ + +package com.velocitypowered.api.event.player; + +import static com.google.common.base.Preconditions.checkNotNull; + +import com.velocitypowered.api.proxy.connection.Player; +import java.util.ArrayList; +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 class TabCompleteEventImpl implements TabCompleteEvent { + private final Player player; + private final String partialMessage; + private final List suggestions; + + /** + * Constructs a new TabCompleteEvent instance. + * @param player the player + * @param partialMessage the partial message + * @param suggestions the initial list of suggestions + */ + public TabCompleteEventImpl(Player player, String partialMessage, List suggestions) { + this.player = checkNotNull(player, "player"); + this.partialMessage = checkNotNull(partialMessage, "partialMessage"); + this.suggestions = new ArrayList<>(checkNotNull(suggestions, "suggestions")); + } + + /** + * Returns the player requesting the tab completion. + * @return the requesting player + */ + @Override + public Player getPlayer() { + return player; + } + + /** + * Returns the message being partially completed. + * @return the partial message + */ + @Override + public String getPartialMessage() { + return partialMessage; + } + + /** + * Returns all the suggestions provided to the user, as a mutable list. + * @return the suggestions + */ + @Override + public List getSuggestions() { + return suggestions; + } + + @Override + public String toString() { + return "TabCompleteEvent{" + + "player=" + player + + ", partialMessage='" + partialMessage + '\'' + + ", suggestions=" + suggestions + + '}'; + } +} diff --git a/api/src/main/java/com/velocitypowered/api/proxy/connection/Player.java b/api/src/main/java/com/velocitypowered/api/proxy/connection/Player.java index 95a1203e9..a1a489ed0 100644 --- a/api/src/main/java/com/velocitypowered/api/proxy/connection/Player.java +++ b/api/src/main/java/com/velocitypowered/api/proxy/connection/Player.java @@ -8,7 +8,7 @@ package com.velocitypowered.api.proxy.connection; import com.velocitypowered.api.command.CommandSource; -import com.velocitypowered.api.event.player.PlayerResourcePackStatusEvent; +import com.velocitypowered.api.event.player.PlayerResourcePackStatusEventImpl; import com.velocitypowered.api.proxy.messages.ChannelMessageSink; import com.velocitypowered.api.proxy.messages.ChannelMessageSource; import com.velocitypowered.api.proxy.player.ConnectionRequestBuilder; @@ -123,7 +123,7 @@ public interface Player extends CommandSource, Identified, InboundConnection, /** * Sends the specified resource pack from {@code url} to the user. If at all possible, send the * resource pack using {@link #sendResourcePack(String, byte[])}. To monitor the status of the - * sent resource pack, subscribe to {@link PlayerResourcePackStatusEvent}. + * sent resource pack, subscribe to {@link PlayerResourcePackStatusEventImpl}. * * @param url the URL for the resource pack */ @@ -132,7 +132,7 @@ public interface Player extends CommandSource, Identified, InboundConnection, /** * Sends the specified resource pack from {@code url} to the user, using the specified 20-byte * SHA-1 hash. To monitor the status of the sent resource pack, subscribe to - * {@link PlayerResourcePackStatusEvent}. + * {@link PlayerResourcePackStatusEventImpl}. * * @param url the URL for the resource pack * @param hash the SHA-1 hash value for the resource pack diff --git a/proxy/src/main/java/com/velocitypowered/proxy/VelocityServer.java b/proxy/src/main/java/com/velocitypowered/proxy/VelocityServer.java index f2c541428..b5866eb99 100644 --- a/proxy/src/main/java/com/velocitypowered/proxy/VelocityServer.java +++ b/proxy/src/main/java/com/velocitypowered/proxy/VelocityServer.java @@ -23,9 +23,9 @@ import com.google.common.collect.ImmutableList; import com.google.gson.Gson; import com.google.gson.GsonBuilder; import com.velocitypowered.api.event.EventManager; -import com.velocitypowered.api.event.lifecycle.ProxyInitializeEvent; -import com.velocitypowered.api.event.lifecycle.ProxyReloadEvent; -import com.velocitypowered.api.event.lifecycle.ProxyShutdownEvent; +import com.velocitypowered.api.event.lifecycle.ProxyInitializeEventImpl; +import com.velocitypowered.api.event.lifecycle.ProxyReloadEventImpl; +import com.velocitypowered.api.event.lifecycle.ProxyShutdownEventImpl; import com.velocitypowered.api.network.ProtocolVersion; import com.velocitypowered.api.plugin.PluginContainer; import com.velocitypowered.api.plugin.PluginManager; @@ -214,7 +214,7 @@ public class VelocityServer implements ProxyServer, ForwardingAudience { // Go ahead and fire the proxy initialization event. We block since plugins should have a chance // to fully initialize before we accept any connections to the server. - eventManager.fire(new ProxyInitializeEvent()).join(); + eventManager.fire(new ProxyInitializeEventImpl()).join(); // init console permissions after plugins are loaded console.setupPermissions(); @@ -390,7 +390,7 @@ public class VelocityServer implements ProxyServer, ForwardingAudience { ipAttemptLimiter = Ratelimiters.createWithMilliseconds(newConfiguration.getLoginRatelimit()); this.configuration = newConfiguration; - eventManager.fireAndForget(new ProxyReloadEvent()); + eventManager.fireAndForget(new ProxyReloadEventImpl()); return true; } @@ -441,7 +441,7 @@ public class VelocityServer implements ProxyServer, ForwardingAudience { } try { - eventManager.fire(new ProxyShutdownEvent()).get(10, TimeUnit.SECONDS); + eventManager.fire(new ProxyShutdownEventImpl()).get(10, TimeUnit.SECONDS); } catch (TimeoutException e) { timedOut = true; } catch (ExecutionException e) { diff --git a/proxy/src/main/java/com/velocitypowered/proxy/command/VelocityCommandManager.java b/proxy/src/main/java/com/velocitypowered/proxy/command/VelocityCommandManager.java index 75325a29f..5895acfb4 100644 --- a/proxy/src/main/java/com/velocitypowered/proxy/command/VelocityCommandManager.java +++ b/proxy/src/main/java/com/velocitypowered/proxy/command/VelocityCommandManager.java @@ -34,6 +34,7 @@ import com.velocitypowered.api.command.RawCommand; import com.velocitypowered.api.command.SimpleCommand; import com.velocitypowered.api.event.command.CommandExecuteEvent; import com.velocitypowered.api.event.command.CommandExecuteEvent.CommandResult; +import com.velocitypowered.api.event.command.CommandExecuteEventImpl; import com.velocitypowered.proxy.event.VelocityEventManager; import com.velocitypowered.proxy.util.BrigadierUtils; import java.util.Iterator; @@ -117,7 +118,7 @@ public class VelocityCommandManager implements CommandManager { } /** - * Fires a {@link CommandExecuteEvent}. + * Fires a {@link CommandExecuteEventImpl}. * * @param source the source to execute the command for * @param cmdLine the command to execute @@ -127,7 +128,7 @@ public class VelocityCommandManager implements CommandManager { final String cmdLine) { Preconditions.checkNotNull(source, "source"); Preconditions.checkNotNull(cmdLine, "cmdLine"); - return eventManager.fire(new CommandExecuteEvent(source, cmdLine)); + return eventManager.fire(new CommandExecuteEventImpl(source, cmdLine)); } private boolean executeImmediately0(final CommandSource source, final String cmdLine) { diff --git a/proxy/src/main/java/com/velocitypowered/proxy/connection/backend/BackendPlaySessionHandler.java b/proxy/src/main/java/com/velocitypowered/proxy/connection/backend/BackendPlaySessionHandler.java index b3dd0e715..877ca182c 100644 --- a/proxy/src/main/java/com/velocitypowered/proxy/connection/backend/BackendPlaySessionHandler.java +++ b/proxy/src/main/java/com/velocitypowered/proxy/connection/backend/BackendPlaySessionHandler.java @@ -24,7 +24,7 @@ import com.mojang.brigadier.builder.ArgumentBuilder; import com.mojang.brigadier.tree.CommandNode; import com.mojang.brigadier.tree.RootCommandNode; import com.velocitypowered.api.command.CommandSource; -import com.velocitypowered.api.event.command.PlayerAvailableCommandsEvent; +import com.velocitypowered.api.event.command.PlayerAvailableCommandsEventImpl; import com.velocitypowered.api.event.connection.PluginMessageEvent; import com.velocitypowered.api.network.ProtocolVersion; import com.velocitypowered.api.proxy.messages.ChannelIdentifier; @@ -214,7 +214,7 @@ public class BackendPlaySessionHandler implements MinecraftSessionHandler { } server.getEventManager().fire( - new PlayerAvailableCommandsEvent(serverConn.getPlayer(), rootNode)) + new PlayerAvailableCommandsEventImpl(serverConn.getPlayer(), rootNode)) .thenAcceptAsync(event -> playerConnection.write(commands), playerConnection.eventLoop()) .exceptionally((ex) -> { logger.error("Exception while handling available commands for {}", playerConnection, ex); diff --git a/proxy/src/main/java/com/velocitypowered/proxy/connection/backend/TransitionSessionHandler.java b/proxy/src/main/java/com/velocitypowered/proxy/connection/backend/TransitionSessionHandler.java index 1b29e36ec..0aad3103b 100644 --- a/proxy/src/main/java/com/velocitypowered/proxy/connection/backend/TransitionSessionHandler.java +++ b/proxy/src/main/java/com/velocitypowered/proxy/connection/backend/TransitionSessionHandler.java @@ -20,8 +20,8 @@ package com.velocitypowered.proxy.connection.backend; import static com.velocitypowered.proxy.connection.backend.BackendConnectionPhases.IN_TRANSITION; import static com.velocitypowered.proxy.connection.forge.legacy.LegacyForgeHandshakeBackendPhase.HELLO; -import com.velocitypowered.api.event.player.ServerConnectedEvent; -import com.velocitypowered.api.event.player.ServerPostConnectEvent; +import com.velocitypowered.api.event.player.ServerConnectedEventImpl; +import com.velocitypowered.api.event.player.ServerPostConnectEventImpl; import com.velocitypowered.proxy.VelocityServer; import com.velocitypowered.proxy.connection.ConnectionTypes; import com.velocitypowered.proxy.connection.MinecraftConnection; @@ -101,7 +101,7 @@ public class TransitionSessionHandler implements MinecraftSessionHandler { // The goods are in hand! We got JoinGame. Let's transition completely to the new state. smc.setAutoReading(false); server.getEventManager() - .fire(new ServerConnectedEvent(player, serverConn.getServer(), + .fire(new ServerConnectedEventImpl(player, serverConn.getServer(), existingConnection != null ? existingConnection.getServer() : null)) .thenRunAsync(() -> { // Make sure we can still transition (player might have disconnected here). @@ -132,7 +132,7 @@ public class TransitionSessionHandler implements MinecraftSessionHandler { serverConn.getPlayer().setConnectedServer(serverConn); // We're done! :) - server.getEventManager().fireAndForget(new ServerPostConnectEvent(player, + server.getEventManager().fireAndForget(new ServerPostConnectEventImpl(player, existingConnection == null ? null : existingConnection.getServer())); resultFuture.complete(ConnectionRequestResults.successful(serverConn.getServer())); }, smc.eventLoop()) diff --git a/proxy/src/main/java/com/velocitypowered/proxy/connection/client/ClientPlaySessionHandler.java b/proxy/src/main/java/com/velocitypowered/proxy/connection/client/ClientPlaySessionHandler.java index 36bfb5cbd..3f5112c4b 100644 --- a/proxy/src/main/java/com/velocitypowered/proxy/connection/client/ClientPlaySessionHandler.java +++ b/proxy/src/main/java/com/velocitypowered/proxy/connection/client/ClientPlaySessionHandler.java @@ -25,10 +25,11 @@ import static com.velocitypowered.proxy.network.PluginMessageUtil.constructChann import com.google.common.collect.ImmutableList; import com.velocitypowered.api.event.command.CommandExecuteEvent.CommandResult; import com.velocitypowered.api.event.connection.PluginMessageEvent; -import com.velocitypowered.api.event.player.PlayerChannelRegisterEvent; +import com.velocitypowered.api.event.player.PlayerChannelRegisterEventImpl; import com.velocitypowered.api.event.player.PlayerChatEvent; -import com.velocitypowered.api.event.player.PlayerResourcePackStatusEvent; -import com.velocitypowered.api.event.player.TabCompleteEvent; +import com.velocitypowered.api.event.player.PlayerChatEventImpl; +import com.velocitypowered.api.event.player.PlayerResourcePackStatusEventImpl; +import com.velocitypowered.api.event.player.TabCompleteEventImpl; import com.velocitypowered.api.network.ProtocolVersion; import com.velocitypowered.api.proxy.messages.ChannelIdentifier; import com.velocitypowered.api.proxy.messages.LegacyChannelIdentifier; @@ -173,10 +174,10 @@ public class ClientPlaySessionHandler implements MinecraftSessionHandler { return null; }); } else { - PlayerChatEvent event = new PlayerChatEvent(player, msg); + PlayerChatEvent event = new PlayerChatEventImpl(player, msg); server.getEventManager().fire(event) .thenAcceptAsync(pme -> { - PlayerChatEvent.ChatResult chatResult = pme.getResult(); + PlayerChatEventImpl.ChatResult chatResult = pme.getResult(); if (chatResult.isAllowed()) { Optional eventMsg = pme.getResult().getMessage(); if (eventMsg.isPresent()) { @@ -224,7 +225,7 @@ public class ClientPlaySessionHandler implements MinecraftSessionHandler { channelIdentifiers.add(new LegacyChannelIdentifier(channel)); } } - server.getEventManager().fireAndForget(new PlayerChannelRegisterEvent(player, + server.getEventManager().fireAndForget(new PlayerChannelRegisterEventImpl(player, ImmutableList.copyOf(channelIdentifiers))); backendConn.write(packet.retain()); } else if (PluginMessageUtil.isUnregister(packet)) { @@ -286,7 +287,7 @@ public class ClientPlaySessionHandler implements MinecraftSessionHandler { @Override public boolean handle(ServerboundResourcePackResponsePacket packet) { - server.getEventManager().fireAndForget(new PlayerResourcePackStatusEvent(player, + server.getEventManager().fireAndForget(new PlayerResourcePackStatusEventImpl(player, packet.getStatus())); return false; } @@ -576,7 +577,7 @@ public class ClientPlaySessionHandler implements MinecraftSessionHandler { for (Offer offer : response.getOffers()) { offers.add(offer.getText()); } - server.getEventManager().fire(new TabCompleteEvent(player, request.getCommand(), offers)) + server.getEventManager().fire(new TabCompleteEventImpl(player, request.getCommand(), offers)) .thenAcceptAsync(e -> { response.getOffers().clear(); for (String s : e.getSuggestions()) { diff --git a/proxy/src/main/java/com/velocitypowered/proxy/connection/client/ConnectedPlayer.java b/proxy/src/main/java/com/velocitypowered/proxy/connection/client/ConnectedPlayer.java index 8039ec4eb..9bcd6a6de 100644 --- a/proxy/src/main/java/com/velocitypowered/proxy/connection/client/ConnectedPlayer.java +++ b/proxy/src/main/java/com/velocitypowered/proxy/connection/client/ConnectedPlayer.java @@ -25,14 +25,17 @@ import com.google.common.base.Preconditions; import com.google.gson.JsonObject; import com.velocitypowered.api.event.player.DisconnectEvent; import com.velocitypowered.api.event.player.DisconnectEvent.LoginStatus; +import com.velocitypowered.api.event.player.DisconnectEventImpl; import com.velocitypowered.api.event.player.KickedFromServerEvent; import com.velocitypowered.api.event.player.KickedFromServerEvent.DisconnectPlayer; import com.velocitypowered.api.event.player.KickedFromServerEvent.Notify; import com.velocitypowered.api.event.player.KickedFromServerEvent.RedirectPlayer; import com.velocitypowered.api.event.player.KickedFromServerEvent.ServerKickResult; -import com.velocitypowered.api.event.player.PlayerModInfoEvent; -import com.velocitypowered.api.event.player.PlayerSettingsChangedEvent; +import com.velocitypowered.api.event.player.KickedFromServerEventImpl; +import com.velocitypowered.api.event.player.PlayerModInfoEventImpl; +import com.velocitypowered.api.event.player.PlayerSettingsChangedEventImpl; import com.velocitypowered.api.event.player.ServerPreConnectEvent; +import com.velocitypowered.api.event.player.ServerPreConnectEventImpl; import com.velocitypowered.api.network.ProtocolVersion; import com.velocitypowered.api.permission.PermissionFunction; import com.velocitypowered.api.permission.PermissionProvider; @@ -59,7 +62,6 @@ import com.velocitypowered.proxy.network.StateRegistry; import com.velocitypowered.proxy.network.packet.AbstractPluginMessagePacket; import com.velocitypowered.proxy.network.packet.clientbound.ClientboundChatPacket; import com.velocitypowered.proxy.network.packet.clientbound.ClientboundDisconnectPacket; -import com.velocitypowered.proxy.network.packet.clientbound.ClientboundHeaderAndFooterPacket; import com.velocitypowered.proxy.network.packet.clientbound.ClientboundKeepAlivePacket; import com.velocitypowered.proxy.network.packet.clientbound.ClientboundPluginMessagePacket; import com.velocitypowered.proxy.network.packet.clientbound.ClientboundResourcePackRequestPacket; @@ -212,7 +214,7 @@ public class ConnectedPlayer implements MinecraftConnectionAssociation, Player { void setPlayerSettings(ServerboundClientSettingsPacket settings) { ClientSettingsWrapper cs = new ClientSettingsWrapper(settings); this.settings = cs; - server.getEventManager().fireAndForget(new PlayerSettingsChangedEvent(this, cs)); + server.getEventManager().fireAndForget(new PlayerSettingsChangedEventImpl(this, cs)); } @Override @@ -222,7 +224,7 @@ public class ConnectedPlayer implements MinecraftConnectionAssociation, Player { public void setModInfo(ModInfo modInfo) { this.modInfo = modInfo; - server.getEventManager().fireAndForget(new PlayerModInfoEvent(this, modInfo)); + server.getEventManager().fireAndForget(new PlayerModInfoEventImpl(this, modInfo)); } @Override @@ -505,7 +507,7 @@ public class ConnectedPlayer implements MinecraftConnectionAssociation, Player { } result = Notify.create(friendlyReason); } - KickedFromServerEvent originalEvent = new KickedFromServerEvent(this, rs, kickReason, + KickedFromServerEvent originalEvent = new KickedFromServerEventImpl(this, rs, kickReason, !kickedFromCurrent, result); handleKickEvent(originalEvent, friendlyReason, kickedFromCurrent); } @@ -669,7 +671,7 @@ public class ConnectedPlayer implements MinecraftConnectionAssociation, Player { Optional connectedPlayer = server.getPlayer(this.getUniqueId()); server.unregisterConnection(this); - DisconnectEvent.LoginStatus status; + DisconnectEventImpl.LoginStatus status; if (connectedPlayer.isPresent()) { if (!connectedPlayer.get().getCurrentServer().isPresent()) { status = LoginStatus.PRE_SERVER_JOIN; @@ -682,7 +684,7 @@ public class ConnectedPlayer implements MinecraftConnectionAssociation, Player { LoginStatus.CANCELLED_BY_USER; } - DisconnectEvent event = new DisconnectEvent(this, status); + DisconnectEvent event = new DisconnectEventImpl(this, status); server.getEventManager().fire(event).whenComplete((val, ex) -> { if (ex == null) { this.teardownFuture.complete(null); @@ -852,7 +854,7 @@ public class ConnectedPlayer implements MinecraftConnectionAssociation, Player { return completedFuture(plainResult(initialCheck.get(), toConnect)); } - ServerPreConnectEvent event = new ServerPreConnectEvent(ConnectedPlayer.this, + ServerPreConnectEvent event = new ServerPreConnectEventImpl(ConnectedPlayer.this, toConnect); return server.getEventManager().fire(event) .thenComposeAsync(newEvent -> { diff --git a/proxy/src/main/java/com/velocitypowered/proxy/connection/client/HandshakeSessionHandler.java b/proxy/src/main/java/com/velocitypowered/proxy/connection/client/HandshakeSessionHandler.java index 07b15b3bf..bed65af85 100644 --- a/proxy/src/main/java/com/velocitypowered/proxy/connection/client/HandshakeSessionHandler.java +++ b/proxy/src/main/java/com/velocitypowered/proxy/connection/client/HandshakeSessionHandler.java @@ -19,7 +19,7 @@ package com.velocitypowered.proxy.connection.client; import com.google.common.annotations.VisibleForTesting; import com.google.common.base.Preconditions; -import com.velocitypowered.api.event.connection.ConnectionHandshakeEvent; +import com.velocitypowered.api.event.connection.ConnectionHandshakeEventImpl; import com.velocitypowered.api.network.ProtocolVersion; import com.velocitypowered.api.proxy.connection.InboundConnection; import com.velocitypowered.proxy.VelocityServer; @@ -136,7 +136,7 @@ public class HandshakeSessionHandler implements MinecraftSessionHandler { return; } - server.getEventManager().fireAndForget(new ConnectionHandshakeEvent(ic)); + server.getEventManager().fireAndForget(new ConnectionHandshakeEventImpl(ic)); connection.setSessionHandler(new LoginSessionHandler(server, connection, ic)); } diff --git a/proxy/src/main/java/com/velocitypowered/proxy/connection/client/LoginSessionHandler.java b/proxy/src/main/java/com/velocitypowered/proxy/connection/client/LoginSessionHandler.java index 635d8135e..31b1919e7 100644 --- a/proxy/src/main/java/com/velocitypowered/proxy/connection/client/LoginSessionHandler.java +++ b/proxy/src/main/java/com/velocitypowered/proxy/connection/client/LoginSessionHandler.java @@ -25,15 +25,17 @@ import static com.velocitypowered.proxy.util.EncryptionUtils.decryptRsa; import static com.velocitypowered.proxy.util.EncryptionUtils.generateServerId; import com.google.common.base.Preconditions; -import com.velocitypowered.api.event.permission.PermissionsSetupEvent; -import com.velocitypowered.api.event.player.DisconnectEvent; +import com.velocitypowered.api.event.permission.PermissionsSetupEventImpl; import com.velocitypowered.api.event.player.DisconnectEvent.LoginStatus; +import com.velocitypowered.api.event.player.DisconnectEventImpl; import com.velocitypowered.api.event.player.GameProfileRequestEvent; -import com.velocitypowered.api.event.player.LoginEvent; +import com.velocitypowered.api.event.player.LoginEventImpl; import com.velocitypowered.api.event.player.PlayerChooseInitialServerEvent; -import com.velocitypowered.api.event.player.PostLoginEvent; +import com.velocitypowered.api.event.player.PlayerChooseInitialServerEventImpl; +import com.velocitypowered.api.event.player.PostLoginEventImpl; import com.velocitypowered.api.event.player.PreLoginEvent; import com.velocitypowered.api.event.player.PreLoginEvent.PreLoginComponentResult; +import com.velocitypowered.api.event.player.PreLoginEventImpl; import com.velocitypowered.api.permission.PermissionFunction; import com.velocitypowered.api.proxy.server.RegisteredServer; import com.velocitypowered.api.util.GameProfile; @@ -176,7 +178,7 @@ public class LoginSessionHandler implements MinecraftSessionHandler { if (login == null) { throw new IllegalStateException("No ServerLogin packet received yet."); } - PreLoginEvent event = new PreLoginEvent(inbound, login.getUsername()); + PreLoginEvent event = new PreLoginEventImpl(inbound, login.getUsername()); server.getEventManager().fire(event) .thenRunAsync(() -> { if (mcConnection.isClosed()) { @@ -245,7 +247,7 @@ public class LoginSessionHandler implements MinecraftSessionHandler { logger.info("{} has connected", player); return server.getEventManager() - .fire(new PermissionsSetupEvent(player, ConnectedPlayer.DEFAULT_PERMISSIONS)) + .fire(new PermissionsSetupEventImpl(player, ConnectedPlayer.DEFAULT_PERMISSIONS)) .thenAcceptAsync(event -> { if (!mcConnection.isClosed()) { // wait for permissions to load, then set the players permission function @@ -285,11 +287,11 @@ public class LoginSessionHandler implements MinecraftSessionHandler { mcConnection.setAssociation(player); mcConnection.setState(StateRegistry.PLAY); - server.getEventManager().fire(new LoginEvent(player)) + server.getEventManager().fire(new LoginEventImpl(player)) .thenAcceptAsync(event -> { if (mcConnection.isClosed()) { // The player was disconnected - server.getEventManager().fireAndForget(new DisconnectEvent(player, + server.getEventManager().fireAndForget(new DisconnectEventImpl(player, LoginStatus.CANCELLED_BY_USER_BEFORE_COMPLETE)); return; } @@ -305,7 +307,7 @@ public class LoginSessionHandler implements MinecraftSessionHandler { } mcConnection.setSessionHandler(new InitialConnectSessionHandler(player)); - server.getEventManager().fire(new PostLoginEvent(player)) + server.getEventManager().fire(new PostLoginEventImpl(player)) .thenCompose((ignored) -> connectToInitialServer(player)) .exceptionally((ex) -> { logger.error("Exception while connecting {} to initial server", player, ex); @@ -321,7 +323,7 @@ public class LoginSessionHandler implements MinecraftSessionHandler { private CompletableFuture connectToInitialServer(ConnectedPlayer player) { Optional initialFromConfig = player.getNextServerToTry(); - PlayerChooseInitialServerEvent event = new PlayerChooseInitialServerEvent(player, + PlayerChooseInitialServerEvent event = new PlayerChooseInitialServerEventImpl(player, initialFromConfig.orElse(null)); return server.getEventManager().fire(event) diff --git a/proxy/src/main/java/com/velocitypowered/proxy/connection/client/StatusSessionHandler.java b/proxy/src/main/java/com/velocitypowered/proxy/connection/client/StatusSessionHandler.java index 9b963b4bd..58331c84d 100644 --- a/proxy/src/main/java/com/velocitypowered/proxy/connection/client/StatusSessionHandler.java +++ b/proxy/src/main/java/com/velocitypowered/proxy/connection/client/StatusSessionHandler.java @@ -19,7 +19,7 @@ package com.velocitypowered.proxy.connection.client; import com.google.common.collect.ImmutableList; import com.spotify.futures.CompletableFutures; -import com.velocitypowered.api.event.connection.ProxyPingEvent; +import com.velocitypowered.api.event.connection.ProxyPingEventImpl; import com.velocitypowered.api.network.ProtocolVersion; import com.velocitypowered.api.proxy.connection.InboundConnection; import com.velocitypowered.api.proxy.server.RegisteredServer; @@ -182,7 +182,7 @@ public class StatusSessionHandler implements MinecraftSessionHandler { } this.pingReceived = true; getInitialPing() - .thenCompose(ping -> server.getEventManager().fire(new ProxyPingEvent(inbound, ping))) + .thenCompose(ping -> server.getEventManager().fire(new ProxyPingEventImpl(inbound, ping))) .thenAcceptAsync(event -> connection.closeWith( LegacyDisconnectPacket.fromServerPing(event.getPing(), packet.getVersion())), connection.eventLoop()) @@ -207,7 +207,7 @@ public class StatusSessionHandler implements MinecraftSessionHandler { this.pingReceived = true; getInitialPing() - .thenCompose(ping -> server.getEventManager().fire(new ProxyPingEvent(inbound, ping))) + .thenCompose(ping -> server.getEventManager().fire(new ProxyPingEventImpl(inbound, ping))) .thenAcceptAsync( (event) -> { StringBuilder json = new StringBuilder(); diff --git a/proxy/src/main/java/com/velocitypowered/proxy/console/VelocityConsole.java b/proxy/src/main/java/com/velocitypowered/proxy/console/VelocityConsole.java index 0f57b6ef4..cd8df4f36 100644 --- a/proxy/src/main/java/com/velocitypowered/proxy/console/VelocityConsole.java +++ b/proxy/src/main/java/com/velocitypowered/proxy/console/VelocityConsole.java @@ -21,6 +21,7 @@ import static com.velocitypowered.api.permission.PermissionFunction.ALWAYS_TRUE; import com.velocitypowered.api.command.ConsoleCommandSource; import com.velocitypowered.api.event.permission.PermissionsSetupEvent; +import com.velocitypowered.api.event.permission.PermissionsSetupEventImpl; import com.velocitypowered.api.permission.PermissionFunction; import com.velocitypowered.api.permission.Tristate; import com.velocitypowered.proxy.VelocityServer; @@ -72,7 +73,7 @@ public final class VelocityConsole extends SimpleTerminalConsole implements Cons * Sets up permissions for the console. */ public void setupPermissions() { - PermissionsSetupEvent event = new PermissionsSetupEvent(this, s -> ALWAYS_TRUE); + PermissionsSetupEvent event = new PermissionsSetupEventImpl(this, s -> ALWAYS_TRUE); // we can safely block here, this is before any listeners fire this.permissionFunction = this.server.getEventManager().fire(event).join().createFunction(this); if (this.permissionFunction == null) { diff --git a/proxy/src/main/java/com/velocitypowered/proxy/network/ConnectionManager.java b/proxy/src/main/java/com/velocitypowered/proxy/network/ConnectionManager.java index 8c56b7c6d..62fa5e84e 100644 --- a/proxy/src/main/java/com/velocitypowered/proxy/network/ConnectionManager.java +++ b/proxy/src/main/java/com/velocitypowered/proxy/network/ConnectionManager.java @@ -21,8 +21,8 @@ import static org.asynchttpclient.Dsl.asyncHttpClient; import static org.asynchttpclient.Dsl.config; import com.google.common.base.Preconditions; -import com.velocitypowered.api.event.lifecycle.network.ListenerBoundEvent; -import com.velocitypowered.api.event.lifecycle.network.ListenerClosedEvent; +import com.velocitypowered.api.event.lifecycle.network.ListenerBoundEventImpl; +import com.velocitypowered.api.event.lifecycle.network.ListenerClosedEventImpl; import com.velocitypowered.api.network.ListenerType; import com.velocitypowered.natives.util.Natives; import com.velocitypowered.proxy.VelocityServer; @@ -136,7 +136,7 @@ public final class ConnectionManager { // Fire the proxy bound event after the socket is bound server.getEventManager().fireAndForget( - new ListenerBoundEvent(address, ListenerType.MINECRAFT)); + new ListenerBoundEventImpl(address, ListenerType.MINECRAFT)); } else { LOGGER.error("Can't bind to {}", address, future.cause()); } @@ -165,7 +165,7 @@ public final class ConnectionManager { // Fire the proxy bound event after the socket is bound server.getEventManager().fireAndForget( - new ListenerBoundEvent(address, ListenerType.QUERY)); + new ListenerBoundEventImpl(address, ListenerType.QUERY)); } else { LOGGER.error("Can't bind to {}", bootstrap.config().localAddress(), future.cause()); } @@ -203,7 +203,7 @@ public final class ConnectionManager { // Fire proxy close event to notify plugins of socket close. We block since plugins // should have a chance to be notified before the server stops accepting connections. - server.getEventManager().fire(new ListenerClosedEvent(oldBind, endpoint.getType())).join(); + server.getEventManager().fire(new ListenerClosedEventImpl(oldBind, endpoint.getType())).join(); Channel serverChannel = endpoint.getChannel(); @@ -222,7 +222,7 @@ public final class ConnectionManager { // Fire proxy close event to notify plugins of socket close. We block since plugins // should have a chance to be notified before the server stops accepting connections. - server.getEventManager().fire(new ListenerClosedEvent(address, endpoint.getType())).join(); + server.getEventManager().fire(new ListenerClosedEventImpl(address, endpoint.getType())).join(); try { LOGGER.info("Closing endpoint {}", address); diff --git a/proxy/src/main/java/com/velocitypowered/proxy/network/pipeline/GS4QueryHandler.java b/proxy/src/main/java/com/velocitypowered/proxy/network/pipeline/GS4QueryHandler.java index 026789e1d..fc33e0b11 100644 --- a/proxy/src/main/java/com/velocitypowered/proxy/network/pipeline/GS4QueryHandler.java +++ b/proxy/src/main/java/com/velocitypowered/proxy/network/pipeline/GS4QueryHandler.java @@ -23,7 +23,7 @@ import static com.velocitypowered.api.event.connection.ProxyQueryEvent.QueryType import com.google.common.cache.Cache; import com.google.common.cache.CacheBuilder; import com.google.common.collect.ImmutableSet; -import com.velocitypowered.api.event.connection.ProxyQueryEvent; +import com.velocitypowered.api.event.connection.ProxyQueryEventImpl; import com.velocitypowered.api.network.ProtocolVersion; import com.velocitypowered.api.plugin.PluginContainer; import com.velocitypowered.api.plugin.PluginDescription; @@ -151,7 +151,7 @@ public class GS4QueryHandler extends SimpleChannelInboundHandler // Call event and write response server.getEventManager() - .fire(new ProxyQueryEvent(isBasic ? BASIC : FULL, senderAddress, response)) + .fire(new ProxyQueryEventImpl(isBasic ? BASIC : FULL, senderAddress, response)) .whenCompleteAsync((event, exc) -> { // Packet header ByteBuf queryResponse = ctx.alloc().buffer();