[SOLVED] Get Multiple args from command

Discussion in 'Plugin Development' started by SteppingHat, Jul 2, 2012.

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

    SteppingHat

    Hey there!

    So, I'm working on a plugin and one of the commands sends a message to a specified user along with other actions.

    The syntax is /command <playername> <message>

    So playername will be args[0] and message will be args[1] and up
    Since the length of args for the message section of the command varies depending on the length of the message, I don't know how to count the arguments and put it into a message to the player.

    I appreciate all your help and thanks heaps!
     
  2. Offline

    Jnorr44

    an example from my own plugin:
    Code:
                // rainFill
                if (args[0].equalsIgnoreCase("rainFill")) {
                    if (args[1].equalsIgnoreCase("false")) {
                        plugin.getConfig().set("rainFill", false);
                        log.info("Flow config.yml, 'rainFill' has been set to FALSE!");
                        flowplayer.sendMessage("Flow config.yml, 'rainFill' has been set to FALSE!");
                        plugin.saveConfig();
                        return true;
                    }
                    if (args[1].equalsIgnoreCase("true")) {
                        plugin.getConfig().set("rainFill", true);
                        log.info("Flow config.yml, 'rainFill' has been set to TRUE!");
                        flowplayer.sendMessage("Flow config.yml, 'rainFill' has been set to TRUE!");
                        plugin.saveConfig();
                        return true;
                    }
                }
    this gets 2 string args
    or is this even what your asking?
     
  3. Offline

    EnvisionRed

    Well, here's something I use:
    Code:
    int k = 1;
    String message = "";
    StringBuilder s = new StringBuilder(300)
    while (k < args.length){
    message = s.append(args[k]).append(" ").toString;
    k++;
    }
    
     
  4. Offline

    SteppingHat

    Thanks EnvisionRed !
    Everythings all working just the way it's supposed to :)
    Thanks for your help!
     
  5. Offline

    sayaad

    This is easily achieved using a for loop. Use this API

    Code:java
    1. private String getArgs(String[] args){
    2. String message = "";
    3. for(int i = 0; i < args.length(); i++){
    4. message = message + args + " ";
    5. }
    6. return message;
    7. }
     
Thread Status:
Not open for further replies.

Share This Page