onChat listener only if player typed

Hi there,

Currently I’m developing an multiserver chat solution for our network but I run into an issue with the onChat function.
I’ve created an onChat listener (as below)

public void onChat(MessageChannelEvent.Chat event) {
	String input = TextSerializers.FORMATTING_CODE.serialize(event.getMessage().toText());

But this also sends stuff to our relay which is not needed, how can I check if the message came from an player entity?

Nevermind found it!

Solution was in topic [SOLVED] PlayerChatEvent event - #4 by Flibio

Dont’ forget that you can add onto the topic with using filters:

public void onChat(MessageChannelEvent.Chat event, @Root Player player) {
  String input = Text.... // blah blah blah
1 Like

Ok, so If I add that extra param into the function is will only be invoked upon an user chat?
So if it has another Cause then an player it will be ignored?

Yes, read Event Filters — Sponge 7.2.0 documentation