Solved How to avoid the default tab completion list

Discussion in 'Plugin Development' started by bowlerguy66, Sep 28, 2018.

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

    bowlerguy66

    With default 1.13, the server automatically tries to return a list of all of the online players on the server no matter what command you're typing in. I'm trying to override this but I don't know how to tell the difference between the default response and something my plugin is returning. Here is my code and it doesn't do a good job of blocking it:

    Show Spoiler

    Code:
        public void createTabComplete() {
           
            plugin.getProtocolManager().addPacketListener(new PacketAdapter(plugin, ListenerPriority.NORMAL, PacketType.Play.Server.TAB_COMPLETE) {
    
                @Override
                public void onPacketSending(PacketEvent event) {           
                    WrapperPlayServerTabComplete wrapper = new WrapperPlayServerTabComplete(event.getPacket());
    
                    Bukkit.broadcastMessage(wrapper.getSuggestions().getList().get(0).toString() + " is the first");
    
                    if(wrapper.getSuggestions().getList().get(0) != null) {
                        String text = wrapper.getSuggestions().getList().get(0).toString();
                        if(text.equals("donotuse")) {
                            event.setCancelled(true);
                        }
                    }
                   
                }
    
            });
           
        }
       
        @Override
        public List<String> onTabComplete(CommandSender sender, Command cmd, String label, String[] args) {
    
            List<String> completions = new ArrayList<String>();
                   
            if(cmd.getName().equalsIgnoreCase("mine")) {
                           
                if(args[0].equalsIgnoreCase("")) {
                   
                    completions.add("list");
                    completions.add("regenerate");
                    completions.add("quickregen");
                    completions.add("clear");
    
                } else if(args[0].equalsIgnoreCase("list")) {
                    return null;
                } else if(args[0].equalsIgnoreCase("regenerate") || args[0].equalsIgnoreCase("regen") || args[0].equalsIgnoreCase("quickregen") || args[0].equalsIgnoreCase("clear")) {
                   
                    completions.add("All");
                                   
                    for(Mine m : MineManager.activeMines) {
                        if(m.getName().equalsIgnoreCase("AMine1") || m.getName().equalsIgnoreCase("AMine2") || m.getName().equalsIgnoreCase("AMine3") || m.getName().equalsIgnoreCase("AMine4")) {
                            completions.add("A");
                            continue;
                        }
                        completions.add(m.getName());
                    }
                   
                    completions.set(0, "All");
                   
                } else {
                    completions.add("donotuse");
                }
               
                return completions;
               
            }
           
            return null;
           
        }
    


    bump

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Sep 29, 2018
  2. Have you tried using the CommandPreProcessEvent?
     
  3. Offline

    Esophose

    @bowlerguy66
    You don't need to do anything fancy with the packets. Returning null from the onTabComplete method will by default display the online players' names as the auto-complete arguments. If you want it to be blank, return an empty ArrayList<String>.
     
  4. Offline

    bowlerguy66

Thread Status:
Not open for further replies.

Share This Page