My loop is only checking the first item of the array, which makes my code fail each time:
String igitems = "IgnoredItems";
String items = getConfig().getString("IgnoredItems.itemid");
items = items + args[0] + ",";
String[] myarray = items.split(",");
for(String fitem : myarray) {
if(!fitem.equals(args[0])){
getConfig().set(igitems + ".itemid", items);
saveConfig();
reloadConfig();
sender.sendMessage(prefix + ChatColor.GREEN + "Added " + ChatColor.GOLD + args[0] + ChatColor.GREEN + " to ignore list.");
break;
} else {
sender.sendMessage(prefix + ChatColor.RED + "Item is already in the list");
break;
}
}
If I add system.out.print(myarray);
after String[] myarray = items.split(",");
it shows the entire array, which is right:
1:0
2:0
5:0
8:0
5:0
But, when I add system.out.print(fitem);
after for(String fitem : myarray){
it shows only the first item from the array (1:0) wich makes my code fail almost each time except if it's the first item.