Help with CommandExecutors

Discussion in 'Plugin Development' started by greaperc4, Oct 23, 2013.

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

    greaperc4

    Hello,
    I want to make CommandExecutors and I know how,
    but 1 question

    How can I get a CommandExecutor to check for args?
    I mean:
    This must me in OnEnable:
    getCommand("Command").setExecutor(new CommandCommand(this));

    I want this:
    getCommand("Command Help").setExecutor(new HelpCommand(this));

    But how, because this cannot be done. I think
     
  2. Offline

    zombiekiller753

    greaperc4
    In your CommandExecutor, you can check for args.

    Read the Plugin Wiki. It got me started.
     
  3. Offline

    adam753

    The args don't matter to Executors. Bukkit passes the command to your plugin, which then passes it to any registered executors matching the actual command.

    But it would be really easy to make a system yourself that does something like this.
     
  4. Offline

    greaperc4

    so I need to make like this?

    Code:java
    1. getCommand("Command").setExecutor(new QuitCommand(this));
    2. getCommand("Command").setExecutor(new JoinCommand(this));


    @ in the QuitCommand:

    Code:java
    1.  
    2. public boolean onCommand(CommandSender sender, Command cmd, String CommandLabel, String[] args) {
    3.  
    4. if (sender instanceof Player) {
    5.  
    6. Player player = (Player) sender;
    7.  
    8. if (cmd.getName().equalsIgnoreCase("Command")) {
    9.  
    10. if (args[0].equalsIgnoreCase("Quit")) {
    11.  
    12. //dostuff
    13. }
    14. }
    15. }
    16. }
    17. return false;
    18. }


    @ in the JoinCommand:

    Code:java
    1.  
    2. public boolean onCommand(CommandSender sender, Command cmd, String CommandLabel, String[] args) {
    3.  
    4. if (sender instanceof Player) {
    5.  
    6. Player player = (Player) sender;
    7.  
    8. if (cmd.getName().equalsIgnoreCase("Command")) {
    9.  
    10. if (args[0].equalsIgnoreCase("Join")) {
    11.  
    12. //dostuff
    13. }
    14. }
    15. }
    16. }
    17. return false;
    18. }
     
  5. Offline

    greaperc4

  6. Offline

    kaZep

    Well everything seems good to me... Go for it!

    [​IMG]
     
    EvilKanoa likes this.
Thread Status:
Not open for further replies.

Share This Page