Solved Check args[0] for certain string

Discussion in 'Plugin Development' started by nirajm34, Dec 2, 2013.

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

    nirajm34

    Hey guy, i wanted to check if the /jmp on
    the "on" part shows that the work is actually on.

    so i wanted too check is the args[0] is the word "on" or "off", and if not displays a error message.

    So far got like this

    Code:java
    1. }else if (cmd.getName().equalsIgnoreCase("highjmp")) {
    2. if (args.length == 0) {
    3. p.sendMessage( ChatColor.AQUA + "</highjmp> <on> " );
    4. String toggle = args[0];
    5. }if (args["on"]) {
    6. }
     
  2. Offline

    fireblast709

    Code:
    if(args.length == 1)
    {
        if(args[0].equals("on"))
        {
            // on
        }
        else
        {
            // off
        }
    }
     
  3. Offline

    nirajm34

  4. Offline

    The_Doctor_123

    Errr... that's not how arrays work. You're probably wanting to do something like:
    Code:java
    1. if (args[0].equalsIgnoreCase("on"))
     
  5. Offline

    Goblom

    nirajm34

    Code:java
    1. switch (args[0].toLowerCase()) {
    2. case "on":
    3. //do on stuff
    4. break;
    5. case "off":
    6. //do off stuff
    7. break;
    8. befault:
    9. //do stuff if args[0] is not "on" or "off"
    10. break;
    11. }
     
  6. Offline

    nirajm34

  7. Offline

    fireblast709

    Keep in mind that this does not work for Java 6, which Minecraft is build on :3. (So it would work when the server has Java 7, but not when they use Java 6)
     
  8. Offline

    nirajm34

    not very helpful for the bukkit forums then lol

    Edit: saw your edit, and i now see
     
  9. Offline

    The_Doctor_123

    nirajm34
    All, except Goblom's will work unless you run the server with Java 7.
     
Thread Status:
Not open for further replies.

Share This Page