[Beginner] Quick TabCompleter Tutorial

Discussion in 'Resources' started by Blah1, Apr 2, 2014.

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

    Blah1

    Just a quick tutorial on how to use the TabCompleter feature.

    If you don't know what this is, go in game and do /effect (yourName) and press tab.

    Without further ado, here is the commented class:

    Code:java
    1. // Make sure your class implements TabCompleter.
    2. public class Test implements TabCompleter {
    3. public List<String> onTabComplete(CommandSender sender, Command cmd, String commandLabel, String[] args) {
    4. List<String> list = new ArrayList<>();
    5. // Now, it's just like any other command.
    6. // Check if the sender is a player.
    7. if (sender instanceof Player) {
    8. // Check if the command is "something."
    9. if (cmd.getName().equalsIgnoreCase("command")) {
    10. // If the player has not typed anything in
    11. if (args.length == 0) {
    12. // Add a list of words that you'd like to show up
    13. // when the player presses tab.
    14. list.add("hello");
    15. list.add("hello2");
    16. // Sort them alphabetically.
    17. Collections.sort(list);
    18. // return the list.
    19. return list;
    20. // If player has typed one word in.
    21. // This > "/command hello " does not count as one
    22. // argument because of the space after the hello.
    23. } else if (args.length == 1) {
    24. list.add("hello");
    25. list.add("hello2");
    26. for (String s : list){
    27. // Since the player has already typed something in,
    28. // we ant to complete the word for them so we check startsWith().
    29. if (!s.toLowerCase().startsWith(args[0].toLowerCase())){
    30. list.remove(s);
    31. }
    32. }
    33. Collections.sort(list);
    34. return list;
    35. }
    36. }
    37. }
    38. // return null at the end.
    39. return null;
    40. }
    41. }
     
  2. Offline

    iiHeroo

    You should upload an image of this, images are very sexy.
     
  3. Offline

    Bammerbom

    iiHeroo Yup. You are very sexy too.
     
  4. Offline

    ImPhantom

    Garris0n likes this.
  5. Offline

    Garris0n

    ಠ◡ಠ
     
    ccrama likes this.
  6. Offline

    Bammerbom

Thread Status:
Not open for further replies.

Share This Page