From 9f5ace9025cc28d4d1f43e0a1cd4fddd6505c4dc Mon Sep 17 00:00:00 2001 From: Outfluencer <48880402+Outfluencer@users.noreply.github.com> Date: Wed, 5 Jul 2023 19:52:43 +1000 Subject: [PATCH] #3418: Add tab completion for bungee command names in pre-1.13 versions --- .../java/net/md_5/bungee/UserConnection.java | 3 +++ .../bungee/connection/DownstreamBridge.java | 19 +++++++++++++++++++ .../bungee/connection/UpstreamBridge.java | 12 +++++++++++- 3 files changed, 33 insertions(+), 1 deletion(-) diff --git a/proxy/src/main/java/net/md_5/bungee/UserConnection.java b/proxy/src/main/java/net/md_5/bungee/UserConnection.java index 21d9dba0..67a4269a 100644 --- a/proxy/src/main/java/net/md_5/bungee/UserConnection.java +++ b/proxy/src/main/java/net/md_5/bungee/UserConnection.java @@ -124,6 +124,9 @@ public final class UserConnection implements ProxiedPlayer private final Scoreboard serverSentScoreboard = new Scoreboard(); @Getter private final Collection sentBossBars = new HashSet<>(); + @Getter + @Setter + private String lastCommandTabbed; /*========================================================================*/ @Getter private String displayName; diff --git a/proxy/src/main/java/net/md_5/bungee/connection/DownstreamBridge.java b/proxy/src/main/java/net/md_5/bungee/connection/DownstreamBridge.java index e133d933..528d53ac 100644 --- a/proxy/src/main/java/net/md_5/bungee/connection/DownstreamBridge.java +++ b/proxy/src/main/java/net/md_5/bungee/connection/DownstreamBridge.java @@ -20,7 +20,9 @@ import java.io.DataInput; import java.net.InetSocketAddress; import java.util.ArrayList; import java.util.List; +import java.util.Locale; import java.util.Map; +import java.util.stream.Collectors; import lombok.RequiredArgsConstructor; import net.md_5.bungee.ServerConnection; import net.md_5.bungee.ServerConnection.KeepAliveData; @@ -646,6 +648,23 @@ public class DownstreamBridge extends PacketHandler return input.getText(); } } ); + } else + { + String last = con.getLastCommandTabbed(); + if ( last != null ) + { + String commandName = last.toLowerCase( Locale.ROOT ); + commands.addAll( bungee.getPluginManager().getCommands().stream() + .filter( (entry) -> + { + String lowerCase = entry.getKey().toLowerCase( Locale.ROOT ); + return lowerCase.startsWith( commandName ) && entry.getValue().hasPermission( con ) && !bungee.getDisabledCommands().contains( lowerCase ); + } ) + .map( (stringCommandEntry) -> '/' + stringCommandEntry.getKey() ) + .collect( Collectors.toList() ) ); + commands.sort( null ); + con.setLastCommandTabbed( null ); + } } TabCompleteResponseEvent tabCompleteResponseEvent = new TabCompleteResponseEvent( server, con, new ArrayList<>( commands ) ); diff --git a/proxy/src/main/java/net/md_5/bungee/connection/UpstreamBridge.java b/proxy/src/main/java/net/md_5/bungee/connection/UpstreamBridge.java index 37a17c21..a3536903 100644 --- a/proxy/src/main/java/net/md_5/bungee/connection/UpstreamBridge.java +++ b/proxy/src/main/java/net/md_5/bungee/connection/UpstreamBridge.java @@ -213,8 +213,9 @@ public class UpstreamBridge extends PacketHandler { List suggestions = new ArrayList<>(); boolean isRegisteredCommand = false; + boolean isCommand = tabComplete.getCursor().startsWith( "/" ); - if ( tabComplete.getCursor().startsWith( "/" ) ) + if ( isCommand ) { isRegisteredCommand = bungee.getPluginManager().dispatchCommand( con, tabComplete.getCursor().substring( 1 ), suggestions ); } @@ -257,6 +258,15 @@ public class UpstreamBridge extends PacketHandler { throw CancelSendSignal.INSTANCE; } + + if ( isCommand && con.getPendingConnection().getVersion() < ProtocolConstants.MINECRAFT_1_13 ) + { + int lastSpace = tabComplete.getCursor().lastIndexOf( ' ' ); + if ( lastSpace == -1 ) + { + con.setLastCommandTabbed( tabComplete.getCursor().substring( 1 ) ); + } + } } @Override