MessageChannel dont send to console

Hi,

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.

Humm… adding some debug codes, the message is not sent to console only if i fire the event.

I firing the event this way:

                  Sponge.getEventManager().post(
			    					SpongeEventFactory.createMessageChannelEventChat(
			    							Cause.source(UChat.plugin).named(NamedCause.notifier(src)).build(), 
			    							src.getMessageChannel(), 
			    							Optional.of(src.getMessageChannel()), 				    							
			    							new MessageEvent.MessageFormatter(Text.builder("<" + src.getName() + "> ")
			    		                            .onShiftClick(TextActions.insertText(src.getName()))
			    		                            .onClick(TextActions.suggestCommand("/msg " + src.getName()))
			    		                            .build(), msg), 
			    		                    msg, 
			    							false));

I got this example from Nucleus/SudoCommand.java at sponge-api/5 · NucleusPowered/Nucleus · GitHub

Firing MessageChannelEvent.Chat does not send any message to anyone, you must send the message using sendMessage

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.

What is the target ChatType ?

ChatType.SYSTEM

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.

I think no.

I using this way:

Created the channel: https://github.com/FabioZumbi12/UltimateChat-Sponge/blob/1.7.0/src/main/java/br/net/fabiozumbi12/UltimateChat/UCMessages.java#L65

Without #addmember and only using #transformMessage: https://github.com/FabioZumbi12/UltimateChat-Sponge/blob/1.7.0/src/main/java/br/net/fabiozumbi12/UltimateChat/UCMessages.java#L145

And then set on event: https://github.com/FabioZumbi12/UltimateChat-Sponge/blob/1.7.0/src/main/java/br/net/fabiozumbi12/UltimateChat/UCListener.java#L75

I need to set the message for each player because i adding some texts and placeholders for each recipient, and this way is working.


And in other point, is in this code i having the problem where the console dont receive the message: https://github.com/FabioZumbi12/UltimateChat-Sponge/blob/1.7.0/src/main/java/br/net/fabiozumbi12/UltimateChat/UCCommands.java#L241

Actually its comented the event part and i using the channel to send the message.

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.

I know, this is not to send the message, is only to modify, like this:

where only this player receives a yellow message with @ and is set using #transformMessage, other players a message without @ and all in blue.
The message is sent by event: https://github.com/FabioZumbi12/UltimateChat-Sponge/blob/1.7.0/src/main/java/br/net/fabiozumbi12/UltimateChat/UCListener.java#L75

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.

Ok man, ok, you are right ‘-’

That yellow name goes only to that player magically?

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.