How to add command to /help list

Discussion in 'Spigot Plugin Development' started by Armagidon, Jan 1, 2020.

  1. I'm registering my commands without plugin.yml via Reflection. And as I grasped when you register command this way, they aren't appear in /help list! How to add command to /help list?
    UPD: I noticed that you can't use setTabComplete, if you register commands this way!
     
    #1 Armagidon, Jan 1, 2020
    Last edited: Jan 1, 2020
  2. Can you show the code where you're registering the commands? Have you tried adding it to the command map in SimplePluginManager?
     
  3. Code (Java):
    public APICommand addCommand(Plugin plugin, String cmd,String pluginname, APIExecutor executor) {
            Validate.notNull(cmd);
            Validate.notEmpty(cmd);
            Validate.notNull(plugin);
            Validate.notNull(executor);
            APICommand command = new APICommand(cmd, executor);

            try {
                final Field bukkitCommandMap = plugin.getServer().getClass().getDeclaredField("commandMap");

                bukkitCommandMap.setAccessible(true);
                CommandMap commandMap = (CommandMap) bukkitCommandMap.get(plugin.getServer());

                commandMap.register(pluginname, command);
            } catch (Exception e) {
                e.printStackTrace();
            }
            if (!commands.containsKey(plugin)) {
                commands.put(plugin, new HashMap<>());
            }
            commands.get(plugin).put(cmd,command);
            return command;
        }