So I don't understand what I've done wrong...

Discussion in 'Spigot Plugin Help' started by pairson, May 23, 2017.

  1. I'm developing a teams plugin, but don't exactly understand why this isn't working, they're both strings, and I want to make sure the variables are equal before allowing the person into the team, so I commented my code because it's sloppy as all hell. Please help me find what is wrong.

    // this is where I get the string for the if statement (from my config which is where data is stored)

    String check = plugin.getConfig().getString("teamsinfo." + team + ".pass");

    // pass is the users suggested password, check is the password stored with the team

    if (pass == check)
    {
    // this is just saving data to the config.
    plugin.getConfig().set("playerinfo." + p.getName() + ".inteam", true);
    plugin.getConfig().set("playerinfo." + p.getName() + ".team", team);
    plugin.getConfig().getStringList("teamsinfo." + team + ".members").add(p.getName());
    plugin.saveConfig();
    //sending the team join message to the faction (didnt test if it works)
    for (String all : plugin.getConfig().getStringList("teamsinfo." + team + ".members"))
    {
    Player player = (Player) plugin.getConfig().get("playerdata." + all + ".playername");
    player.sendMessage(ChatColor.RED + p.getName() + ChatColor.GRAY + "has joined your team.");
    }
    return true;
    }
    //this is where it makes it to every time, and doesn't use the if statement, though I've made sure they're equal to eachother
    p.sendMessage(ChatColor.RED + "Incorrect password.");
     
  2. Wrong section, please post your issue here: https://www.spigotmc.org/forums/spigot-plugin-development.52/

    1. If possible, don't check if a string is equal to something using "==", use ".equals()" instead.
    2. Replace this:
    Code (Text):
    plugin.getConfig().getStringList("teamsinfo." + team + ".members").add(p.getName());
    With this:
    Code (Text):
    List<String> members = plugin.getConfig().getStringList("teamsinfo." + team + ".members");
    members.add(p.getName());
    plugin.getConfig().set("teamsinfo." + team + ".members", members);
     
  3. Wrong section, yes, but it's a 2 second fix.

    You cannot compare strings like this:
    Code (Text):
    if(string1 == string2){ ... }
    // does not work
    Use this:
    Code (Text):
    if(string1.equals(string2)){ ... }
    // works
    if(string1.equalsIgnoreCase(string2)){ ... }
    // works, ignore's case
     
    • Like Like x 1
  4. Thats what i meant by
     
  5. You should also hash the password using bCrypt.