args error

Discussion in 'Plugin Development' started by loderos, May 29, 2013.

Thread Status:
Not open for further replies.
  1. hi,my command gives an argument error when i run it, but it does run the command
    Code:
    else if (cmd.getName().equalsIgnoreCase("donator")) {
    String player = sender.getName();
    if (args.length <1 ){
     
  2. Offline

    Minecrell

    loderos What error? Can you show some more code and the full error including the stack trace?
    But I think it is because of
    Code:java
    1. if (args.length <1 ){

    With that code you check if there are NO arguments and not if the player entered arguments.
     
  3. but it's meant to check if the players have no arguments, then how do i do this?
     
  4. Offline

    Minecrell

    loderos Well, then it would be right, but still doesn't explain the error. If you still have problems with the error please post it here.
     
  5. Offline

    kreashenz

    To check if it doesn't have any args, wouldn't you use
    Code:java
    1. if(args.length == 0){
    2. // do stuff
    3. } else if(args.length ???){
    4. // meow
    5. }
     
  6. Offline

    Minecrell

    kreashenz Well args.length can't be smaller than 0, so args.length < 1 and args.length == 0 is the same I think.
     
  7. Offline

    kreashenz

    Minecrell I think Either way, it'd work, I guess.. [EDIT] Woah, the BBCode actually worked.. Wasn't expecting it to.
     
  8. Offline

    Minecrell

    kreashenz Just what I said :p Should be the same, and yes BBCodes are really working! :D
     
  9. Offline

    Rhino390

    Code:java
    1.  
    2. if(args.length == 0) {
    3. //Tell them they need more arguments
    4. return false;
    5. }
    6. else if(args.length == 1) {
    7. //Do the code here
    8. return true;
    9. }
    10. else {
    11. //Tell them what to do here
    12. sender.sendMessage(ChatColor.RED + "Review your argument count!");
    13. return false;
    14. }
    15.  

    The first chunk of code checks if they have no args, the second chunk checks to make sure they only have one argument, while the third is an else statement, so that if their argument length is anything else, it sends them the message telling them the command.

    wow, people replied fast XD

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Jun 1, 2016
  10. Offline

    kreashenz

    I also don't think you should return false, after any case.. I don't use it, but I guess it might just be a habit for me.
     
  11. Offline

    Minecrell

    Rhino390 kreashenz You should return false if you want to show the command usage of your plugin.yml.
     
  12. Offline

    Rhino390

    yeah, I just learned code that way, but i also don't add in the annoying usage message in the plugin.yml, I prefer to tell them manually.
     
  13. thank you for your help by the way
     
  14. Offline

    Minecrell

    loderos Did you solve your problem?
     
Thread Status:
Not open for further replies.

Share This Page