Solved Registering Commands outside of plugin.yml

Discussion in 'Spigot Plugin Development' started by David_Mayr, Mar 29, 2020.

  1. I have a Core Plugin and a Module System. The Core Plugin loads all the Modules. The Modules can obviously not edit the plugin.yml so i built a method to register them with NMS!
    Code (Text):

    PluginCommand command = null;

    try {
        Constructor<PluginCommand> c = PluginCommand.class.getDeclaredConstructor(String.class, Plugin.class);
        c.setAccessible(true);
       
        command = c.newInstance(aliases[0], plugin);
    } catch (SecurityException | IllegalArgumentException | IllegalAccessException | InstantiationException | InvocationTargetException | NoSuchMethodException e) {
        e.printStackTrace();
    }
    if(command == null) return;
    command.setAliases(Arrays.asList(aliases));
    getCommandMap().register(aliases[0], plugin.getDescription().getName(), command);
     
    It works but I cant tab the commands...
     
  2. Call private syncCommands() method using reflection from Bukkit.getServer() class.
     
  3. It works! Thanks