Event when player gets message in chat

Discussion in 'Plugin Development' started by RORAK, Mar 3, 2022.

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

    RORAK

    Hello, I want to somehow get an event every time player gets a new message in chat. It should include also command response messages like /summon command response.
    Code:
    // Somethink like
    public void onPlayerGetsChat(String message) {
         // do something
    }
    I also want to get the message with § color signs.
    If you know the answer, please give me a function that will register this function.

    Thanks a lot!
     
  2. Offline

    timtower Administrator Administrator Moderator

    @RORAK What do you want to do with it? Because you can't do that with events like this.
     
  3. Offline

    rudraksha007

    you will have to use packet Listener.... i don't think that is possible by any other way... just listen for outgoing ChatMessage Packet and do whatever u want... for the commands part, there is a PlayerSendCommandEvent
     
  4. Offline

    Lars Mars

    Yeah,
    like the user above told you:
    you need to implements a listener. For example:
    public class <class> implements Listener {
    @EventHandler
    public void onChat(<Eventname> <event variable>) {
    etc.
    }
    }

    here's a list with bukkit events : https://bukkit.org/threads/directory-list-of-events.112493/
     
  5. Offline

    timtower Administrator Administrator Moderator

    This does not work for command output though, as this is just chat
     
  6. Offline

    RORAK

    I would be extremely useful if you could tell me how, because I can't find it anywhere.

    I know, I want to make custom think, that calls this event to make the code more organized.

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Mar 5, 2022
  7. Offline

    timtower Administrator Administrator Moderator

    But what are you gonna do with it? How does the information in those messages help you?
     
  8. Offline

    RORAK

    I want to make chat logger for every player (where is every message player received in chat)
     
  9. Offline

    timtower Administrator Administrator Moderator

    Client does that already...
     
  10. Offline

    RORAK

    So how can i get it in my java code?
    I want to also log replies of commands lik /summon creeper (Creeper succesfully summon) or command replies from other plugins. (I want some object like Map<Player, List<String>>)
     
  11. Offline

    timtower Administrator Administrator Moderator

    Use UUID's instead.
    https://bukkit.org/threads/protocollib-get-the-content-of-the-message.478831/
    Still don't see any real usage for this though, so pretty curious how you are gonna use it.
     
  12. Offline

    RORAK

    Oh, that's it, I don't wanna use protocol lib, because my plugin has to be independent. So, is there a way to do it without protocol lib?
    I want to add feature to edit messages. Each message player sends will get special id, and will be saved in storage object for all players, who received the message. Then, the sender player can type '/e id message' and for every player who gets the message the chat will be cleared and the message history with changed message will be sent to player. I already have all objects to work with, I only need the event to log all of the messages player gets in chat.
    Hope you understand it.
     
  13. Offline

    timtower Administrator Administrator Moderator

    Protocollib makes it easy though, even the editing.
    Without it you need to remake the plugin for every version.
    Sender won't have a clue about which message is which id for a different user.
    By the time the id has been found theessage is gone already.
     
Thread Status:
Not open for further replies.

Share This Page