Solved What's wrong in here?!

Discussion in 'Plugin Development' started by Condolent, Jul 15, 2014.

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

    Condolent

    Code:java
    1. if(args.length == 2) {
    2.  
    3. if(args[0].equalsIgnoreCase("create")) {
    4.  
    5. String factionName = args[1];
    6.  
    7. if(factionName.toCharArray().length > 7) {
    8. p.sendMessage(ChatColor.RED + "Too many characters! A faction-name can contain up to 7 characters!");
    9. } else
    10. if(factionName.toCharArray().length == 7) {
    11.  
    12. factions.add(factionName);
    13. p.sendMessage(ChatColor.GREEN + "Faction " + factionName + " successfully created!");
    14. plugin.savePlayerFactions();
    15.  
    16. }
    17.  
    18. }
    19.  
    20. }



    Can anyone see where it goes wrong?
    Trying to set it so if the 2nd argument has 7 characters or lower, it adds the argument to a string list. Only it won't do anything, not even give a error statement..
     
  2. Offline

    teej107

    Add in debug code. String already has a length() method, no need to get a char array from it. Your else if statement only allows arguments that are 7 in length. Your two if statements that are checking the length are conflicting with eachother.
     
  3. Offline

    Waffles87

    It looks like this line:

    if(factionName.toCharArray().length==7){

    is making it so that the 2nd argument needs to have exactly 7 characters for this work. I think you can just do this:

    if(factionName.toCharArray().length > 7){
    p.sendMessage(ChatColor.RED + "Too many characters .... !");
    }else {
    factions.add(factionName);
    p.sendMessage(ChatColor.GREEN + "Faction " + factionName + " successfully created!");
    plugin.savePlayerFactions();
    }

    Uhh sorry that came out so illegible...

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

    teej107

    Condolent
    Yes that is impossible to read. Don't try to read it.
     
  5. Offline

    Condolent

    Waffles87 That did it! I feel so blind atm.. Guess it's just due to the fact that I'm kind of loopy due to no sleep xD
     
Thread Status:
Not open for further replies.

Share This Page