Solved How to send a message to a player from a set?

Discussion in 'Spigot Plugin Development' started by devonzimmi, Nov 7, 2019.

Thread Status:
Not open for further replies.
  1. I am trying to send a message to a new set of players that I gathered from event.getRecipients(). I am trying to iterate through the set and send a message to each one inside the new set. For some reason, I am not receiving a message even though I am listed in the set.

    How can I send a message to every player inside of a set?
    I get zero errors. It just doesn't send anything.

    Here is my current code (broken):
    Code (Java):
    Set<Player> filteredUsers = e.getRecipients();
    filteredUsers.removeIf(unfilteredUsers::contains);

    filteredUsers.forEach((player) -> {
       player.sendMessage(String.join(" ", msgArray));
    });
    I have also tried this:
    Code (Java):
    for(Player player : filteredUsers) {
       player.sendMessage(String.join(" ", msgArray));
    }
    Why isn't player.sendMessage(); actually sending a message??
     
  2. what the String.Join message?
     
  3. I've split the message into an array. Then I join it back once im done editing it. That part works fine. The only problem is sending a message to a recipient in filteredUsers.
     
  4. I think getRecepients() can have some weird behavior, try changing to filteredUsers to new HashSet<>(Bukkit.getOnlinePlayers()). It will be guaranteed to have all player's inside it, and it'll definitely be mutable
     
    • Useful Useful x 1
  5. That fixed it!! Thank you so much!!
     
Thread Status:
Not open for further replies.