azalea_protocol/packets/game/
c_disguised_chat.rs1use azalea_buf::AzBuf;
2use azalea_chat::{
3 FormattedText,
4 translatable_component::{PrimitiveOrComponent, TranslatableComponent},
5};
6use azalea_core::registry_holder::RegistryHolder;
7use azalea_protocol_macros::ClientboundGamePacket;
8
9use super::c_player_chat::ChatTypeBound;
10use crate::packets::game::c_player_chat::GUESSED_DEFAULT_REGISTRIES_FOR_CHAT;
11
12#[derive(Clone, Debug, AzBuf, PartialEq, ClientboundGamePacket)]
17pub struct ClientboundDisguisedChat {
18 pub message: FormattedText,
19 pub chat_type: ChatTypeBound,
20}
21
22impl ClientboundDisguisedChat {
23 #[must_use]
30 pub fn message(&self) -> FormattedText {
31 self.message_using_registries(&GUESSED_DEFAULT_REGISTRIES_FOR_CHAT)
32 }
33
34 #[must_use]
39 pub fn message_using_registries(&self, registries: &RegistryHolder) -> FormattedText {
40 let sender = self.chat_type.name.clone();
41 let content = self.message.clone();
42 let target = self.chat_type.target_name.clone();
43
44 let mut args = vec![
45 PrimitiveOrComponent::FormattedText(sender),
46 PrimitiveOrComponent::FormattedText(content),
47 ];
48 if let Some(target) = target {
49 args.push(PrimitiveOrComponent::FormattedText(target));
50 }
51
52 let translation_key = self.chat_type.translation_key(registries);
53 let component = TranslatableComponent::new(translation_key.to_owned(), args);
54
55 FormattedText::Translatable(component)
56 }
57}