aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--azalea-client/src/client.rs2
-rw-r--r--azalea-protocol/src/packets/game/clientbound_player_chat_packet.rs61
-rw-r--r--codegen/lib/extract.py12
3 files changed, 67 insertions, 8 deletions
diff --git a/azalea-client/src/client.rs b/azalea-client/src/client.rs
index c70d0e90..a59c340b 100644
--- a/azalea-client/src/client.rs
+++ b/azalea-client/src/client.rs
@@ -64,7 +64,7 @@ impl ChatPacket {
pub fn message(&self) -> Component {
match self {
ChatPacket::System(p) => p.content.clone(),
- ChatPacket::Player(p) => p.message.message(false),
+ ChatPacket::Player(p) => p.message(false),
}
}
}
diff --git a/azalea-protocol/src/packets/game/clientbound_player_chat_packet.rs b/azalea-protocol/src/packets/game/clientbound_player_chat_packet.rs
index e961828e..3f75e74b 100644
--- a/azalea-protocol/src/packets/game/clientbound_player_chat_packet.rs
+++ b/azalea-protocol/src/packets/game/clientbound_player_chat_packet.rs
@@ -1,5 +1,8 @@
use azalea_buf::McBuf;
-use azalea_chat::component::Component;
+use azalea_chat::{
+ component::Component,
+ translatable_component::{StringOrComponent, TranslatableComponent},
+};
use azalea_core::BitSet;
use azalea_crypto::{MessageSignature, SignedMessageHeader};
use azalea_protocol_macros::ClientboundGamePacket;
@@ -47,7 +50,10 @@ pub struct SignedMessageBody {
}
impl PlayerChatMessage {
- pub fn message(&self, only_secure_chat: bool) -> Component {
+ /// Returns the content of the message. If you want to get the Component
+ /// for the whole message including the sender part, use
+ /// [`ClientboundPlayerChatPacket::message`].
+ pub fn content(&self, only_secure_chat: bool) -> Component {
if only_secure_chat {
return self
.signed_body
@@ -58,7 +64,56 @@ impl PlayerChatMessage {
}
self.unsigned_content
.clone()
- .unwrap_or_else(|| self.message(true))
+ .unwrap_or_else(|| self.content(true))
+ }
+}
+
+impl ClientboundPlayerChatPacket {
+ /// Get the full message, including the sender part.
+ pub fn message(&self, only_secure_chat: bool) -> Component {
+ let sender = self.chat_type.name.clone();
+ let content = self.message.content(only_secure_chat);
+ let target = self.chat_type.target_name.clone();
+
+ let translation_key = self.chat_type.chat_type.chat_translation_key();
+
+ let mut args = vec![
+ StringOrComponent::Component(sender),
+ StringOrComponent::Component(content),
+ ];
+ if let Some(target) = target {
+ args.push(StringOrComponent::Component(target));
+ }
+
+ let component = TranslatableComponent::new(translation_key.to_string(), args);
+
+ Component::Translatable(component)
+ }
+}
+
+impl ChatType {
+ pub fn chat_translation_key(&self) -> &'static str {
+ match self {
+ ChatType::Chat => "chat.type.text",
+ ChatType::SayCommand => "chat.type.announcement",
+ ChatType::MsgCommandIncoming => "commands.message.display.incoming",
+ ChatType::MsgCommandOutgoing => "commands.message.display.outgoing",
+ ChatType::TeamMsgCommandIncoming => "chat.type.team.text",
+ ChatType::TeamMsgCommandOutgoing => "chat.type.team.sent",
+ ChatType::EmoteCommand => "chat.type.emote",
+ }
+ }
+
+ pub fn narrator_translation_key(&self) -> &'static str {
+ match self {
+ ChatType::Chat => "chat.type.text.narrate",
+ ChatType::SayCommand => "chat.type.text.narrate",
+ ChatType::MsgCommandIncoming => "chat.type.text.narrate",
+ ChatType::MsgCommandOutgoing => "chat.type.text.narrate",
+ ChatType::TeamMsgCommandIncoming => "chat.type.text.narrate",
+ ChatType::TeamMsgCommandOutgoing => "chat.type.text.narrate",
+ ChatType::EmoteCommand => "chat.type.emote",
+ }
}
}
diff --git a/codegen/lib/extract.py b/codegen/lib/extract.py
index 5d49ac62..e66b9400 100644
--- a/codegen/lib/extract.py
+++ b/codegen/lib/extract.py
@@ -123,13 +123,17 @@ def get_generator_mod_data(version_id: str, category: str):
with open(get_dir_location(f'{generator_mod_dir}/src/main/resources/fabric.mod.json'), 'w') as f:
json.dump(fabric_mod_json, f, indent=2)
- try: os.system(f'cd {generator_mod_dir} && chmod u+x ./gradlew')
- except: pass
+ try:
+ os.system(f'cd {generator_mod_dir} && chmod u+x ./gradlew')
+ except:
+ pass
# set the server port to something other than 25565 so it doesn't
# conflict with anything else that's running
- try: os.makedirs(get_dir_location(f'{generator_mod_dir}/run'))
- except: pass
+ try:
+ os.makedirs(get_dir_location(f'{generator_mod_dir}/run'))
+ except:
+ pass
with open(get_dir_location(f'{generator_mod_dir}/run/server.properties'), 'w') as f:
f.write('server-port=56553')