Solved Command Arguements

Discussion in 'Plugin Development' started by MBon29, Jul 30, 2014.

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

    MBon29

    So I have one base command but I have several arguments with different tasks. I rather not have all my commands in one class. What would be the best way to go about doing this? I have searched around a bit but all the ways I have seen have seemed too over complicated than they should be.

    Base Command: /master
    Sub Commands:
    • /master tabname <player> <color>
    • /master worldtp <player> <world>
    • /master hide
     
  2. Offline

    JustinsCool15

    Code:
    if(cmd.getName().equalsIgnoreCase("master"){
        if(args.length > 0){
            if(args[0].equalsIgnoreCase("tabname"){
                //Stuff
            }
            if(args[0].equalsIgnoreCase("worldtp"){
                //Stuff
            }
            if(args[0].equalsIgnoreCase("hide"){
                //Stuff
            }
            if(args[0].equalsIgnoreCase("tabname"){
                //Stuff
            }
        }
    }
     
  3. Offline

    MBon29

    I know how to do that but I wanted to have each subcommand in a different class. How would I do that? (I do know java but am still rusty).
     
  4. Offline

    mythbusterma

    Just call them after you've filtered the command, or you can call all of them, effectively giving them a chance to listen for the command.
     
  5. Offline

    MBon29

    I need an example of the second thing you said. I am a bit confused.
     
  6. Offline

    mythbusterma

    MBon29

    For example:

    Code:java
    1. private OtherCommandListener listener1;
    2. private OtherOtherCommandListener listener2;
    3.  
    4. public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) {
    5. listener1.doThis(sender,label,args);
    6. listener1.doThat(sender,label,args);
    7. listener2.doThis(sender,label,args);
    8. listener2.doThat(sender,label,args);
    9. }


    So you'd have two other classes that would receive commands and it's up to each method to filter to see if that is it.
     
Thread Status:
Not open for further replies.

Share This Page