From 797dd9171088cd697b3c95663cbbc65b05315414 Mon Sep 17 00:00:00 2001 From: mat Date: Mon, 4 Dec 2023 14:25:10 -0600 Subject: revert packet name to Disguised and make it more like ChatPacket::Player --- .../game/clientbound_disguised_chat_packet.rs | 35 ++++++++++++++++++++-- azalea-protocol/src/packets/game/mod.rs | 2 +- 2 files changed, 34 insertions(+), 3 deletions(-) (limited to 'azalea-protocol/src') diff --git a/azalea-protocol/src/packets/game/clientbound_disguised_chat_packet.rs b/azalea-protocol/src/packets/game/clientbound_disguised_chat_packet.rs index 00e0d577..e1ccff7e 100644 --- a/azalea-protocol/src/packets/game/clientbound_disguised_chat_packet.rs +++ b/azalea-protocol/src/packets/game/clientbound_disguised_chat_packet.rs @@ -1,10 +1,41 @@ use super::clientbound_player_chat_packet::ChatTypeBound; use azalea_buf::McBuf; -use azalea_chat::FormattedText; +use azalea_chat::{ + translatable_component::{StringOrComponent, TranslatableComponent}, + FormattedText, +}; use azalea_protocol_macros::ClientboundGamePacket; +// A disguised chat packet is basically the same as a normal +// [`ClientboundPlayerChatPacket`], except that it doesn't have any of the chat +// signing things. Vanilla servers use this when messages are sent from the +// console. #[derive(Clone, Debug, McBuf, ClientboundGamePacket, PartialEq)] -pub struct ClientboundMaskedChatPacket { +pub struct ClientboundDisguisedChatPacket { pub message: FormattedText, pub chat_type: ChatTypeBound, } + +impl ClientboundDisguisedChatPacket { + /// Get the full message, including the sender part. + #[must_use] + pub fn message(&self) -> FormattedText { + let sender = self.chat_type.name.clone(); + let content = self.message.clone(); + let target = self.chat_type.target_name.clone(); + + let translation_key = self.chat_type.chat_type.chat_translation_key(); + + let mut args = vec![ + StringOrComponent::FormattedText(sender), + StringOrComponent::FormattedText(content), + ]; + if let Some(target) = target { + args.push(StringOrComponent::FormattedText(target)); + } + + let component = TranslatableComponent::new(translation_key.to_string(), args); + + FormattedText::Translatable(component) + } +} diff --git a/azalea-protocol/src/packets/game/mod.rs b/azalea-protocol/src/packets/game/mod.rs index 0b7fb7ee..c806f21d 100755 --- a/azalea-protocol/src/packets/game/mod.rs +++ b/azalea-protocol/src/packets/game/mod.rs @@ -255,7 +255,7 @@ declare_state_packets!( 0x19: clientbound_damage_event_packet::ClientboundDamageEventPacket, 0x1a: clientbound_delete_chat_packet::ClientboundDeleteChatPacket, 0x1b: clientbound_disconnect_packet::ClientboundDisconnectPacket, - 0x1c: clientbound_disguised_chat_packet::ClientboundMaskedChatPacket, + 0x1c: clientbound_disguised_chat_packet::ClientboundDisguisedChatPacket, 0x1d: clientbound_entity_event_packet::ClientboundEntityEventPacket, 0x1e: clientbound_explode_packet::ClientboundExplodePacket, 0x1f: clientbound_forget_level_chunk_packet::ClientboundForgetLevelChunkPacket, -- cgit v1.2.3