How to change onTabComplete to NOT include Ops

Discussion in 'Plugin Development' started by ice374, Aug 9, 2013.

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

    ice374

    How to change onTabComplete to NOT include Ops :/
     
  2. Offline

    Dyprex

    ice374 likes this.
  3. Offline

    ice374

    Dyprex that's what I had been thinking should work, but I cant manage to get the idea out of my head and into reality if you know the feeling
     
  4. Offline

    afistofirony

    ice374 perhaps something like this?

    Code:
    public List<String> onTabComplete (CommandSender sender, Command command, String label, String[] args) {
        List<String> nonOps = new ArrayList<String>();
        List<String> result = new ArrayList<String>();
        for (Player player : Bukkit.getOnlinePlayers ()) {
            if (!player.isOp())
                nonOps.add(player.getName());
        }
     
        for (String name : nonOps) {
             if (name.toLowerCase().startsWith(args[args.length - 1].toLowerCase()))
                 result.add(name);
        }
     
        return result;
    }
     
    ice374 likes this.
  5. Offline

    breezeyboy

    Whats the event onTabComplete do anyways?
     
    ice374 likes this.
  6. Offline

    afistofirony

    It's not an event. You use it in a class that implements TabExecutor. It takes the same parameters as the onCommand method from the CommandExecutor interface.

    (You also have to set the tab executor in the main class, I think it's getCommand("name").setExecutor(new TabExecutor {...});)
     
    ice374 likes this.
  7. Offline

    ice374

    That seems like it should work, but how do i make it override online player names when someone is typing (not just a command).

    For example if there were 3 people on (ice, iboss and idev) and ice was an op, then only iboss and idev would show up when someone types something like "hello i" then presses TAB

    anyone? please

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Jun 3, 2016
  8. Offline

    newboyhun

    ice374
    Use PlayerChatTabCompleteEvent event.

    Code:
    @EventHandler
    public void tabcomplete(PlayerChatTabCompleteEvent e) {
        e.getTabCompletions.clear();
        List<String> nonOps = new ArrayList<String>();
        List<String> result = new ArrayList<String>();
        for (Player player : Bukkit.getOnlinePlayers ()) {
            if (!player.isOp())
                nonOps.add(player.getName());
        }
     
        for (String name : nonOps) {
            if (name.toLowerCase().startsWith(args[args.length - 1].toLowerCase()))
                result.add(name);
        }
     
        e.getTabCompletions().addAll(result);
    }
    
     
    ice374 likes this.
  9. Offline

    ice374

    just getting this small problem: http://imgur.com/LTAMhHn
     
  10. Offline

    AmShaegar

    Code:
    String[] args = e.getChatMessage().split(" ");
     
    ice374 likes this.
  11. Offline

    newboyhun

    ice374
    Code:
    if (name.toLowerCase().startsWith(e.getLastToken().toLowerCase()))
    
     
    ice374 likes this.
Thread Status:
Not open for further replies.

Share This Page