From 9b71564c5b2164ae0415ac33e7044473d560c68b Mon Sep 17 00:00:00 2001 From: Luccboy <58391278+Luccboy@users.noreply.github.com> Date: Sun, 29 Oct 2023 04:21:15 +0100 Subject: [PATCH] Improve tab completion of glist and send command (#1126) --- .../proxy/command/builtin/GlistCommand.java | 12 ++++++++-- .../proxy/command/builtin/SendCommand.java | 24 +++++++++++++++---- 2 files changed, 29 insertions(+), 7 deletions(-) diff --git a/proxy/src/main/java/com/velocitypowered/proxy/command/builtin/GlistCommand.java b/proxy/src/main/java/com/velocitypowered/proxy/command/builtin/GlistCommand.java index 5d2f19fea..0bfc0f074 100644 --- a/proxy/src/main/java/com/velocitypowered/proxy/command/builtin/GlistCommand.java +++ b/proxy/src/main/java/com/velocitypowered/proxy/command/builtin/GlistCommand.java @@ -66,10 +66,18 @@ public class GlistCommand { ArgumentCommandNode serverNode = RequiredArgumentBuilder .argument(SERVER_ARG, StringArgumentType.string()) .suggests((context, builder) -> { + String argument = context.getArguments().containsKey(SERVER_ARG) + ? context.getArgument(SERVER_ARG, String.class) + : ""; for (RegisteredServer server : server.getAllServers()) { - builder.suggest(server.getServerInfo().getName()); + String serverName = server.getServerInfo().getName(); + if (serverName.regionMatches(true, 0, argument, 0, argument.length())) { + builder.suggest(serverName); + } + } + if ("all".regionMatches(true, 0, argument, 0, argument.length())) { + builder.suggest("all"); } - builder.suggest("all"); return builder.buildFuture(); }) .executes(this::serverCount) diff --git a/proxy/src/main/java/com/velocitypowered/proxy/command/builtin/SendCommand.java b/proxy/src/main/java/com/velocitypowered/proxy/command/builtin/SendCommand.java index bf07e8a4c..555716130 100644 --- a/proxy/src/main/java/com/velocitypowered/proxy/command/builtin/SendCommand.java +++ b/proxy/src/main/java/com/velocitypowered/proxy/command/builtin/SendCommand.java @@ -56,21 +56,35 @@ public class SendCommand { .executes(this::usage) .build(); ArgumentCommandNode playerNode = RequiredArgumentBuilder - .argument("player", StringArgumentType.word()) + .argument(PLAYER_ARG, StringArgumentType.word()) .suggests((context, builder) -> { + String argument = context.getArguments().containsKey(PLAYER_ARG) + ? context.getArgument(PLAYER_ARG, String.class) + : ""; for (Player player : server.getAllPlayers()) { - builder.suggest(player.getUsername()); + String playerName = player.getUsername(); + if (playerName.regionMatches(true, 0, argument, 0, argument.length())) { + builder.suggest(playerName); + } + } + if ("all".regionMatches(true, 0, argument, 0, argument.length())) { + builder.suggest("all"); } - builder.suggest("all"); return builder.buildFuture(); }) .executes(this::usage) .build(); ArgumentCommandNode serverNode = RequiredArgumentBuilder - .argument("server", StringArgumentType.word()) + .argument(SERVER_ARG, StringArgumentType.word()) .suggests((context, builder) -> { + String argument = context.getArguments().containsKey(SERVER_ARG) + ? context.getArgument(SERVER_ARG, String.class) + : ""; for (RegisteredServer server : server.getAllServers()) { - builder.suggest(server.getServerInfo().getName()); + String serverName = server.getServerInfo().getName(); + if (serverName.regionMatches(true, 0, argument, 0, argument.length())) { + builder.suggest(serverName); + } } return builder.buildFuture(); })