From c03d7e259c02ebd598cea5dc7b183cb6b03295d9 Mon Sep 17 00:00:00 2001 From: Shane Freeder Date: Sat, 25 Jun 2022 21:38:55 +0100 Subject: [PATCH] Validate that we have a target --- .../connection/client/ClientPlaySessionHandler.java | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) 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 04bfd100e..79afe9b29 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 @@ -229,6 +229,7 @@ public class ClientPlaySessionHandler implements MinecraftSessionHandler { @Override public boolean handle(PlayerCommand packet) { + player.ensureAndGetCurrentServer(); if (!validateChat(packet.getCommand())) { return true; } @@ -246,6 +247,7 @@ public class ClientPlaySessionHandler implements MinecraftSessionHandler { @Override public boolean handle(PlayerChat packet) { + player.ensureAndGetCurrentServer(); if (!validateChat(packet.getMessage())) { return true; } @@ -270,6 +272,7 @@ public class ClientPlaySessionHandler implements MinecraftSessionHandler { @Override public boolean handle(LegacyChat packet) { + player.ensureAndGetCurrentServer(); String msg = packet.getMessage(); if (!validateChat(msg)) { return true; @@ -703,7 +706,15 @@ public class ClientPlaySessionHandler implements MinecraftSessionHandler { return CompletableFuture.completedFuture(null); } - MinecraftConnection smc = player.ensureAndGetCurrentServer().ensureConnected(); + MinecraftConnection smc; + try { + smc = player.ensureAndGetCurrentServer().ensureConnected(); + } catch (Exception ex) { + player.disconnect(Component.translatable("velocity.error.player-connection-error", + NamedTextColor.RED)); + return CompletableFuture.completedFuture(null); + } + String commandToRun = result.getCommand().orElse(originalCommand); if (result.isForwardToServer()) { ChatBuilder write = ChatBuilder