azalea_protocol/packets/game/
c_disguised_chat.rs1use azalea_buf::AzBuf;
2use azalea_chat::{
3 translatable_component::{StringOrComponent, TranslatableComponent},
4 FormattedText,
5};
6use azalea_protocol_macros::ClientboundGamePacket;
7
8use super::c_player_chat::ChatTypeBound;
9
10#[derive(Clone, Debug, AzBuf, ClientboundGamePacket, PartialEq)]
15pub struct ClientboundDisguisedChat {
16 pub message: FormattedText,
17 pub chat_type: ChatTypeBound,
18}
19
20impl ClientboundDisguisedChat {
21 #[must_use]
23 pub fn message(&self) -> FormattedText {
24 let sender = self.chat_type.name.clone();
25 let content = self.message.clone();
26 let target = self.chat_type.target_name.clone();
27
28 let translation_key = self.chat_type.chat_type.chat_translation_key();
29
30 let mut args = vec![
31 StringOrComponent::FormattedText(sender),
32 StringOrComponent::FormattedText(content),
33 ];
34 if let Some(target) = target {
35 args.push(StringOrComponent::FormattedText(target));
36 }
37
38 let component = TranslatableComponent::new(translation_key.to_string(), args);
39
40 FormattedText::Translatable(component)
41 }
42}