#3418: Add tab completion for bungee command names in pre-1.13 versions

This commit is contained in:
Outfluencer 2023-07-05 19:52:43 +10:00 committed by md_5
parent 3a6e2631bf
commit 9f5ace9025
No known key found for this signature in database
GPG Key ID: E8E901AC7C617C11
3 changed files with 33 additions and 1 deletions

View File

@ -124,6 +124,9 @@ public final class UserConnection implements ProxiedPlayer
private final Scoreboard serverSentScoreboard = new Scoreboard();
@Getter
private final Collection<UUID> sentBossBars = new HashSet<>();
@Getter
@Setter
private String lastCommandTabbed;
/*========================================================================*/
@Getter
private String displayName;

View File

@ -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 ) );

View File

@ -213,8 +213,9 @@ public class UpstreamBridge extends PacketHandler
{
List<String> 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