Comparing Name to String from the config

Discussion in 'Plugin Development' started by vrox, Sep 3, 2011.

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


    Im pretty new to Java, so sorry if this is a noob question.
    Is it possible to use an if-else statement to compare a username and a string from a config file?

    I used:

    attackerName victim.getName();
    So I have the actual username (victim is the Player who died), not the CraftPlayer thing. Im also using:

    blackCape config.getString("Black Cape""Vrox");
    in order to get the name from the config, which is currently 'Vrox'

    Then later I have:

    if (attackerName==blackCape){
    config.setProperty("Black Cape"defenderName);
    blackCape defenderName;
               "black cape owner changed!");
                } else {
               "attacker didnt have black cape! blackcape: ." blackCape +". attacker: ." attackerName +".");
    but it always goes to 'else' even when they are the same.
    The console returns:

    2011-09-03 11:43:30 [INFO] attacker didnt have black cape! blackcape: .Vrox. attacker: .Vrox.
    I added the .'s into the message to make sure there were no spaces, and there aren't any.

    Anyone know why it isn't working? Thanks in advance.
  2. Offline


    try using attackerName.equals(blackCape) instead of attackerName==blackCape
  3. Offline


    That fixed it! Thanks!
  4. Offline


    Ya you have to use .equals() when comparing two strings
Thread Status:
Not open for further replies.

Share This Page