You can simply cancel the event, and then send a message to all the players by sending one player a different custom message.
For instance:
Player ply = (player who name is mentioned)
String message = "<message>"
on.playNote(on.getLocation(), Instrument.PIANO, Note.natural(1, Tone.A));
String s = message.replaceAll(ply.getName(), ChatColor.GOLD + ChatColor.UNDERLINE + ply.getName());
ply.sendMessage(s);
So your event might look like this:
@EventHandler
public void onChat(AsyncPlayerChatEvent e){
String message = e.getMessage();
e.setCancelled(true);
for(Player on : Bukkit.getOnlinePlayers()){
if(message.contains(on.getName())){
String newMessage = message.replaceAll(on.getName(), ChatColor.BLUE + ChatColor.UNDERLINE + on.getName() + ChatColor.WHITE);
on.sendMessage(newMessage);
on.playNote(on.getLocation(), Instrument.PIANO, Note.natural(1, Tone.A));
}
else{
on.sendMessage(message);
}
}
}
source
share