Tab Complete Entities

Discussion in 'Plugin Development' started by Hatsonboats58, Sep 3, 2020.

  1. Offline

    Hatsonboats58

    I was wondering how I could tab complete entities. I understand players but can't seem to find entities.
    Thanks in advance and I will be here if you don't have all the information needed (this is my first post).

    Code:
    package com.hatsonboats.commands;
    
    import org.bukkit.Bukkit;
    import org.bukkit.command.Command;
    import org.bukkit.command.CommandSender;
    import org.bukkit.command.TabCompleter;
    
    import java.util.ArrayList;
    import java.util.List;
    
    public class InvisTabCompletion implements TabCompleter {
        @Override
        public List<String> onTabComplete(CommandSender sender, Command cmd, String label, String[] args) {
            if(args.length == 1){
                
               
            }
        }
    }
    
     
  2. Offline

    xelatercero

    I mean you wan to tab complete the names of ALL entities? I a not the mosted suited to give advice , but i did this:

    Code:java
    1.  
    2. public class TestTabCompleter implements TabCompleter {
    3.  
    4. @Overridepublic List<String> onTabComplete(CommandSender sender, Command cmd, String label, String[] args) {
    5.  
    6. if(!(sender instanceof Player)) { sender.sendMessage(ChatColor.RED + "This command is only for players"); return null;}
    7. Player player = (Player) sender;
    8. List<String> entList = new ArrayList<>();
    9. if(cmd.getName().equalsIgnoreCase("spm")) {
    10.  
    11. EntityType[] entArray = EntityType.values();
    12.  
    13. for(EntityType ent : entArray) {
    14. entList.add(ent.toString());
    15. }
    16.  
    17. return (args.length > 0) ? StringUtil.copyPartialMatches(args[0], entList, new ArrayList<>()) : null;}
    18.  
    19.  
    20.  
    21.  
    22. return null;}
    23. }
    24.  



    EDIT: Also you dont specify wich command do you want to complete
     
    Last edited: Sep 4, 2020
  3. Offline

    Hatsonboats58

    Ok. Its /farm <entity>

    Edit: I tried it and it didn't work. I did change spm to farm but it still didnt work
     
    Last edited: Sep 4, 2020
  4. Offline

    xelatercero

    Can you post your command class, your main class, and your tab complete class?
     

Share This Page