Hello! I'm developing a plugin so a player cannot see chat. But I do not know how to do that. Can anyone give me a example on how to do it? I am using Eclipse. and Is not allowed to place a command or speak.
Code: public void onPlayerChat(PlayerASyncChatEvent e) { e.setCancelled(true); } //Give it a go. david123718
That would fully disable the chat event, blocking it from being logged in any way. I'd recommend doing it this way: Code:java public void onPlayerChat(PlayerASyncChatEvent e){ e.getRecipients().clear();}
david123718 create a Set<UUID> field, add their UUID if they are blocked and remove their UUID if you want to unblock them. Then in the AsyncPlayerChatEvent (surprisingly enough no one has corrected that) you simply loop over the recipients, and remove them if their UUID is in the Set. Do note, when you simply follow this you will most certainly end up with a ConcurrentModificationException. To loop & remove from any collection, use Iterators (at least, that would be the most clear solution out of the efficient ones)