No MessageEvent or MessageChannelEvent when receiving specific messages

Hello,

I was making a chat plugin and made a listener.
If I join the server, leave or send a message, the listener is triggered,
but if I or console use '/say ’ or '/tell ',
there is only a CommandSendEvent, no MessageEvent or MessageChannelEvent.

When I use a command, and I get a response (like ‘Unknown Command’ or 'Teleported to '),
the listener isn’t triggered too.

So, what I want, is a listener that will be triggered when there is something added to a players chat screen. This could be:

  • Normal Messages
  • Join and Leave Messages
  • /tell or /say mesages
  • Command Responses

How can I do that?

There should be a MessageChannelEvent for every message sent to a player.
It was added in this pull request:

Maybe you’re on an old version? It should work on recent API 5 and API 6 builds.
As an aside, this is what I make use of in my Chat UI plugin.

I was working with a 1.8.9 server, because 1.12 crashed because of to little RAM.

1.8.9 is unsupported. You’ll need to update to 1.10.2 or 1.11.2 to get this feature.

I will give it a try.

It works for 1.10.2, but the server crashes because of too little RAM :joy:.

How much RAM does the machine running the server have? I suggest having at least 2GB to run the server. Make sure to give java a reasonable amount with -Xms2G -Xmx2G

Currently I have 1,9 RAM.

My plugin is working, but there are 3 ‘bugs’:

  1. If I use ‘/say’, there is no MessageChannelEvent.Chat triggered, only a MessageChannelEvent, so I cannot use ‘event.getRawMessage()’.

  2. If I use ‘/tell <player> <msg>’, the raw message isn’t just ‘<msg>’, but: 'Server whispers to you: ’

  3. How can I see the difference between a MessageChannelEvent triggered by ‘/tell’ and MessageChannelEvent triggered by ‘/help’ or ‘/gamemode’?

Here are some answers for your questions, as best as I can get them:

  1. You can use event.getMessage().toPlain() to read the text as a String, and you can parse that string to determine what you want from there.

  2. That’s the message which is sent to the client, not the message pre-formatting. Any message attained this way will be what the client sees, not what the client sends.

  3. Since they all call the same method to send the player the message, there is no surefire way of knowing what triggered the event. Your best bet is to look at the message that is sent to the player and try to determine it based on that.

  1. But why does ‘/say’ not trigger a MessageChannelEvent.Chat? It triggered a MessageChannelEvent now. Should I open an issue?

  2. I don’t like to do that in that way :joy:

  3. That would not be 100% working :expressionless:

If you want to change specifically those commands, i would suggest overwriting them with your own commands.
However you did not tell us what exactly you want to do, so beware of the XYProblem ^^

Maybe I can explain it with some pictures:

I want to make a chat like above.
As you can see, that worked.

This is bug 3:

You see that the help-command will be formatted, but I only want commands like /tell and /say.

Then only format MessageChannelEvent.Chat and for /tell and /say create two new commands (with the same labels: ‘tell’ and ‘say’) wich do the same, but formatted in your way.

I think that will fix all my bugs,

I also want to implement a Party System, but that is solved too.

Should I make a new Plugin for Partjes or build it in my Chat plugin?