Solved Adding commands to the command suggester.

Discussion in 'Spigot Plugin Development' started by Tirco, Jun 30, 2021.

  1. When you first start typing a command in minecraft, the game will try to parse the commands you have access to, and if it can't find it, it will turn it red. Since this list contains plugin commands as well, clearly this is sendt from the server to the client at some point... What I want to do is ADD values to the list. All resources I could find were about removing them.


    What I tried, (but as the e.getCommands() said, it wouldn't work):

    Code (Java):
        @EventHandler
        public void onCommandSuggestion(PlayerCommandSendEvent e) {
            //Collection<String> completions = e.getCommands();
            Collection<String> commandBuilderCommands = new ArrayList<String>();
            for(CommandBuilder b : MyListOfCommands) {
                commandBuilderCommands.add(b.getName());
            }
            //e.getCommands().clear();
            e.getCommands().addAll(commandBuilderCommands);
            e.getPlayer().updateCommands(); //Tried both with and without this bit.
     
    Any suggestions?
     
  2. The easiest way to do it would be to just register new commands through the plugin.yml file.
    That way it'll automatically be added to the list without having to write any code to mess with it.
    Of course you don't have to make command executors for them.
     
  3. But he might want it to be dynamic.
     
  4. Plugins are already static the moment you make them so how can the commands be dynamic?
    Or do you mean like if he wants to add commands via commands?
     
  5. Yes for example, or trough config.
     
  6. Fine, if you don't care about dynamics (and actually want to do something with these commands) use what I said (plugin.yml).
    If not, then you can use the PlayerCommandPreprocessEvent event to add commands to the list, but do note that with this method if the player runs the fake commands you added there's a good chance for errors.
    Choose what you prefer.
     
  7. Yes, I do want them to be dynamic.
    I don't see how PlayerCommandPreprocessEvent helps here?

    To clarify, making stuff happen when you type in an unexisting command is not what I'm after.
    What I'm after is adding items to this list:
    upload_2021-6-30_12-54-45.png
    Even if the command doesn't exist.
     
  8. Whoops, my bad... Use PlayerCommandSendEvent.
    More specifically do "PlayerCommandSendEvent.getCommamds()" and add whatever you want to it.
     
  9. Thanks for trying to help, but I don't think you read my first post properly :)

    Using PlayerCommandSendEvent is what I've tried to do, but
    upload_2021-6-30_14-21-0.png
    I tried either way, doesn't work...
     
  10. Then plugin.yml it is.
    Sorry mate, no idea why that didn't work...
     
  11. Im going to do my best to help, but I dont know if this is 100% going to help.

    1) You need to register your command to the server, this I think can be done dynamically.

    2) You need to re-send the command map to players. This requires CraftBukkit as Bukkit does not have API for it. In Skript we do this, since commands can be created/added at anytime while the server is currently running. Here is the utility class in Skript that resends commands to players:
    https://github.com/SkriptLang/Skrip...h/njol/skript/bukkitutil/CommandReloader.java
     
    • Agree Agree x 1
    • Useful Useful x 1

  12. Thank you! This bit is really useful :)
     
    • Friendly Friendly x 1