Solved Looping through players in config?

Discussion in 'Plugin Development' started by killerman747, Apr 23, 2014.

Thread Status:
Not open for further replies.
  1. Offline

    killerman747

    Hello, I was wondering how I would go about looping through a List<String> to find online players that are in that list then do something like send them a message? Here is what I have:
    Code:java
    1. List<String> Members = plugin.getConfig().getStringList(".Plugin.List");
    2. for(Player onlinePlayers : Bukkit.getOnlinePlayers()){
    3. if(Members .contains(onlinePlayers)){
    4. onlinePlayers.sendMessage(ChatColor.GREEN + "Your on the list!");
    5. }
    6. }

    Any help?
     
  2. Offline

    BillyGalbreath

    The code you have should work. But the path node is syntactically wrong. It cannot have a leading period.
     
  3. Offline

    coasterman10

    You should delete the leading period on ".Plugin.List". Also, you are checking if a List<String> contains a Player, which will never return true. You should instead check if it contains the player's name: onlinePlayers.getName()
     
  4. Offline

    killerman747

    coasterman10
    So I changed my code like you said but still nothing seems to happen to the players on the list.
    Code:
    List<String> Members = plugin.getConfig().getStringList("Plugin.List");
                        for(Player onlinePlayers : Bukkit.getOnlinePlayers()){
                            if(Members .contains(onlinePlayers.getName())){
                                onlinePlayers.sendMessage(ChatColor.GREEN + "Your on the list!");
                            }
                        }
    Any ideas?
     
  5. Offline

    BillyGalbreath

    Debug messages help with situations like this. Use System.out to print to console the contents of Members to see if its even reading the config. Your config structure of may not be what you think it is.

    System.out.println("Members: " + Members);
     
  6. Offline

    BillyBobJoe168

    From how you have plugin.getConfig(), I can see this is another class, probably a Player listener or something. Are you registering it? Also, I believe it is Bukkit.getServer().getOnlinePlayers(). You forgot the .getServer() part.
     
  7. Offline

    coasterman10

    getServer() is redundant. A lot of methods in the Bukkit class are delegated to the server automatically.
     
  8. Offline

    Zethariel

    Echo out the members list. Also post full classes and what does the config have inside.
     
  9. Offline

    killerman747

    BillyBobJoe168
    Wow...I feel stupid. I forgot to add another period to break down into the next section of the config...thanks for making me double check my self.
     
Thread Status:
Not open for further replies.

Share This Page