quarry icon indicating copy to clipboard operation
quarry copied to clipboard

How do i construct a translation text component

Open ajh123 opened this issue 3 years ago • 2 comments

So in my factory i have

    def send_chat(self, message, sender=None, isSystem=0):
        if sender is None:
            sender = UUID(int=0)

        for player in self.players:
            player.send_packet(
                "chat_message",
                player.buff_type.pack_json(message), # same result with pack chat
                player.buff_type.pack('B', isSystem),
                player.buff_type.pack_uuid(sender))

And in my protocol

    def packet_chat_message(self, buff):
        # When we receive a chat message from the player, ask the factory
        # to relay it to all connected players
        p_text = buff.unpack_string()
        self.factory.send_chat(self.construct_chat(self.display_name, self.uuid, p_text),
                               sender=self.uuid)

    def construct_chat(self, display_name, uuid, message):
        return str('{"translate":"chat.type.text","with":[{"text":"'+display_name+'","clickEvent":{"action":"suggest_command","value":"/msg '+display_name+' "},"hoverEvent":{"action":"show_entity","value":"{"id":"'+str(uuid.to_hex())+'","name":"'+display_name+'"}}"},"insertion":"'+display_name+'"},{"text":"'+message+'"}]}')

However when the chat message does get relayed, all the json get displayed in the. chat box too. I want it to appear the result of construct_chat appear like a normal chat message on a vanilla server.

ajh123 avatar Jul 24 '21 16:07 ajh123

This is based of this

ajh123 avatar Jul 24 '21 17:07 ajh123

the string is getting escaped; example Default responce: b'\xc6\x02{"translate":"chat.type.text","with":[{"insertion":"PLAYER_NAME","clickEvent":{"action":"suggest_command","value":"/tell PLAYER_NAME "},"hoverEvent":{"action":"show_entity","contents":{"type":"minecraft:player","id":"f593819c-e51e-315e-a06e-000000000000","name":{"text":"PLAYER_NAME"}}},"text":"PLAYER_NAME"},"a"]}\x00\xf5\x93\x81\x9c\xe5\x1e1^\xa0n\t1\xb6\x92\x12\x80' your code: b'\xf8\x02"{\"translate\":\"chat.type.text\",\"with\":[{\"insertion\":\"PLAYER_NAME\",\"clickEvent\":{\"action\":\"suggest_command\",\"value\":\"/tell PLAYER_NAME \"},\"hoverEvent\":{\"action\":\"show_entity\",\"contents\":{\"type\":\"minecraft:player\",\"id\":\"f593819c-e51e-315e-a06e-093100000000\",\"name\":{\"text\":\"PLAYER_NAME\"}}},\"text\":\"PLAYER_NAME\"},\"a\"]}"\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00' PACK as chat and make sure not to have escaping problems

(edit) try doing '{"translate":"chat.type.text","with":[{"'

davidawesome02 avatar Jun 11 '22 23:06 davidawesome02