-2

I want to make a value in my config.properties for example like this:

blocked_names=Filon,Alron,Kren

or

blocked_names="Filon","Alron","Kren"

Every name will be read separately and it will be checked if the name is valid or not. Here is line where name is checked but it works only if one name is added

if (nick.equals(config.getProperty("blocked_names"))){ 
                info_info.setText("This name is blocked!");
                return;
        }

Do you know how should I make this to work fine ? Sorry for my English but I am still learning :)

HMD
  • 468
  • 1
  • 5
  • 21
Barry
  • 57
  • 4

1 Answers1

0

You need to split the value of blocked_names into an array of strings and then iterate the array.

Do it as follows:

String [] blockedNames = config.getProperty("blocked_names").split(",");
for(String name: blockedNames) {
    if (nick.equals(name.replace("\"", ""))){// Remove " from name
        info_info.setText(name + " is blocked!");
        return;
    }
}
halfer
  • 19,824
  • 17
  • 99
  • 186
Arvind Kumar Avinash
  • 71,965
  • 6
  • 74
  • 110