Question Changing a message for a specific player AsyncChatEvent

neverlessy

New member
Nov 27, 2022
1
0
1
How can I change the message only for a specific player in an AsyncChatEvent?

For example, I have two players. player 1 and player 2

I want the message to change only for player 2

I tried to remove the player from the list of recipients and send another message to him, but then it most likely could affect someone else's plugins changing the chat. What should I do?
 
Version Output
1.19.2
Last edited:

Notro

New member
Aug 23, 2023
9
0
1
Hello, you can do the following:
public class AsyncChatListener implements Listener { @EventHandler public void onAsyncPlayerChat(AsyncPlayerChatEvent event) { event.getRecipients().stream() .filter(player -> player.getUniqueId() == /* insert your wanted player's uniqueId here */) .forEach(player -> event.setMessage(/* insert your wanted message here */)); } }