From e29e20b1e82cee467bf45f92780570f3e9d6dada Mon Sep 17 00:00:00 2001 From: Andrew Steinborn Date: Tue, 26 Nov 2019 13:44:21 -0500 Subject: [PATCH] Fix 1.13+ tab-complete with command but no arguments As a nice side-effect, this simplifies the tab complete code a bit. --- .../client/ClientPlaySessionHandler.java | 26 +++++-------------- 1 file changed, 7 insertions(+), 19 deletions(-) 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 9b22408b4..a1ae14faf 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 @@ -386,31 +386,19 @@ public class ClientPlaySessionHandler implements MinecraftSessionHandler { } List offers = new ArrayList<>(); - int longestLength = 0; for (String suggestion : suggestions) { offers.add(new Offer(suggestion)); - if (suggestion.length() > longestLength) { - longestLength = suggestion.length(); - } } - TabCompleteResponse resp = new TabCompleteResponse(); - resp.setTransactionId(packet.getTransactionId()); - int startPos = packet.getCommand().lastIndexOf(' ') + 1; - int length; - if (startPos == 0) { - startPos = packet.getCommand().length() + 1; - length = longestLength; - } else { - length = packet.getCommand().length() - startPos; + if (startPos > 0) { + TabCompleteResponse resp = new TabCompleteResponse(); + resp.setTransactionId(packet.getTransactionId()); + resp.setStart(startPos); + resp.setLength(packet.getCommand().length() - startPos); + resp.getOffers().addAll(offers); + player.getConnection().write(resp); } - - resp.setStart(startPos); - resp.setLength(length); - resp.getOffers().addAll(offers); - - player.getConnection().write(resp); return true; }