From d0cbcf65e92ef2f0cf150887d4ca8f14f7bbabbe Mon Sep 17 00:00:00 2001 From: Andrew Steinborn Date: Sun, 19 Apr 2020 09:07:17 -0400 Subject: [PATCH] Fix some tab-complete regressions --- .../proxy/command/VelocityCommandManager.java | 9 ++++++++- .../connection/client/ClientPlaySessionHandler.java | 8 ++++---- 2 files changed, 12 insertions(+), 5 deletions(-) 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 4b85bdef6..a7742980c 100644 --- a/proxy/src/main/java/com/velocitypowered/proxy/command/VelocityCommandManager.java +++ b/proxy/src/main/java/com/velocitypowered/proxy/command/VelocityCommandManager.java @@ -167,7 +167,14 @@ public class VelocityCommandManager implements CommandManager { if (line.isEmpty()) { return new String[0]; } - return line.trim().split(" ", -1); + + String[] trimmed = line.trim().split(" ", -1); + if (line.endsWith(" ") && !line.trim().isEmpty()) { + // To work around a 1.13+ specific bug we have to inject a space at the end of the arguments + trimmed = Arrays.copyOf(trimmed, trimmed.length + 1); + trimmed[trimmed.length - 1] = ""; + } + return trimmed; } @Override 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 f68448d8c..35d149c24 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 @@ -365,12 +365,12 @@ public class ClientPlaySessionHandler implements MinecraftSessionHandler { private boolean handleCommandTabComplete(TabCompleteRequest packet) { // In 1.13+, we need to do additional work for the richer suggestions available. String command = packet.getCommand().substring(1); - int spacePos = command.indexOf(' '); - if (spacePos == -1) { - spacePos = command.length(); + int commandEndPosition = command.indexOf(' '); + if (commandEndPosition == -1) { + commandEndPosition = command.length(); } - String commandLabel = command.substring(0, spacePos); + String commandLabel = command.substring(0, commandEndPosition); if (!server.getCommandManager().hasCommand(commandLabel)) { if (player.getProtocolVersion().compareTo(MINECRAFT_1_13) < 0) { // Outstanding tab completes are recorded for use with 1.12 clients and below to provide