Solved List<String> Loop Strings not matching strings?

Discussion in 'BungeeCord Plugin Development' started by Voidane, Sep 9, 2019.

  1. Here's what I get from the config of what world I'm placing in and what worlds I have denied in the config
    Code (Text):
    [17:16:06 INFO]: world == world These do not Match
    [17:16:06 INFO]: a == world These do not Match
    [17:16:06 INFO]: a == world These do not Match
    Here is what i'm using to test it
    Code (Java):
    java.util.List<String> list = main.getConfig().getStringList("Effects Denied Worlds");
            for (String nameString : list) {
                if (nameString == e.getBlock().getWorld().getName()) {
                    Bukkit.getServer().getConsoleSender().sendMessage(nameString + " == " + e.getBlock().getWorld().getName() + ChatColor.DARK_RED+"  Match");
                    } else {
                        Bukkit.getServer().getConsoleSender().sendMessage(nameString + " == " + e.getBlock().getWorld().getName() + ChatColor.DARK_RED+" These do not Match");
                        }
                    }
    I also tried
    Code (Java):
    if (nameString.toLowerCase() == e.getBlock().getWorld().getName().toString().toLowerCase()) {
    That didnt work either...


    My config I have set
    Code (YAML):
    # Deny what worlds should not have access to the effects of block placement , and breaking , including sounds
    Effects Denied Worlds
    :
      - world
       - a
       - a
    Even tho, world == world , ...... is a match right??, its saying its not. in which case is allowing every world on the server to be allowed to use the effects.
     
    #1 Voidane, Sep 9, 2019
    Last edited: Sep 10, 2019
  2. You should use equals when comparing objects and "==" when comparing primitive values
     
  3. ...and when comparing Enums.