0

i get this wierd bug. i have this code, which compares the password in the config file with the given argument:

if(label.equalsIgnoreCase("login")){
if(getConfig().getString("players."+p.getName()+".password") == args[0]){
p.sendMessage("OK!");
} else {
p.sendMessage("NOT OK!");
}

but no matter what, it ouputs "NOT OK!", what am i doing wrong? ive tried to debug it, to send a message with the given argument and what it sees in the config file. they were both the same!

1 Answers1

0

You should try

String configValue = config.getString("players."+p.getName()+".password");
if(configValue != null && configValue.equals(args[0]) { // maybe you just need to change the index of args[], depending on if your command looks like /xy <password> or /xy z <password>
    p.sendMessage("OK!");
} else {
    p.sendMessage("NOT OK!");
}
mezzodrinker
  • 998
  • 10
  • 28
  • Thanks, that worked, it had some typing issues but i fixed it! –  Apr 25 '14 at 10:29
  • You're welcome. For reasons why to use ```.equals()``` instead of ```==``` when it comes to Strings, try out this question: [How do I compare Strings in Java](http://stackoverflow.com/questions/513832/how-do-i-compare-strings-in-java) – mezzodrinker Apr 25 '14 at 21:54
  • By the way, the most common way of saying thanks here is accepting an answer (ticking the check mark). If you think the answer was useful, you can up-vote it as well (clicking the arrow up) – mezzodrinker Apr 26 '14 at 09:28