I tryng to modify the reveivers of a message on MessageChannelEvent.Chat but this message is not sent to console. I using this way:
MutableMessageChannel msgCh = MessageChannel.TO_CONSOLE.asMutable();
...
//a loop to add the player i want to receive
msgCh.transformMessage(sender, player, buildMessage(stringMessage), ChatTypes.SYSTEM);
...
event.setChannel(msgCh);
But this send only to players, not to console… why?
transformMessage doesn’t actually have any side effects. It simply, well, transforms a message. For instance, some plugin might use custom chat formatting for different users. I myself use it in Boop to highlight the name. What you’re looking for is addMember.
The players receive the message correctly, excpet console.
Using transformMessage works without addMember, but i have tested without change the channel and when i only fire, console dont get the message, only players. Its really anyoing.
Instead to fire the event, i tested MutableMessageChannel#send(Text) and this sent msg to all including console. The question is if this way other plugins can listen to chat message and modify, or in other words, if this fire the MessageChatEvent?
Again, transformMessage has zero side effects. Its sole purpose is to slightly modify any given message to fit its recipients. It does not modify the channel in any way. If you want to send a message to a group of players plus the console, then the easiest way is to make a List<MessageReceiver>, add all the players plus Sponge.getServer().getConsole(), and use MessageChannel.fixed() to create the channel.
This line here does literally nothing. It transforms a message for a recipient. It does not send a message, it does not modify the channel’s recipients, it does not do anything other than returning a modified Text object. And there’s a much simpler way to go about this. Look at Boop: Using a channel and the channel itself.
It still doesn’t do anything. It’s basically a converter method; takes a Text in and spits another one out. Calling it on your own produces no result except a modified Text (which you throw away); it’s called automatically by the send() method.
Well, no, it does it over here
If you don’t believe me, that it does nothing, try commenting out the three lines that call it in UCMessages, and see if the plugin behaves exactly the same.