Registering a CommandExecutor for all commands

Discussion in 'Plugin Development' started by Hoolean, Jan 20, 2013.

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

    Hoolean

    Is there a way to register a CommandExecutor without using getCommand().setExecutor()?

    It's pretty important for my plugin that the command names will change depending on each time it is started up .___.
     
  2. the plugin main class also implements CommandExecutor, and its called if you dont set a command executer for a command
     
  3. Offline

    Hoolean

    What if I don't have a Plugin class to add it too :/
     
  4. Offline

    gomeow

    What I like to do is have a class, called PluginCommand, have the constructor take the instance of the Plugin, and have a method called execute(CommandSender cs, String[] args) that returns true/false. Then in the onCommand in the main class I use it.

    As seen here: https://github.com/gomeow/DepositChest/blob/master/me/gomeow/Depositchest.java

    But if you have multiple commands you might want to try it a little differently
     
  5. without a main class, a plugin cannot run
     
  6. Offline

    Hoolean

    Yes, I'm very aware of that, hence me having 31 projects on BukkitDev, I just need to know if there is a way of doing it without making a JavaPlugin class ._______.
     
  7. you can manually read the plugin.yml and scan it for commands and register them
     
  8. Offline

    desht

    Probably better to use plugin.getDescription().getCommands().keySet() in this case. That will give you a Set containing all your command names.
    PHP:
    for (String cmdNamegetDescription().getCommands().keySet()) {
      
    getCommand(cmdName).setExecutor(someOtherClass);
    }
     
  9. Offline

    Hoolean

     
  10. Offline

    Liuci

    In what way are you changing the command names?
    Are you setting the names externally through the plugin.yml? If so, as ferrybig said, you can register each one manually onEnable, and desht 's code would work for this since the foreach iterates through your plugin.yml and sends all new command names to your commandExecutor.
     
Thread Status:
Not open for further replies.

Share This Page