Yes. The best way I can think of it ATM is; 1. On PlayerChatEvent, store the message into a variable, along with the display name of who sent it 2. Set the message to null 3. Get a list of all nearby players 4. Send the message to those players
Actually, just setting the recipients is a better approach than either of the above. Code: event.getRecipients().clear(); for (Player player : aCollectionOfNearbyPlayers) { event.getRecipients().add(player); } Edit: Ignore this, it's more optimal to do as V10lator said above.
makskay So it's better to clear and re-populate the recipients of the event instead of cancelling it and sending it by hand...? Please explain why (hint: have a look here before you reply).
In my defense, there is one reason I can think of to directly alter the senders instead of canceling the event and resending it to each player: to maintain compatibility with other chat plugins that alter message formatting, especially when these plugins are listening at a higher priority than your own. Messages sent to players with Player.sendMessage() don't throw AsyncPlayerChatEvents and as such can't be processed by other formatting plugins, which can break compatibility with plugins like EssentialsChat that embed tags in messages early on and replace those tags with color codes at a higher priority. Since I'm currently working on a chat plugin and have to maintain compatibility with others while altering message recipients, I'm used to doing it the way I suggested above. If you're not concerned about conflicts with other plugins then V10lator's method is indeed way more optimized.
From some other thread: EntityLocation entityloc = new EntityLocation(player); for (Player p : player.getWorld().getPlayers()) { Integer distance = entityloc.getDistance(p); if(distance < (your number here)){ .... }