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 ccd5c798b..d15811de0 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 @@ -94,7 +94,7 @@ public class BackendPlaySessionHandler implements MinecraftSessionHandler { } if (PluginMessageUtil.isMCBrand(packet)) { - serverConn.getPlayer().getConnection().write(PluginMessageUtil.rewriteMCBrand(packet)); + serverConn.getPlayer().getConnection().write(PluginMessageUtil.rewriteMinecraftBrand(packet)); return true; } 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 1232fef6a..bed0f611d 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 @@ -103,11 +103,11 @@ public class VelocityServerConnection implements MinecraftConnectionAssociation, private String createBungeeForwardingAddress() { // BungeeCord IP forwarding is simply a special injection after the "address" in the handshake, // separated by \0 (the null byte). In order, you send the original host, the player's IP, their - // UUID (undashed), and if you are in online-mode, their login properties (retrieved from Mojang). - return registeredServer.getServerInfo().getAddress().getHostString() + "\0" + - proxyPlayer.getRemoteAddress().getHostString() + "\0" + - proxyPlayer.getProfile().getId() + "\0" + - GSON.toJson(proxyPlayer.getProfile().getProperties()); + // UUID (undashed), and if you are in online-mode, their login properties (from Mojang). + return registeredServer.getServerInfo().getAddress().getHostString() + "\0" + + proxyPlayer.getRemoteAddress().getHostString() + "\0" + + proxyPlayer.getProfile().getId() + "\0" + + GSON.toJson(proxyPlayer.getProfile().getProperties()); } private void startHandshake() { 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 db9a1df12..f87580847 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 @@ -182,7 +182,7 @@ public class ClientPlaySessionHandler implements MinecraftSessionHandler { clientPluginMsgChannels.removeAll(channels); backendConn.write(packet); } else if (PluginMessageUtil.isMCBrand(packet)) { - backendConn.write(PluginMessageUtil.rewriteMCBrand(packet)); + backendConn.write(PluginMessageUtil.rewriteMinecraftBrand(packet)); } else if (backendConn.isLegacyForge() && !serverConn.hasCompletedJoin()) { if (packet.getChannel().equals(ForgeConstants.FORGE_LEGACY_HANDSHAKE_CHANNEL)) { if (!player.getModInfo().isPresent()) { @@ -195,9 +195,10 @@ public class ClientPlaySessionHandler implements MinecraftSessionHandler { // Always forward the FML handshake to the remote server. backendConn.write(packet); } else { - // The client is trying to send messages too early. This is primarily caused by mods, but it's further - // aggravated by Velocity. To work around these issues, we will queue any non-FML handshake messages to - // be sent once the JoinGame packet has been received by the proxy. + // The client is trying to send messages too early. This is primarily caused by mods, but + // it's further aggravated by Velocity. To work around these issues, we will queue any + // non-FML handshake messages to be sent once the JoinGame packet has been received by the + // proxy. loginPluginMessages.add(packet); } } else { @@ -287,12 +288,12 @@ public class ClientPlaySessionHandler implements MinecraftSessionHandler { spawned = true; player.getConnection().delayedWrite(joinGame); - // We have something special to do for legacy Forge servers - during first connection the FML handshake - // will transition to complete regardless. Thus, we need to ensure that a reset packet is ALWAYS sent on - // first switch. + // We have something special to do for legacy Forge servers - during first connection the FML + // handshake will transition to complete regardless. Thus, we need to ensure that a reset + // packet is ALWAYS sent on first switch. // - // As we know that calling this branch only happens on first join, we set that if we are a Forge - // client that we must reset on the next switch. + // As we know that calling this branch only happens on first join, we set that if we are a + // Forge client that we must reset on the next switch. // // The call will handle if the player is not a Forge player appropriately. player.getConnection().setCanSendLegacyFMLResetPacket(true); @@ -306,11 +307,12 @@ public class ClientPlaySessionHandler implements MinecraftSessionHandler { // - A respawn packet with a different dimension // - Another respawn with the correct dimension // - // The two respawns with different dimensions are required, otherwise the client gets confused. + // The two respawns with different dimensions are required, otherwise the client gets + // confused. // - // Most notably, by having the client accept the join game packet, we can work around the need to perform - // entity ID rewrites, eliminating potential issues from rewriting packets and improving compatibility with - // mods. + // Most notably, by having the client accept the join game packet, we can work around the need + // to perform entity ID rewrites, eliminating potential issues from rewriting packets and + // improving compatibility with mods. player.getConnection().delayedWrite(joinGame); int tempDim = joinGame.getDimension() == 0 ? -1 : 0; player.getConnection().delayedWrite( @@ -360,12 +362,12 @@ public class ClientPlaySessionHandler implements MinecraftSessionHandler { // We only need to indicate we can send a reset packet if we complete a handshake, that is, // logged onto a Forge server. // - // The special case is if we log onto a Vanilla server as our first server, FML will treat this - // as complete and **will** need a reset packet sending at some point. We will handle this - // during initial player connection if the player is detected to be forge. + // The special case is if we log onto a Vanilla server as our first server, FML will treat + // this as complete and **will** need a reset packet sending at some point. We will handle + // this during initial player connection if the player is detected to be forge. // - // This is why we use an if statement rather than the result of VelocityServerConnection#isLegacyForge() - // because we don't want to set it false if this is a first connection to a Vanilla server. + // We do not use the result of VelocityServerConnection#isLegacyForge() directly because we + // don't want to set it false if this is a first connection to a Vanilla server. // // See LoginSessionHandler#handle for where the counterpart to this method is player.getConnection().setCanSendLegacyFMLResetPacket(true); diff --git a/proxy/src/main/java/com/velocitypowered/proxy/protocol/netty/GS4QueryHandler.java b/proxy/src/main/java/com/velocitypowered/proxy/protocol/netty/GS4QueryHandler.java index 9bcf330de..f5252078c 100644 --- a/proxy/src/main/java/com/velocitypowered/proxy/protocol/netty/GS4QueryHandler.java +++ b/proxy/src/main/java/com/velocitypowered/proxy/protocol/netty/GS4QueryHandler.java @@ -22,6 +22,7 @@ import java.util.Collection; import java.util.Collections; import java.util.Iterator; import java.util.List; +import java.util.Optional; import java.util.Set; import java.util.concurrent.ThreadLocalRandom; import java.util.concurrent.TimeUnit; @@ -174,8 +175,8 @@ public class GS4QueryHandler extends SimpleChannelInboundHandler } } catch (Exception e) { logger.warn("Error while trying to handle a query packet from {}", msg.sender(), e); - // NB: Only need to explicitly release upon exception, writing the response out will decrement the reference - // count. + // NB: Only need to explicitly release upon exception, writing the response out will decrement + // the reference count. responsePacket.release(); } } @@ -265,9 +266,8 @@ public class GS4QueryHandler extends SimpleChannelInboundHandler while (iterator.hasNext()) { QueryResponse.PluginInformation info = iterator.next(); pluginsString.append(info.getName()); - if (info.getVersion() != null) { - pluginsString.append(' ').append(info.getVersion()); - } + Optional version = info.getVersion(); + version.ifPresent(s -> pluginsString.append(' ').append(s)); if (iterator.hasNext()) { pluginsString.append(';').append(' '); } diff --git a/proxy/src/main/java/com/velocitypowered/proxy/protocol/packet/BossBar.java b/proxy/src/main/java/com/velocitypowered/proxy/protocol/packet/BossBar.java index ae7dfbac1..7b3b60a18 100644 --- a/proxy/src/main/java/com/velocitypowered/proxy/protocol/packet/BossBar.java +++ b/proxy/src/main/java/com/velocitypowered/proxy/protocol/packet/BossBar.java @@ -85,15 +85,15 @@ public class BossBar implements MinecraftPacket { @Override public String toString() { - return "BossBar{" + - "uuid=" + uuid + - ", action=" + action + - ", name='" + name + '\'' + - ", percent=" + percent + - ", color=" + color + - ", overlay=" + overlay + - ", flags=" + flags + - '}'; + return "BossBar{" + + "uuid=" + uuid + + ", action=" + action + + ", name='" + name + '\'' + + ", percent=" + percent + + ", color=" + color + + ", overlay=" + overlay + + ", flags=" + flags + + '}'; } @Override diff --git a/proxy/src/main/java/com/velocitypowered/proxy/protocol/packet/Chat.java b/proxy/src/main/java/com/velocitypowered/proxy/protocol/packet/Chat.java index 1c53be24f..bffbd1408 100644 --- a/proxy/src/main/java/com/velocitypowered/proxy/protocol/packet/Chat.java +++ b/proxy/src/main/java/com/velocitypowered/proxy/protocol/packet/Chat.java @@ -47,10 +47,10 @@ public class Chat implements MinecraftPacket { @Override public String toString() { - return "Chat{" + - "message='" + message + '\'' + - ", type=" + type + - '}'; + return "Chat{" + + "message='" + message + '\'' + + ", type=" + type + + '}'; } @Override diff --git a/proxy/src/main/java/com/velocitypowered/proxy/protocol/packet/Disconnect.java b/proxy/src/main/java/com/velocitypowered/proxy/protocol/packet/Disconnect.java index 3f433f61f..40ad1644c 100644 --- a/proxy/src/main/java/com/velocitypowered/proxy/protocol/packet/Disconnect.java +++ b/proxy/src/main/java/com/velocitypowered/proxy/protocol/packet/Disconnect.java @@ -34,9 +34,9 @@ public class Disconnect implements MinecraftPacket { @Override public String toString() { - return "Disconnect{" + - "reason='" + reason + '\'' + - '}'; + return "Disconnect{" + + "reason='" + reason + '\'' + + '}'; } @Override diff --git a/proxy/src/main/java/com/velocitypowered/proxy/protocol/packet/EncryptionRequest.java b/proxy/src/main/java/com/velocitypowered/proxy/protocol/packet/EncryptionRequest.java index a06eb4d2d..1773817ff 100644 --- a/proxy/src/main/java/com/velocitypowered/proxy/protocol/packet/EncryptionRequest.java +++ b/proxy/src/main/java/com/velocitypowered/proxy/protocol/packet/EncryptionRequest.java @@ -33,10 +33,10 @@ public class EncryptionRequest implements MinecraftPacket { @Override public String toString() { - return "EncryptionRequest{" + - "publicKey=" + Arrays.toString(publicKey) + - ", verifyToken=" + Arrays.toString(verifyToken) + - '}'; + return "EncryptionRequest{" + + "publicKey=" + Arrays.toString(publicKey) + + ", verifyToken=" + Arrays.toString(verifyToken) + + '}'; } @Override diff --git a/proxy/src/main/java/com/velocitypowered/proxy/protocol/packet/EncryptionResponse.java b/proxy/src/main/java/com/velocitypowered/proxy/protocol/packet/EncryptionResponse.java index 49ffd2d43..8ad106793 100644 --- a/proxy/src/main/java/com/velocitypowered/proxy/protocol/packet/EncryptionResponse.java +++ b/proxy/src/main/java/com/velocitypowered/proxy/protocol/packet/EncryptionResponse.java @@ -32,10 +32,10 @@ public class EncryptionResponse implements MinecraftPacket { @Override public String toString() { - return "EncryptionResponse{" + - "sharedSecret=" + Arrays.toString(sharedSecret) + - ", verifyToken=" + Arrays.toString(verifyToken) + - '}'; + return "EncryptionResponse{" + + "sharedSecret=" + Arrays.toString(sharedSecret) + + ", verifyToken=" + Arrays.toString(verifyToken) + + '}'; } @Override diff --git a/proxy/src/main/java/com/velocitypowered/proxy/protocol/packet/Handshake.java b/proxy/src/main/java/com/velocitypowered/proxy/protocol/packet/Handshake.java index db4fbcd6f..1ab85b002 100644 --- a/proxy/src/main/java/com/velocitypowered/proxy/protocol/packet/Handshake.java +++ b/proxy/src/main/java/com/velocitypowered/proxy/protocol/packet/Handshake.java @@ -47,12 +47,12 @@ public class Handshake implements MinecraftPacket { @Override public String toString() { - return "Handshake{" + - "protocolVersion=" + protocolVersion + - ", serverAddress='" + serverAddress + '\'' + - ", port=" + port + - ", nextStatus=" + nextStatus + - '}'; + return "Handshake{" + + "protocolVersion=" + protocolVersion + + ", serverAddress='" + serverAddress + '\'' + + ", port=" + port + + ", nextStatus=" + nextStatus + + '}'; } @Override diff --git a/proxy/src/main/java/com/velocitypowered/proxy/protocol/packet/JoinGame.java b/proxy/src/main/java/com/velocitypowered/proxy/protocol/packet/JoinGame.java index 7cbbd1165..3440536bb 100644 --- a/proxy/src/main/java/com/velocitypowered/proxy/protocol/packet/JoinGame.java +++ b/proxy/src/main/java/com/velocitypowered/proxy/protocol/packet/JoinGame.java @@ -78,15 +78,15 @@ public class JoinGame implements MinecraftPacket { @Override public String toString() { - return "JoinGame{" + - "entityId=" + entityId + - ", gamemode=" + gamemode + - ", dimension=" + dimension + - ", difficulty=" + difficulty + - ", maxPlayers=" + maxPlayers + - ", levelType='" + levelType + '\'' + - ", reducedDebugInfo=" + reducedDebugInfo + - '}'; + return "JoinGame{" + + "entityId=" + entityId + + ", gamemode=" + gamemode + + ", dimension=" + dimension + + ", difficulty=" + difficulty + + ", maxPlayers=" + maxPlayers + + ", levelType='" + levelType + '\'' + + ", reducedDebugInfo=" + reducedDebugInfo + + '}'; } @Override diff --git a/proxy/src/main/java/com/velocitypowered/proxy/protocol/packet/KeepAlive.java b/proxy/src/main/java/com/velocitypowered/proxy/protocol/packet/KeepAlive.java index 2d2cecab9..bb9465122 100644 --- a/proxy/src/main/java/com/velocitypowered/proxy/protocol/packet/KeepAlive.java +++ b/proxy/src/main/java/com/velocitypowered/proxy/protocol/packet/KeepAlive.java @@ -22,9 +22,9 @@ public class KeepAlive implements MinecraftPacket { @Override public String toString() { - return "KeepAlive{" + - "randomId=" + randomId + - '}'; + return "KeepAlive{" + + "randomId=" + randomId + + '}'; } @Override diff --git a/proxy/src/main/java/com/velocitypowered/proxy/protocol/packet/LegacyDisconnect.java b/proxy/src/main/java/com/velocitypowered/proxy/protocol/packet/LegacyDisconnect.java index 3f6271a69..7437199cb 100644 --- a/proxy/src/main/java/com/velocitypowered/proxy/protocol/packet/LegacyDisconnect.java +++ b/proxy/src/main/java/com/velocitypowered/proxy/protocol/packet/LegacyDisconnect.java @@ -7,10 +7,15 @@ public class LegacyDisconnect { private final String reason; - public LegacyDisconnect(String reason) { + private LegacyDisconnect(String reason) { this.reason = reason; } + /** + * Converts a legacy response into a disconnect packet. + * @param response the response to convert + * @return the disconnect packet + */ public static LegacyDisconnect fromPingResponse(LegacyPingResponse response) { String kickMessage = String.join("\0", "ยง1", diff --git a/proxy/src/main/java/com/velocitypowered/proxy/protocol/packet/LegacyPingResponse.java b/proxy/src/main/java/com/velocitypowered/proxy/protocol/packet/LegacyPingResponse.java index 917a10717..d1bd3235c 100644 --- a/proxy/src/main/java/com/velocitypowered/proxy/protocol/packet/LegacyPingResponse.java +++ b/proxy/src/main/java/com/velocitypowered/proxy/protocol/packet/LegacyPingResponse.java @@ -45,15 +45,20 @@ public class LegacyPingResponse { @Override public String toString() { - return "LegacyPingResponse{" + - "protocolVersion=" + protocolVersion + - ", serverVersion='" + serverVersion + '\'' + - ", motd='" + motd + '\'' + - ", playersOnline=" + playersOnline + - ", playersMax=" + playersMax + - '}'; + return "LegacyPingResponse{" + + "protocolVersion=" + protocolVersion + + ", serverVersion='" + serverVersion + '\'' + + ", motd='" + motd + '\'' + + ", playersOnline=" + playersOnline + + ", playersMax=" + playersMax + + '}'; } + /** + * Transforms a {@link ServerPing} into a legacy ping response. + * @param ping the response to transform + * @return the legacy ping response + */ public static LegacyPingResponse from(ServerPing ping) { return new LegacyPingResponse(ping.getVersion().getProtocol(), ping.getVersion().getName(), diff --git a/proxy/src/main/java/com/velocitypowered/proxy/protocol/packet/LoginPluginMessage.java b/proxy/src/main/java/com/velocitypowered/proxy/protocol/packet/LoginPluginMessage.java index f7ea9cd97..0ae7db44f 100644 --- a/proxy/src/main/java/com/velocitypowered/proxy/protocol/packet/LoginPluginMessage.java +++ b/proxy/src/main/java/com/velocitypowered/proxy/protocol/packet/LoginPluginMessage.java @@ -41,11 +41,11 @@ public class LoginPluginMessage implements MinecraftPacket { @Override public String toString() { - return "LoginPluginMessage{" + - "id=" + id + - ", channel='" + channel + '\'' + - ", data=" + data + - '}'; + return "LoginPluginMessage{" + + "id=" + id + + ", channel='" + channel + '\'' + + ", data=" + data + + '}'; } @Override diff --git a/proxy/src/main/java/com/velocitypowered/proxy/protocol/packet/LoginPluginResponse.java b/proxy/src/main/java/com/velocitypowered/proxy/protocol/packet/LoginPluginResponse.java index bcbb9a639..f2ef0fb64 100644 --- a/proxy/src/main/java/com/velocitypowered/proxy/protocol/packet/LoginPluginResponse.java +++ b/proxy/src/main/java/com/velocitypowered/proxy/protocol/packet/LoginPluginResponse.java @@ -39,11 +39,11 @@ public class LoginPluginResponse implements MinecraftPacket { @Override public String toString() { - return "LoginPluginResponse{" + - "id=" + id + - ", success=" + success + - ", data=" + data + - '}'; + return "LoginPluginResponse{" + + "id=" + id + + ", success=" + success + + ", data=" + data + + '}'; } @Override diff --git a/proxy/src/main/java/com/velocitypowered/proxy/protocol/packet/PluginMessage.java b/proxy/src/main/java/com/velocitypowered/proxy/protocol/packet/PluginMessage.java index ed594cffb..ba0940bdc 100644 --- a/proxy/src/main/java/com/velocitypowered/proxy/protocol/packet/PluginMessage.java +++ b/proxy/src/main/java/com/velocitypowered/proxy/protocol/packet/PluginMessage.java @@ -36,10 +36,10 @@ public class PluginMessage implements MinecraftPacket { @Override public String toString() { - return "PluginMessage{" + - "channel='" + channel + '\'' + - ", data=" + ByteBufUtil.hexDump(data) + - '}'; + return "PluginMessage{" + + "channel='" + channel + '\'' + + ", data=" + ByteBufUtil.hexDump(data) + + '}'; } @Override diff --git a/proxy/src/main/java/com/velocitypowered/proxy/protocol/packet/Respawn.java b/proxy/src/main/java/com/velocitypowered/proxy/protocol/packet/Respawn.java index 89383f7bf..e8b9535b5 100644 --- a/proxy/src/main/java/com/velocitypowered/proxy/protocol/packet/Respawn.java +++ b/proxy/src/main/java/com/velocitypowered/proxy/protocol/packet/Respawn.java @@ -57,12 +57,12 @@ public class Respawn implements MinecraftPacket { @Override public String toString() { - return "Respawn{" + - "dimension=" + dimension + - ", difficulty=" + difficulty + - ", gamemode=" + gamemode + - ", levelType='" + levelType + '\'' + - '}'; + return "Respawn{" + + "dimension=" + dimension + + ", difficulty=" + difficulty + + ", gamemode=" + gamemode + + ", levelType='" + levelType + '\'' + + '}'; } @Override diff --git a/proxy/src/main/java/com/velocitypowered/proxy/protocol/packet/ServerLogin.java b/proxy/src/main/java/com/velocitypowered/proxy/protocol/packet/ServerLogin.java index 7bb3a4944..e773db7f6 100644 --- a/proxy/src/main/java/com/velocitypowered/proxy/protocol/packet/ServerLogin.java +++ b/proxy/src/main/java/com/velocitypowered/proxy/protocol/packet/ServerLogin.java @@ -28,9 +28,9 @@ public class ServerLogin implements MinecraftPacket { @Override public String toString() { - return "ServerLogin{" + - "username='" + username + '\'' + - '}'; + return "ServerLogin{" + + "username='" + username + '\'' + + '}'; } @Override diff --git a/proxy/src/main/java/com/velocitypowered/proxy/protocol/packet/ServerLoginSuccess.java b/proxy/src/main/java/com/velocitypowered/proxy/protocol/packet/ServerLoginSuccess.java index 068b0d428..333ac3d58 100644 --- a/proxy/src/main/java/com/velocitypowered/proxy/protocol/packet/ServerLoginSuccess.java +++ b/proxy/src/main/java/com/velocitypowered/proxy/protocol/packet/ServerLoginSuccess.java @@ -37,10 +37,10 @@ public class ServerLoginSuccess implements MinecraftPacket { @Override public String toString() { - return "ServerLoginSuccess{" + - "uuid=" + uuid + - ", username='" + username + '\'' + - '}'; + return "ServerLoginSuccess{" + + "uuid=" + uuid + + ", username='" + username + '\'' + + '}'; } @Override diff --git a/proxy/src/main/java/com/velocitypowered/proxy/protocol/packet/SetCompression.java b/proxy/src/main/java/com/velocitypowered/proxy/protocol/packet/SetCompression.java index 7d33cae36..9f2e2c693 100644 --- a/proxy/src/main/java/com/velocitypowered/proxy/protocol/packet/SetCompression.java +++ b/proxy/src/main/java/com/velocitypowered/proxy/protocol/packet/SetCompression.java @@ -27,9 +27,9 @@ public class SetCompression implements MinecraftPacket { @Override public String toString() { - return "SetCompression{" + - "threshold=" + threshold + - '}'; + return "SetCompression{" + + "threshold=" + threshold + + '}'; } @Override diff --git a/proxy/src/main/java/com/velocitypowered/proxy/protocol/packet/StatusResponse.java b/proxy/src/main/java/com/velocitypowered/proxy/protocol/packet/StatusResponse.java index bd264eee4..1e471f884 100644 --- a/proxy/src/main/java/com/velocitypowered/proxy/protocol/packet/StatusResponse.java +++ b/proxy/src/main/java/com/velocitypowered/proxy/protocol/packet/StatusResponse.java @@ -27,9 +27,9 @@ public class StatusResponse implements MinecraftPacket { @Override public String toString() { - return "StatusResponse{" + - "status='" + status + '\'' + - '}'; + return "StatusResponse{" + + "status='" + status + '\'' + + '}'; } @Override diff --git a/proxy/src/main/java/com/velocitypowered/proxy/protocol/packet/TabCompleteRequest.java b/proxy/src/main/java/com/velocitypowered/proxy/protocol/packet/TabCompleteRequest.java index f1229d2a0..2241d32fd 100644 --- a/proxy/src/main/java/com/velocitypowered/proxy/protocol/packet/TabCompleteRequest.java +++ b/proxy/src/main/java/com/velocitypowered/proxy/protocol/packet/TabCompleteRequest.java @@ -53,12 +53,12 @@ public class TabCompleteRequest implements MinecraftPacket { @Override public String toString() { - return "TabCompleteRequest{" + - "command='" + command + '\'' + - ", assumeCommand=" + assumeCommand + - ", hasPosition=" + hasPosition + - ", position=" + position + - '}'; + return "TabCompleteRequest{" + + "command='" + command + '\'' + + ", assumeCommand=" + assumeCommand + + ", hasPosition=" + hasPosition + + ", position=" + position + + '}'; } @Override diff --git a/proxy/src/main/java/com/velocitypowered/proxy/protocol/packet/TabCompleteResponse.java b/proxy/src/main/java/com/velocitypowered/proxy/protocol/packet/TabCompleteResponse.java index 723cbdd4b..6e24fcfc8 100644 --- a/proxy/src/main/java/com/velocitypowered/proxy/protocol/packet/TabCompleteResponse.java +++ b/proxy/src/main/java/com/velocitypowered/proxy/protocol/packet/TabCompleteResponse.java @@ -18,9 +18,9 @@ public class TabCompleteResponse implements MinecraftPacket { @Override public String toString() { - return "TabCompleteResponse{" + - "offers=" + offers + - '}'; + return "TabCompleteResponse{" + + "offers=" + offers + + '}'; } @Override diff --git a/proxy/src/main/java/com/velocitypowered/proxy/protocol/packet/TitlePacket.java b/proxy/src/main/java/com/velocitypowered/proxy/protocol/packet/TitlePacket.java index d2b31c7ff..b353a27fd 100644 --- a/proxy/src/main/java/com/velocitypowered/proxy/protocol/packet/TitlePacket.java +++ b/proxy/src/main/java/com/velocitypowered/proxy/protocol/packet/TitlePacket.java @@ -141,13 +141,13 @@ public class TitlePacket implements MinecraftPacket { @Override public String toString() { - return "TitlePacket{" + - "action=" + action + - ", component='" + component + '\'' + - ", fadeIn=" + fadeIn + - ", stay=" + stay + - ", fadeOut=" + fadeOut + - '}'; + return "TitlePacket{" + + "action=" + action + + ", component='" + component + '\'' + + ", fadeIn=" + fadeIn + + ", stay=" + stay + + ", fadeOut=" + fadeOut + + '}'; } @Override diff --git a/proxy/src/main/java/com/velocitypowered/proxy/protocol/util/PluginMessageUtil.java b/proxy/src/main/java/com/velocitypowered/proxy/protocol/util/PluginMessageUtil.java index 396d3f3a6..9b38ac8d9 100644 --- a/proxy/src/main/java/com/velocitypowered/proxy/protocol/util/PluginMessageUtil.java +++ b/proxy/src/main/java/com/velocitypowered/proxy/protocol/util/PluginMessageUtil.java @@ -13,12 +13,12 @@ import java.util.List; public class PluginMessageUtil { - public static final String BRAND_CHANNEL_LEGACY = "MC|Brand"; - public static final String BRAND_CHANNEL = "minecraft:brand"; - public static final String REGISTER_CHANNEL_LEGACY = "REGISTER"; - public static final String REGISTER_CHANNEL = "minecraft:register"; - public static final String UNREGISTER_CHANNEL_LEGACY = "UNREGISTER"; - public static final String UNREGISTER_CHANNEL = "minecraft:unregister"; + private static final String BRAND_CHANNEL_LEGACY = "MC|Brand"; + private static final String BRAND_CHANNEL = "minecraft:brand"; + private static final String REGISTER_CHANNEL_LEGACY = "REGISTER"; + private static final String REGISTER_CHANNEL = "minecraft:register"; + private static final String UNREGISTER_CHANNEL_LEGACY = "UNREGISTER"; + private static final String UNREGISTER_CHANNEL = "minecraft:unregister"; private PluginMessageUtil() { throw new AssertionError(); @@ -62,7 +62,7 @@ public class PluginMessageUtil { return message; } - public static PluginMessage rewriteMCBrand(PluginMessage message) { + public static PluginMessage rewriteMinecraftBrand(PluginMessage message) { Preconditions.checkNotNull(message, "message"); Preconditions.checkArgument(isMCBrand(message), "message is not a MC Brand plugin message"); diff --git a/proxy/src/main/java/com/velocitypowered/proxy/server/ping/PingSessionHandler.java b/proxy/src/main/java/com/velocitypowered/proxy/server/PingSessionHandler.java similarity index 93% rename from proxy/src/main/java/com/velocitypowered/proxy/server/ping/PingSessionHandler.java rename to proxy/src/main/java/com/velocitypowered/proxy/server/PingSessionHandler.java index d4fad2605..2d93dc973 100644 --- a/proxy/src/main/java/com/velocitypowered/proxy/server/ping/PingSessionHandler.java +++ b/proxy/src/main/java/com/velocitypowered/proxy/server/PingSessionHandler.java @@ -1,4 +1,4 @@ -package com.velocitypowered.proxy.server.ping; +package com.velocitypowered.proxy.server; import com.velocitypowered.api.proxy.server.RegisteredServer; import com.velocitypowered.api.proxy.server.ServerPing; @@ -20,7 +20,7 @@ public class PingSessionHandler implements MinecraftSessionHandler { private final MinecraftConnection connection; private boolean completed = false; - public PingSessionHandler(CompletableFuture result, RegisteredServer server, + PingSessionHandler(CompletableFuture result, RegisteredServer server, MinecraftConnection connection) { this.result = result; this.server = server; diff --git a/proxy/src/main/java/com/velocitypowered/proxy/server/ServerMap.java b/proxy/src/main/java/com/velocitypowered/proxy/server/ServerMap.java index 19cd95ae7..7184c6df3 100644 --- a/proxy/src/main/java/com/velocitypowered/proxy/server/ServerMap.java +++ b/proxy/src/main/java/com/velocitypowered/proxy/server/ServerMap.java @@ -21,6 +21,12 @@ public class ServerMap { this.server = server; } + /** + * Returns the server associated with the given name. + * + * @param name the name to look up + * @return the server, if it exists + */ public Optional getServer(String name) { Preconditions.checkNotNull(name, "server"); String lowerName = name.toLowerCase(Locale.US); @@ -31,6 +37,12 @@ public class ServerMap { return ImmutableList.copyOf(servers.values()); } + /** + * Registers a server with the proxy. + * + * @param serverInfo the server to register + * @return the registered server + */ public RegisteredServer register(ServerInfo serverInfo) { Preconditions.checkNotNull(serverInfo, "serverInfo"); String lowerName = serverInfo.getName().toLowerCase(Locale.US); @@ -47,6 +59,11 @@ public class ServerMap { } } + /** + * Unregisters the specified server from the proxy. + * + * @param serverInfo the server to unregister + */ public void unregister(ServerInfo serverInfo) { Preconditions.checkNotNull(serverInfo, "serverInfo"); String lowerName = serverInfo.getName().toLowerCase(Locale.US); 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 9c057fc8b..d24cab559 100644 --- a/proxy/src/main/java/com/velocitypowered/proxy/server/VelocityRegisteredServer.java +++ b/proxy/src/main/java/com/velocitypowered/proxy/server/VelocityRegisteredServer.java @@ -24,7 +24,6 @@ import com.velocitypowered.proxy.protocol.netty.MinecraftDecoder; import com.velocitypowered.proxy.protocol.netty.MinecraftEncoder; import com.velocitypowered.proxy.protocol.netty.MinecraftVarintFrameDecoder; import com.velocitypowered.proxy.protocol.netty.MinecraftVarintLengthEncoder; -import com.velocitypowered.proxy.server.ping.PingSessionHandler; import io.netty.channel.Channel; import io.netty.channel.ChannelFuture; import io.netty.channel.ChannelFutureListener; diff --git a/proxy/src/main/java/com/velocitypowered/proxy/util/AddressUtil.java b/proxy/src/main/java/com/velocitypowered/proxy/util/AddressUtil.java index 9c3682a6b..06fb1cd45 100644 --- a/proxy/src/main/java/com/velocitypowered/proxy/util/AddressUtil.java +++ b/proxy/src/main/java/com/velocitypowered/proxy/util/AddressUtil.java @@ -4,9 +4,17 @@ import com.google.common.base.Preconditions; import java.net.InetSocketAddress; import java.net.URI; -public enum AddressUtil { - ; +public class AddressUtil { + private AddressUtil() { + throw new AssertionError(); + } + /** + * Attempts to parse an IP address of the form 127.0.0.1:25565. + * + * @param ip the IP to parse + * @return the parsed address + */ public static InetSocketAddress parseAddress(String ip) { Preconditions.checkNotNull(ip, "ip"); URI uri = URI.create("tcp://" + ip); diff --git a/proxy/src/main/java/com/velocitypowered/proxy/util/EncryptionUtils.java b/proxy/src/main/java/com/velocitypowered/proxy/util/EncryptionUtils.java index bf458aed4..82cc2e2a2 100644 --- a/proxy/src/main/java/com/velocitypowered/proxy/util/EncryptionUtils.java +++ b/proxy/src/main/java/com/velocitypowered/proxy/util/EncryptionUtils.java @@ -12,6 +12,12 @@ import javax.crypto.Cipher; public enum EncryptionUtils { ; + /** + * Generates an RSA key pair. + * + * @param keysize the key size (in bits) for the RSA key pair + * @return the generated key pair + */ public static KeyPair createRsaKeyPair(final int keysize) { try { final KeyPairGenerator generator = KeyPairGenerator.getInstance("RSA"); @@ -22,16 +28,37 @@ public enum EncryptionUtils { } } + /** + * Generates a hex digest in two's complement form for use with the Mojang joinedServer endpoint. + * + * @param digest the bytes to digest + * @return the hex digest + */ public static String twosComplementHexdigest(byte[] digest) { return new BigInteger(digest).toString(16); } + /** + * Decrypts an RSA message. + * + * @param keyPair the key pair to use + * @param bytes the bytes of the encrypted message + * @return the decrypted message + * @throws GeneralSecurityException if the message couldn't be decoded + */ public static byte[] decryptRsa(KeyPair keyPair, byte[] bytes) throws GeneralSecurityException { Cipher cipher = Cipher.getInstance("RSA"); cipher.init(Cipher.DECRYPT_MODE, keyPair.getPrivate()); return cipher.doFinal(bytes); } + /** + * Generates the server ID for the hasJoined endpoint. + * + * @param sharedSecret the shared secret between the client and the proxy + * @param key the RSA public key + * @return the server ID + */ public static String generateServerId(byte[] sharedSecret, PublicKey key) { try { MessageDigest digest = MessageDigest.getInstance("SHA-1"); diff --git a/proxy/src/main/java/com/velocitypowered/proxy/util/Ratelimiter.java b/proxy/src/main/java/com/velocitypowered/proxy/util/Ratelimiter.java index 670949cec..8e39133a1 100644 --- a/proxy/src/main/java/com/velocitypowered/proxy/util/Ratelimiter.java +++ b/proxy/src/main/java/com/velocitypowered/proxy/util/Ratelimiter.java @@ -8,6 +8,9 @@ import java.net.InetAddress; import java.util.concurrent.ExecutionException; import java.util.concurrent.TimeUnit; +/** + * A simple rate-limiter based on a Guava {@link Cache}. + */ public class Ratelimiter { private final Cache expiringCache; @@ -32,6 +35,12 @@ public class Ratelimiter { } } + /** + * Attempts to rate-limit the client. + * + * @param address the address to rate limit + * @return true if we should allow the client, false if we should rate-limit + */ public boolean attempt(InetAddress address) { if (timeoutNanos == 0) { return true; diff --git a/proxy/src/main/java/com/velocitypowered/proxy/util/ThrowableUtils.java b/proxy/src/main/java/com/velocitypowered/proxy/util/ThrowableUtils.java index bbc9ea9b9..b2c8e0100 100644 --- a/proxy/src/main/java/com/velocitypowered/proxy/util/ThrowableUtils.java +++ b/proxy/src/main/java/com/velocitypowered/proxy/util/ThrowableUtils.java @@ -1,7 +1,9 @@ package com.velocitypowered.proxy.util; -public enum ThrowableUtils { - ; +public class ThrowableUtils { + private ThrowableUtils() { + throw new AssertionError(); + } public static String briefDescription(Throwable throwable) { return throwable.getClass().getSimpleName() + ": " + throwable.getMessage(); diff --git a/proxy/src/main/java/com/velocitypowered/proxy/util/VelocityChannelRegistrar.java b/proxy/src/main/java/com/velocitypowered/proxy/util/VelocityChannelRegistrar.java index c48dd0a56..a5ab624b8 100644 --- a/proxy/src/main/java/com/velocitypowered/proxy/util/VelocityChannelRegistrar.java +++ b/proxy/src/main/java/com/velocitypowered/proxy/util/VelocityChannelRegistrar.java @@ -46,6 +46,11 @@ public class VelocityChannelRegistrar implements ChannelRegistrar { return ImmutableList.copyOf(identifierMap.keySet()); } + /** + * Returns all channel IDs (as strings) for use with Minecraft 1.13 and above. + * + * @return the channel IDs for Minecraft 1.13 and above + */ public Collection getModernChannelIds() { Collection ids = new ArrayList<>(); for (ChannelIdentifier value : identifierMap.values()) {