Auto-Complete Tab to an OfflinePlayer's name

Discussion in 'Plugin Development' started by Mr. Sandwich, Nov 16, 2017.

Thread Status:
Not open for further replies.
  1. Offline

    Mr. Sandwich

    Hii, so I am trying to do so when you type * you will be able to auto-complete to an offline player's name regardless of what argument number this argument is. For example: Hey *Da -> Hey *Danny
    So I am asking if it's possible and if it is how to do it or at least point me into the right direction, thanks in advance.
     
  2. I don't use tab completion a lot, but your best option would probably to store the names of every player who joins in a file, and then use that. However, it might cause issues with name changes, where it autocompletes to a player who doesn't exist. Perhaps there's something in the Mojang API for this?

    Sent from my SM-G903F using Tapatalk
     
  3. Offline

    Unknown123

    @Mr. Sandwich @TheMinecraftKnight
    - Iterate over offline players with Bukkit.getOfflinePlayers()
    - if offlinePlayer.getName().startsWith(name)
    - Auto complete it.

    If you dont know how to start, implement TabCompletor and use getCommand("xyz").setTabCompletor(new YourCompletor()) ;
    Typed on my phone so there might be errors
     
  4. Offline

    MightyOne

    yeah there is this class TabCompleter which is structured similiar to the onCommand() method. The only difference is that it returns a List<String>. In this method you can check the command and args[] and return all possible names.
    dont forget to call getCommand("whatever").setTabCompleter(yourInstanceOfTabCompleter); somewhere in you class that extends JavaPlugin
     
    Last edited: Nov 16, 2017
  5. Offline

    Unknown123


    What? I mean you also can implement both interfaces in one class but you need to set the CommandExecutor and the TabCompletor
     
  6. Offline

    Mr. Sandwich

    But if I complete with the TabCompletor with getCommand wont it only work if its the first argument?
     
Thread Status:
Not open for further replies.

Share This Page