Solved How to create a formatted chat message?

Discussion in 'Spigot Plugin Development' started by Nuubles, Apr 5, 2021.

  1. How would it be possible to send a player a message as if it was sent by another player? This is needed because the client may want to only display commands or has some players blocked (p). Currently the chat is heavily formatted (with hoverable ranks, hoverable player names, each player receives a translated messages in their own language) using TextComponent, and is being sent with player.sendMessage(). Although this works, it does not follow any of the settings defined by the users client and bypasses them.

    I suppose I'll have to use packets, but what packet (couldn't find any from the javadocs) should I use and how would I set a formatted TextComponent to the packet as the message?

    The results of the formatting are stored in a HashMap<Player,BaseComponent> structure named components, currently the message is being sent with the following code:
    Code (Java):
    // loop each recipient and send the message
    for(Entry<Player, BaseComponent> pb : components.entrySet())
        pb.getKey().spigot().sendMessage(pb.getValue());
     
    #1 Nuubles, Apr 5, 2021
    Last edited: Apr 5, 2021
    • Like Like x 1