Solved Server / Plugin message sent event

Discussion in 'Spigot Plugin Development' started by Bjorno43, Feb 7, 2020.

  1. Which event is being triggered when the server or a plugin sends a message to a player?

    I know the AsyncPlayerChatEvent triggers when a player sends a message to the chat. And you can also use that event to figure out who received it.

    But that event doesn't get triggered when the server or some plugin sends a message. Therefor I can't use it to detect if a player got a message from either of those. Anyone an idea which event I can use to detect this? And obviously also access the message that got sent?
     
  2. SteelPhoenix

    Moderator

    What are you trying to achieve? It sounds like an x/y problem as mentioned before.

    The only way to intercept (all) outgoing chat messages to the client is by listening to outgoing chat packets but this also includes regular chat messages, and stuff like the text above your hotbar (though this can be seperated using the position byte)
     
    • Agree Agree x 2
    • Informative Informative x 1
  3. You can listen ALL messages via ProtocolLib / packets - PacketType.Play.Server.Chat. Outdated(?) example. And yeah, like SteelPheonix said, regular chat is included.
     
    • Informative Informative x 1
  4. I'm working on a chatsystem plugin that allowes users to switch between channels using (clickable) tabs. Those tabs always need to remain at the bottom of the chat, obviously. In order to achieve this, I'm catching messages with the AsyncPlayerChatEvent and make sure they end up in the correct channel / above the tabs. That all works perfectly fine.

    The trouble starts when different kinds of messages appear. They push the tabs up as I'm unable to catch them. That alone wouldn't be that much of an issue, but because the tabs are pushed back to the bottom as soon as AsyncPlayerChatEvent triggers, these other messages are simply removed. Hence I'm trying to find a way to catch those and put them in their own channel to prevent any futher issues.
     
    • Informative Informative x 1
  5. Thanks everyone! Seems protocollib is the way to go to solve this issue :)
     
  6. I'm not sure what's going on, but it seems those messages don't trigger ProtocolLib's client chat packets. I've tried:
    Code (Java):
    protocolManager.addPacketListener(new PacketAdapter(this,
            ListenerPriority.NORMAL,
            PacketType.Play.Client.CHAT) {
        @Override
        public void onPacketReceiving(PacketEvent event) {
            System.out.println(event.getPacketType().toString());
        }
    });
    It does trigger whenever the player receives a message from another player. But it doesn't on any other messages. It didn't trigger using "say test" from within the console. Nor did it when the player went AFK message triggered or any message from a plugin appeared. Anyone an idea?

    Edit:

    Perhaps if anyone knows how to just create a general packet listener that returns me any packet type, I can just check the console which packet type(s) are being triggered?
     
  7. Use PacketType.Play.Server.CHAT
     
  8. It should be on packet sending not recieving.
     
  9. Ye you guys were right. Strangely enough it seems the sender of those messages are actually the players themselves. The packets do contain some data like b=SYSTEM it seems. Just gonna have to figure out how to get that out of there and I'm set :)
     
  10. This may help.
     
    • Winner Winner x 1
  11. Thanks that solved the issue. I can now catch all messages. Now just need to make sure only the intended player receives them and not everyone xD