aboutsummaryrefslogtreecommitdiff
path: root/azalea-protocol/src/packets/game/clientbound_disguised_chat_packet.rs
diff options
context:
space:
mode:
authormat <git@matdoes.dev>2023-12-04 14:25:10 -0600
committermat <git@matdoes.dev>2023-12-04 14:27:13 -0600
commit797dd9171088cd697b3c95663cbbc65b05315414 (patch)
treec179130af8172015b0d0c3b31732c77b563744a0 /azalea-protocol/src/packets/game/clientbound_disguised_chat_packet.rs
parent888c2765037711f45a6dac8d8bad70dc9ee70998 (diff)
downloadazalea-drasl-797dd9171088cd697b3c95663cbbc65b05315414.tar.xz
revert packet name to Disguised and make it more like ChatPacket::Player
Diffstat (limited to 'azalea-protocol/src/packets/game/clientbound_disguised_chat_packet.rs')
-rw-r--r--azalea-protocol/src/packets/game/clientbound_disguised_chat_packet.rs35
1 files changed, 33 insertions, 2 deletions
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)
+ }
+}