diff --git a/proxy/src/main/java/com/velocitypowered/proxy/connection/backend/BungeeCordMessageResponder.java b/proxy/src/main/java/com/velocitypowered/proxy/connection/backend/BungeeCordMessageResponder.java index 018f0ea17..678c77e8f 100644 --- a/proxy/src/main/java/com/velocitypowered/proxy/connection/backend/BungeeCordMessageResponder.java +++ b/proxy/src/main/java/com/velocitypowered/proxy/connection/backend/BungeeCordMessageResponder.java @@ -53,7 +53,7 @@ class BungeeCordMessageResponder { out.writeUTF("IP"); out.writeUTF(player.getRemoteAddress().getHostString()); out.writeInt(player.getRemoteAddress().getPort()); - sendResponse(buf); + sendResponseOnConnection(buf); } private void processPlayerCount(ByteBufDataInput in) { @@ -75,7 +75,7 @@ class BungeeCordMessageResponder { } if (buf.isReadable()) { - sendResponse(buf); + sendResponseOnConnection(buf); } else { buf.release(); } @@ -109,7 +109,7 @@ class BungeeCordMessageResponder { } if (buf.isReadable()) { - sendResponse(buf); + sendResponseOnConnection(buf); } else { buf.release(); } @@ -126,7 +126,7 @@ class BungeeCordMessageResponder { out.writeUTF("GetServers"); out.writeUTF(joiner.toString()); - sendResponse(buf); + sendResponseOnConnection(buf); } private void processMessage(ByteBufDataInput in) { @@ -150,7 +150,7 @@ class BungeeCordMessageResponder { out.writeUTF("GetServer"); out.writeUTF(player.ensureAndGetCurrentServer().getServerInfo().getName()); - sendResponse(buf); + sendResponseOnConnection(buf); } private void processUuid() { @@ -160,7 +160,7 @@ class BungeeCordMessageResponder { out.writeUTF("UUID"); out.writeUTF(UuidUtils.toUndashed(player.getUniqueId())); - sendResponse(buf); + sendResponseOnConnection(buf); } private void processUuidOther(ByteBufDataInput in) { @@ -172,7 +172,7 @@ class BungeeCordMessageResponder { out.writeUTF(player.getUsername()); out.writeUTF(UuidUtils.toUndashed(player.getUniqueId())); - sendResponse(buf); + sendResponseOnConnection(buf); }); } @@ -186,7 +186,7 @@ class BungeeCordMessageResponder { out.writeUTF(info.getServerInfo().getAddress().getHostString()); out.writeShort(info.getServerInfo().getAddress().getPort()); - sendResponse(buf); + sendResponseOnConnection(buf); }); } @@ -212,7 +212,7 @@ class BungeeCordMessageResponder { private void processForwardToPlayer(ByteBufDataInput in) { proxy.getPlayer(in.readUTF()) .flatMap(Player::getCurrentServer) - .ifPresent(server -> sendResponse(player, prepareForwardMessage(in))); + .ifPresent(server -> sendServerResponse(player, prepareForwardMessage(in))); } private void processForwardToServer(ByteBufDataInput in) { @@ -234,8 +234,8 @@ class BungeeCordMessageResponder { } // Note: this method will always release the buffer! - private void sendResponse(ByteBuf buf) { - sendResponse(this.player, buf); + private void sendResponseOnConnection(ByteBuf buf) { + sendServerResponse(this.player, buf); } static String getBungeeCordChannel(ProtocolVersion version) { @@ -244,7 +244,7 @@ class BungeeCordMessageResponder { } // Note: this method will always release the buffer! - private static void sendResponse(ConnectedPlayer player, ByteBuf buf) { + private static void sendServerResponse(ConnectedPlayer player, ByteBuf buf) { MinecraftConnection serverConnection = player.ensureAndGetCurrentServer().ensureConnected(); String chan = getBungeeCordChannel(serverConnection.getProtocolVersion()); diff --git a/proxy/src/main/java/com/velocitypowered/proxy/connection/backend/VelocityServerConnection.java b/proxy/src/main/java/com/velocitypowered/proxy/connection/backend/VelocityServerConnection.java index 9f0903469..a7cf3ed82 100644 --- a/proxy/src/main/java/com/velocitypowered/proxy/connection/backend/VelocityServerConnection.java +++ b/proxy/src/main/java/com/velocitypowered/proxy/connection/backend/VelocityServerConnection.java @@ -214,6 +214,12 @@ public class VelocityServerConnection implements MinecraftConnectionAssociation, return sendPluginMessage(identifier, Unpooled.wrappedBuffer(data)); } + /** + * Sends a plugin message to the server through this connection. + * @param identifier the channel ID to use + * @param data the data + * @return whether or not the message was sent + */ public boolean sendPluginMessage(ChannelIdentifier identifier, ByteBuf data) { Preconditions.checkNotNull(identifier, "identifier"); Preconditions.checkNotNull(data, "data"); 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 97dc93305..d90fc2054 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 @@ -135,6 +135,10 @@ public class ConnectedPlayer implements MinecraftConnectionAssociation, Player { return Optional.ofNullable(connectedServer); } + /** + * Makes sure the player is connected to a server and returns the server they are connected to. + * @return the server the player is connected to + */ public VelocityServerConnection ensureAndGetCurrentServer() { VelocityServerConnection con = this.connectedServer; if (con == null) { diff --git a/proxy/src/main/java/com/velocitypowered/proxy/server/VelocityRegisteredServer.java b/proxy/src/main/java/com/velocitypowered/proxy/server/VelocityRegisteredServer.java index e999d5e7c..dc8f1687d 100644 --- a/proxy/src/main/java/com/velocitypowered/proxy/server/VelocityRegisteredServer.java +++ b/proxy/src/main/java/com/velocitypowered/proxy/server/VelocityRegisteredServer.java @@ -126,6 +126,12 @@ public class VelocityRegisteredServer implements RegisteredServer { return sendPluginMessage(identifier, Unpooled.wrappedBuffer(data)); } + /** + * Sends a plugin message to the server through this connection. + * @param identifier the channel ID to use + * @param data the data + * @return whether or not the message was sent + */ public boolean sendPluginMessage(ChannelIdentifier identifier, ByteBuf data) { for (ConnectedPlayer player : players) { VelocityServerConnection connection = player.getConnectedServer();