Solved Default Spigot Tab Completion (/ <tab>)

Discussion in 'Spigot Plugin Development' started by Maxx_Qc, Mar 6, 2020.

  1. Hey guys, I'm trying to figure a way of removing certain commands when a player do /<tab> in the chat. I tried using PlayerCommandSendEvent and PlayerChatTabCompleteEvent but it didn't work... I got the collections, cleared it, and added all of my custom commands (I only want those to be accessible with tab complete, not bukkit/spigot base commands such as /me and stuff).

    Thank you :)
     
  2. Players only see commands they have permissions for BUT the permissions have to be setup in the plugin.yml for the server to know that it should check.
     
  3. Currently the players have no permission at all, yet they can see almost every command on the server using the tab method. Like, they don't have the permission to do /me, they get the permission error message from bukkit, but it is still available on the tab complete.
     
  4. You can completely remove any command with commands.yml, but be warned this removes the command for ALL users, even console.

    Code (YAML):
    aliases:
      me
    :
     - []
     
    I checked on my test server to be sure. This removes the command from tab completion and everything (even console)
     
  5. drives_a_ford

    Moderator

    PlayerCommandSendEvent is the way to go. You said you tried it. What went wrong? Are you sure you registered your listener and the event was handled?
    Perhaps you had some other logic in the event handler that didn't work properly?
     
    • getCommands
      @NotNull
      public @NotNull Collection<String> getCommands()
      Returns a mutable collection of all top level commands to be sent.
      It is not legal to add entries to this collection, only remove them. Behaviour of adding entries is undefined.
      Returns:
      collection of all commands
     
  6. Why didn’t clear work?


    Every others event are working in my class. Did some debug, method got called but it did nothing. What went wrong? Well player still sees all the command
     
  7. I would have to see your code. I think it is unwise to use clear as that would erase all results and since you are not able to add commands your left with nothing. You should just remove the commands you don't want in tab completion.
     
  8. drives_a_ford

    Moderator

    I just tried and it works just fine:
    Code (Java):

    @EventHandler
    public void onCommands(org.bukkit.event.player.PlayerCommandSendEvent event) {
    event.getCommands().clear();
    perms.getLogger().info("cleared for " + event.getPlayer().getName());
    }
     
    Result: no commands to tab-complete.

    You should share your code, otherwise all I can do is speculate.
     
  9. Yop, my bad. There was an error on my switch case... thanks for this, solved!