Solved Tab Autocompletion for Arguments

Discussion in 'BungeeCord Plugin Development' started by Skifty, Feb 5, 2020.

  1. So I have a plugin for private messages across servers
    How would I make a suggestion of PlayerNames when the player presses TAB after entering the command ?
     
  2. implement TabExecutor in your command.
     
  3. Code (Text):
    @Override
        public Iterable<String> onTabComplete(CommandSender commandSender, String[] strings) {
            if (strings.length == 1) {
                ArrayList<String> PlayerNames = new ArrayList<>();
                for (ProxiedPlayer p : ProxyServer.getInstance().getPlayers()) {
                    PlayerNames.add(p.getName());
                }
                return PlayerNames;
            }

            return null;
        }
    Alright, so I got this. Works fine when tabbing the first argument, no problem there. But when you try to Tab after the first argument (so when you begin typing the message) Bungee throws a NPE (which makes sense because it returns null) how can I prevent this?
     
  4. You can try Collections.emptyList() instead of null.
     
  5. That worked perfectly, Thanks a lot !