boogzey 1 Share Posted August 31, 2018 How can I loop over my friends list and check if a friend is online? Or rather, how can I enumerate the number of online friends I have at a particular time? I've instantiated friend like so: final Friend onlineFriends = new Friend(Client.getClient(), true); Let's say I have a list of players, p. I loop over my list of players and add them to my friends list. After that, how can I check which of them are online? Here's what I'm currently using to add them. for (String p: users) { log("Attempting to add (" + p + ") "+ " to list "); sleepUntil(() -> friend.addFriend(p), 10000); if(friend.haveFriend(p)){ log("Successfully added: " + p); } Link to comment Share on other sites More sharing options...
Milasoft 202 Share Posted August 31, 2018 You don't have to instantiate Friend. To add a player to your friends list just use: getFriends().addFriend(Player); Verify they are added with: getFriends().haveFriend(playerName); And to check if they are online... for(Friend f : getFriends().getFriends()) { if(f.isOnline()) { //friend is online } } Link to comment Share on other sites More sharing options...
boogzey 1 Author Share Posted August 31, 2018 24 minutes ago, Milasoft said: You don't have to instantiate Friend. To add a player to your friends list just use: getFriends().addFriend(Player); Verify they are added with: getFriends().haveFriend(playerName); And to check if they are online... for(Friend f : getFriends().getFriends()) { if(f.isOnline()) { //friend is online } } Perfect, thank you! Link to comment Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.