diff --git a/api/src/main/java/com/velocitypowered/api/proxy/ConsoleCommandSource.java b/api/src/main/java/com/velocitypowered/api/proxy/ConsoleCommandSource.java new file mode 100644 index 000000000..b48542cc3 --- /dev/null +++ b/api/src/main/java/com/velocitypowered/api/proxy/ConsoleCommandSource.java @@ -0,0 +1,9 @@ +package com.velocitypowered.api.proxy; + +import com.velocitypowered.api.command.CommandSource; + +/** + * Indicates that the executor of the command is the console. + */ +public interface ConsoleCommandSource extends CommandSource { +} diff --git a/api/src/main/java/com/velocitypowered/api/proxy/ProxyServer.java b/api/src/main/java/com/velocitypowered/api/proxy/ProxyServer.java index a3d0111f8..7cde5a176 100644 --- a/api/src/main/java/com/velocitypowered/api/proxy/ProxyServer.java +++ b/api/src/main/java/com/velocitypowered/api/proxy/ProxyServer.java @@ -99,7 +99,7 @@ public interface ProxyServer { * * @return the console command invoker */ - CommandSource getConsoleCommandSource(); + ConsoleCommandSource getConsoleCommandSource(); /** * Gets the {@link PluginManager} instance. 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 a7e2e69af..e5b07c58b 100644 --- a/proxy/src/main/java/com/velocitypowered/proxy/command/VelocityCommandManager.java +++ b/proxy/src/main/java/com/velocitypowered/proxy/command/VelocityCommandManager.java @@ -68,21 +68,29 @@ public class VelocityCommandManager implements CommandManager { return commands.containsKey(command); } + /** + * Offer suggestions to fill in the command. + * @param source the source for the command + * @param cmdLine the partially completed command + * @return a {@link List}, possibly empty + */ public List offerSuggestions(CommandSource source, String cmdLine) { Preconditions.checkNotNull(source, "source"); Preconditions.checkNotNull(cmdLine, "cmdLine"); String[] split = cmdLine.split(" ", -1); if (split.length == 0) { + // No command available. return ImmutableList.of(); } String alias = split[0]; if (split.length == 1) { + // Offer to fill in commands. List availableCommands = new ArrayList<>(); for (Map.Entry entry : commands.entrySet()) { - if (entry.getKey().regionMatches(true, 0, alias, 0, alias.length()) && - entry.getValue().hasPermission(source, new String[0])) { + if (entry.getKey().regionMatches(true, 0, alias, 0, alias.length()) + && entry.getValue().hasPermission(source, new String[0])) { availableCommands.add("/" + entry.getKey()); } } @@ -93,6 +101,7 @@ public class VelocityCommandManager implements CommandManager { String[] actualArgs = Arrays.copyOfRange(split, 1, split.length); Command command = commands.get(alias.toLowerCase(Locale.ENGLISH)); if (command == null) { + // No such command, so we can't offer any tab complete suggestions. return ImmutableList.of(); } diff --git a/proxy/src/main/java/com/velocitypowered/proxy/console/VelocityConsole.java b/proxy/src/main/java/com/velocitypowered/proxy/console/VelocityConsole.java index 97e7f84ad..79fe49d10 100644 --- a/proxy/src/main/java/com/velocitypowered/proxy/console/VelocityConsole.java +++ b/proxy/src/main/java/com/velocitypowered/proxy/console/VelocityConsole.java @@ -1,9 +1,9 @@ package com.velocitypowered.proxy.console; -import com.velocitypowered.api.command.CommandSource; import com.velocitypowered.api.event.permission.PermissionsSetupEvent; import com.velocitypowered.api.permission.PermissionFunction; import com.velocitypowered.api.permission.Tristate; +import com.velocitypowered.api.proxy.ConsoleCommandSource; import com.velocitypowered.proxy.VelocityServer; import java.util.List; import net.kyori.text.Component; @@ -18,7 +18,7 @@ import org.jline.reader.Candidate; import org.jline.reader.LineReader; import org.jline.reader.LineReaderBuilder; -public final class VelocityConsole extends SimpleTerminalConsole implements CommandSource { +public final class VelocityConsole extends SimpleTerminalConsole implements ConsoleCommandSource { private static final Logger logger = LogManager.getLogger(VelocityConsole.class);