Arg 2 not working

Discussion in 'Plugin Development' started by ChintziSecilMC, Jul 4, 2015.

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

    ChintziSecilMC

    I have no idea why this isn't working, does anyone have any idea why this wouldn't work, the first are "give" works but arg 2 "chest" doesnt D:

    I grateful for any help i get

    Code:
                } else if (args.length == 1 && args[0].equalsIgnoreCase("give")) {
                    player.sendMessage(pluginPrefix);
                    if (args.length == 2 && args[1].equalsIgnoreCase("chest")) {
                        player.sendMessage("test");
                    }
                }
     
  2. Offline

    feff890

    @ChintziSecilMC

    Line 1 is where your problem is. Should be:
    Code:
    } else if (args.length == 2 && args[0].equalsIgnoreCase("give")) {
     
  3. Offline

    BladeFireTurtle

    Yeah, this means you can also remove the args.length check in the second if statement.
     
  4. @feff890 @BladeFireTurtle
    You barely explained what exactly is wrong, even I don't understand it.
    @ChintziSecilMC
    You're first checking if the argument length is 1, and then after that check you're checking if the length is 2, so that will never return true. I recommend using >= (bigger than or equal to) instead of ==, so your arguments can be as long as you want without having issues with not getting the arguments.
     
  5. Offline

    BladeFireTurtle

    Oh sorry I was being lazy. In my defence, I assumed the OP did have some basic understanding of his own code and it seemed like a very simple logic error. As a side note I do not recommend using >= (why get arguments that you don't support?), instead check if the length is what you expect, in your case length == 2 and use an else statement to send the player a usage message if the augment length is not what you expect.
     
  6. @BladeFireTurtle
    Well, unless you want something specific, I sometimes find it more easy to not be limited to a certain argument length, and not get invalid arguments when typing 1 more argument that has no effect.
     
  7. Offline

    stefvanschie

    Code:
    if (args.length == 2 && args[0].equalsIgnoreCase("give") {
      if (args[1].equalsIgnoreCase("chest") {
        //code
      }
    }
     
Thread Status:
Not open for further replies.

Share This Page