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

    vrox

    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:

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

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

    Then later I have:

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

    Code:
    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

    Jogy34

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

    vrox

    That fixed it! Thanks!
     
  4. Offline

    Jogy34

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

Share This Page