Solved How i can take the message from the chat?

Discussion in 'Spigot Plugin Development' started by Giorgino, Jan 28, 2020.

  1. Hi, does anyone know how I can take the message that a player is typing in the chat but without having it sent?
     
  2. You can't.
    Before the message is sent, no information will be passed to the server, so there is no way of achieving what you want to do
     
    • Useful Useful x 1
  3. Ah ok.. But is it possible to take the message but without showing it to the other players?
     
  4. That is indeed possible (obviously only after the player has sent the message).
    You would have to listen to the PlayerChatEvent. There you can get the message and do whatever you want to do with it, especially sending it only to you and not other players.
     
    • Winner Winner x 1
  5. SteelPhoenix

    Moderator

    with AsyncPlayerChatEvent you can cancel the event and modify the recipiants
     
    • Winner Winner x 1
  6. If player sends a message, you can make it so nobody sees it but you can of course take it
     
    • Winner Winner x 1
  7. Thanks so much.
     
  8. drives_a_ford

    Moderator

    Oh, you're one of those:
    Code (Java):

                if (PlayerChatEvent.getHandlerList().getRegisteredListeners().length != 0) {
                    // Evil plugins still listening to deprecated event
     
    (NMS source, PlayerConnection class)
     
    • Winner Winner x 3
  9. I meant the Async event, I have not joined the dark side yet