Mute Chat for one player

Discussion in 'Plugin Development' started by Robin Bi, May 27, 2014.

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

    Robin Bi

    It's me again ^^

    Still in my report-plugin, i want to mute chat for the player who reports someone, so he isn't annoyed by it. I know the PlayerChatEvent, and I know how to cancel it but this only prevents the user from chatting and doesn't make him not to receive any chat messages.
    Chat shall go on but the users who are reporting shall not receive it. I already have an ArrayList of everyone who's in "reporting mode".


    Hope you have some ideas ^^
     
  2. Offline

    1Achmed1

    What does it matter if he can see them if he can't say anything in the first place?
     
  3. Offline

    fireblast709

    Robin Bi there is event.getRecipients(), just be wary that it can be thrown using immutable sets (which do not support add/remove)
     
  4. Offline

    Robin Bi

    1Achmed1 He will enter this "muted mode" when he is currently reporting a player. When reporting, the user must enter a reason into the chat and i don't want him to be annoyed by any chat messages. So i need to silence the others, but only for him.

    fireblast709 Thanks, but i don't really get what you mean there....
    Do you mean
    Code:java
    1. @EventHandler
    2. public void onChat(PlayerChatEvent e) {
    3. Set<Player> recipients = e.getRecipients();
    4. }

    ? And if so, how do i deal with the set i got? Maybe you can tell me what to google? :3
     
  5. Offline

    fireblast709

    if any of the recipients has reported e.getPlayer(), you want to remove them from the Set
     
  6. Offline

    Robin Bi

    fireblast709 Thanks, i got it to work, but it throws errors i can't correct...

    This is the error the console gives me.


    And the ChatEvent-class has this:
    Code:java
    1.  
    2.  
    3.  
    4.  
    5.  
    6.  
    7.  
    8.  
    9.  
    10. @SuppressWarnings("deprecation")
    11. public class ChatEvent implements Listener {
    12.  
    13.  
    14.  
    15. @EventHandler
    16. public void onChat(PlayerChatEvent e) {
    17. Set<Player> recipients = e.getRecipients();
    18. for (Player p : recipients) {
    19. if (ChatNabler.isReporting(p.getName())) recipients.remove(p);
    20. }
    21. }
    22. }
    23.  

    (Added empty lines so that they fit to the error log.)


    Thanks for your help, hope you go on helping meh :3
     
  7. Offline

    fireblast709

    Robin Bi ConcurrentModificationException occurs because you edit the Set while looping over it. Instead, use an Iterator:
    Code:java
    1. Iterator<Player> it = recipients.iterator();
    2. Player p;
    3. while(it.hasNext())
    4. {
    5. p = it.next();
    6. if(ChatNabler.isReporting(p.getName()))
    7. it.remove();
    8. }
     
    Robin Bi likes this.
  8. Offline

    Robin Bi

Thread Status:
Not open for further replies.

Share This Page