How come user can't send chat but can still read others chat?

Discussion in 'Plugin Development' started by Eggspurt, Jun 25, 2015.

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

    Eggspurt

    Code:
    @EventHandler
       public void disableChat(AsyncPlayerChatEvent event) {
         Player player = event.getPlayer();
         if(map.containsKey(player.getName())) {
           event.setCancelled(true);
         }
       }
    It cancels the event for the user in the hashmap, like it should but the user can still see other Chat Messages, how would I make it so user doesn't receive messages either?
     
  2. Offline

    Boomer

    the chat event is only being fired for the player sending it.

    If you send a chat message, your are the player in event.getPlayer()
    if I send amessage, i am the player in event.getPlayer()

    if my name is in your map, it will simply block messages that I send. Messages anyone else sends, if not in the map, go through fine.
    Its just a one-way chat event "Allow this player to speak or not"
    Doesn't influence listening. For that, you'd have to replace all chat events with your own chat-message broadcaster that sends a message to each player or not, in a loop. Have fun with formatting that string, since you'd be going contrary to any work you've done setting up a chat formatting system, its not easy. You'd be sending not just the message, but the prefixes, colors, etc to each player
     
  3. Offline

    xTigerRebornx

    @Boomer Untrue, you can change the recipients of the chat event using getRecipients()

    @Eggspurt You can try looping through the recipients of the message, and if their name is in the Map, remove them from the recipients (you'd need to do this after looping to prevent a ConcurrentModificationException)
     
  4. Offline

    Boomer

    Sweet. Much more effective.
    When done right.
     
Thread Status:
Not open for further replies.

Share This Page