Chat

Discussion in 'Plugin Development' started by david123718, Sep 1, 2014.

Thread Status:
Not open for further replies.
  1. Offline

    david123718

    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.
     
  2. Code:
    public void onPlayerChat(PlayerASyncChatEvent e)
    {
      e.setCancelled(true);
    }
    //Give it a go.
    david123718
     
  3. Offline

    luigieai

    You at least know the basics java??
     
  4. Offline

    es359


    Missing your EventHandler annotation.
     
  5. Offline

    Ivan

    That would fully disable the chat event, blocking it from being logged in any way. I'd recommend doing it this way:
    Code:java
    1.  
    2. public void onPlayerChat(PlayerASyncChatEvent e)
    3. {
    4. e.getRecipients().clear();
    5. }
    6.  
     
  6. Offline

    david123718

    H
    how do i toggle it? Like contain the player
     
  7. Offline

    fireblast709

    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)
     
Thread Status:
Not open for further replies.

Share This Page