diff --git a/proxy/src/main/java/com/velocitypowered/proxy/VelocityServer.java b/proxy/src/main/java/com/velocitypowered/proxy/VelocityServer.java index 4f0e3616a..52a850e53 100644 --- a/proxy/src/main/java/com/velocitypowered/proxy/VelocityServer.java +++ b/proxy/src/main/java/com/velocitypowered/proxy/VelocityServer.java @@ -243,7 +243,7 @@ public class VelocityServer implements ProxyServer { logger.info("Shutting down the proxy..."); for (ConnectedPlayer player : ImmutableList.copyOf(connectionsByUuid.values())) { - player.close(TextComponent.of("Proxy shutting down.")); + player.disconnect(TextComponent.of("Proxy shutting down.")); } this.cm.shutdown(); 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 55bf24485..678a9967f 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 @@ -253,7 +253,7 @@ public class ClientPlaySessionHandler implements MinecraftSessionHandler { @Override public void exception(Throwable throwable) { - player.close(TextComponent.builder() + player.disconnect(TextComponent.builder() .content("An exception occurred in your connection: ") .color(TextColor.RED) .append(TextComponent.of(ThrowableUtils.briefDescription(throwable), TextColor.WHITE)) 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 2fecb0d98..e06cdacfa 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 @@ -411,10 +411,6 @@ public class ConnectedPlayer implements MinecraftConnectionAssociation, Player { } } - public void close(TextComponent reason) { - connection.closeWith(Disconnect.create(reason)); - } - private MinecraftConnection ensureBackendConnection() { VelocityServerConnection sc = this.connectedServer; if (sc == null) { 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 4e246ac23..b23fec1ce 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 @@ -19,8 +19,6 @@ import com.velocitypowered.proxy.VelocityServer; import com.velocitypowered.proxy.config.PlayerInfoForwarding; import com.velocitypowered.proxy.connection.MinecraftConnection; import com.velocitypowered.proxy.connection.MinecraftSessionHandler; -import com.velocitypowered.proxy.connection.VelocityConstants; -import com.velocitypowered.proxy.protocol.ProtocolConstants; import com.velocitypowered.proxy.protocol.StateRegistry; import com.velocitypowered.proxy.protocol.packet.Disconnect; import com.velocitypowered.proxy.protocol.packet.EncryptionRequest; @@ -44,8 +42,6 @@ import java.util.Arrays; import java.util.Optional; import java.util.concurrent.ThreadLocalRandom; import net.kyori.text.Component; -import net.kyori.text.TextComponent; -import net.kyori.text.format.TextColor; import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.Logger; import org.checkerframework.checker.nullness.qual.MonotonicNonNull; @@ -195,7 +191,7 @@ public class LoginSessionHandler implements MinecraftSessionHandler { if (!result.isForceOfflineMode() && (server.getConfiguration().isOnlineMode() || result .isOnlineModeAllowed())) { // Request encryption. - EncryptionRequest request = generateRequest(); + EncryptionRequest request = generateEncryptionRequest(); this.verify = Arrays.copyOf(request.getVerifyToken(), 4); inbound.write(request); } else { @@ -204,7 +200,7 @@ public class LoginSessionHandler implements MinecraftSessionHandler { }, inbound.eventLoop()); } - private EncryptionRequest generateRequest() { + private EncryptionRequest generateEncryptionRequest() { byte[] verify = new byte[4]; ThreadLocalRandom.current().nextBytes(verify); @@ -251,23 +247,22 @@ public class LoginSessionHandler implements MinecraftSessionHandler { if (reason.isPresent()) { player.disconnect(reason.get()); } else { - handleProxyLogin(player); + finishLogin(player); } }, inbound.eventLoop()); }); } - private void handleProxyLogin(ConnectedPlayer player) { + private void finishLogin(ConnectedPlayer player) { Optional toTry = player.getNextServerToTry(); if (!toTry.isPresent()) { - player.close(TextComponent.of("No available servers", TextColor.RED)); + player.disconnect(VelocityMessages.NO_AVAILABLE_SERVERS); return; } if (!server.registerConnection(player)) { - inbound.closeWith( - Disconnect.create(TextComponent.of("You are already on this proxy!", TextColor.RED))); + player.disconnect(VelocityMessages.ALREADY_CONNECTED); return; } diff --git a/proxy/src/main/java/com/velocitypowered/proxy/util/VelocityMessages.java b/proxy/src/main/java/com/velocitypowered/proxy/util/VelocityMessages.java index 9aca769d0..621003e4c 100644 --- a/proxy/src/main/java/com/velocitypowered/proxy/util/VelocityMessages.java +++ b/proxy/src/main/java/com/velocitypowered/proxy/util/VelocityMessages.java @@ -10,6 +10,10 @@ public class VelocityMessages { .of("This server only accepts connections from online-mode clients.", TextColor.RED); public static final Component NO_PROXY_BEHIND_PROXY = TextComponent .of("Running Velocity behind Velocity isn't supported.", TextColor.RED); + public static final Component NO_AVAILABLE_SERVERS = TextComponent + .of("No available servers", TextColor.RED); + public static final Component ALREADY_CONNECTED = TextComponent + .of("You are already connected to this proxy!", TextColor.RED); private VelocityMessages() { throw new AssertionError();