How to remove brackets ( < > ) in the chat?

How to remove brackets ( < > ) in the chat?

in the ChatEvents use the ChatRenderer to set the format of the messages.

1 Like

I’m using 1.17 and I can’t find the setFormat function:

@EventHandler
        public void chatEvent(AsyncChatEvent e){

            TextComponent message = (TextComponent) e.message();

            e.renderer().render(
            e.getPlayer(),
            Component.text(ChatColor.BLUE+e.getPlayer().getName()),
            Component.text(" : ")
                    .append(e.message()), Audience.audience());
        }

There is no more setFormat. You set your own implementation of ChatRenderer

Hey
I did it this way:

e.setCancelled(true);
for (Audience viewer : e.viewers()) {
       viewer.sendMessage("Your Chat Message");
}    

Of course there is a better way but yeah. This was the easiest for me.

Thanks for the answer!
I used the brodcast method:

    e.setCancelled(true);
    player.getServer().broadcast(
                    Component.text(player.getName()+" : "+"The Chat message")
            );

You should really use the ChatRenderer interface for this… it’s the direct replacement of the old setFormat method.

2 Likes

Give us an example how to do that then? I wont use it since the method im using now works.

I tried to figure it out but with no success. Can you provide us woth a little example?

Here’s an example using an implementation:

public class CustomChatRenderer implements ChatRenderer {
	@Override
	public Component render(Player source, Component displayName, Component message, Audience messageViewer) {
		return Component.text()  
            .append(displayName)
			.append(Component.text(" : "))
			.append(message)
            .build();
	}
}

And here’s an example using a lambda:

event.renderer((player, displayName, message, viewer) ->
	Component.text()  
        .append(displayName)
		.append(Component.text(" : "))  
		.append(message)
        .build()
)
2 Likes

This is not that necessary, but component builder should be used. In your case, message and “:” are childs of displayName, so they gonna inherit style from parent (displayName)

1 Like

Thank you so much! I really appreciate it.

You’re correct. I’ll edit my original post and fix that, thanks :smiley:

I understand how Components work i just didnt use the render stuff cause it was complicated at this time. Thanks for giving an example tho.