Solved Check arguments returns false

Discussion in 'Plugin Development' started by Eskillu, Jun 4, 2016.

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

    Eskillu

    My check 2 arguments returns false even being equal!!!
    Code:
    if(args[0].equals(args[1])) {
                                player.sendMessage(tag + "§cAs suas senhas não estão iguais!");
    
    There is args 1 and 2 \/
    [​IMG]

    Please, help.
     
  2. Offline

    Lolmewn

    I don't think I understand what you would need this for :S
    Anyway, you check if they're equal, and then send the message. Aren't you supposed to check if they're not equal?
     
  3. Offline

    timtower Administrator Administrator Moderator

    Moved to plugin development.
     
  4. Offline

    TheFl4me

    He probably needs this for a plugin that requires players to log in ingame, and when creating their account they have to write the password twice to confirm it.

    And yes I agree with you, shouldnt it be sending that message when args[0] != args[1] ?
     
  5. Offline

    timtower Administrator Administrator Moderator

    @TheFl4me Always compare strings with equals, never with == or similar.
     
  6. Offline

    TheFl4me

    Oh thx, good to know ._.

    WHy is that if I may ask?
     
  7. Offline

    timtower Administrator Administrator Moderator

    Because it won't work if you use ==
     
  8. Offline

    Xerox262

    @TheFl4me ==/!= should only be used for null checks or to compare an enum/primitive, .equals() should be used for everything else, otherwise two of the same objects with the same data would not be equal.

    Strings are not enums or primitive therefore should use .equals() too.
     
  9. Offline

    Chiller

    To expand, the double equals checks reference equality so if this player you sent me equals that player I have saved and with strings even though it is the same value, it is different references.
     
Thread Status:
Not open for further replies.

Share This Page