1
2
Fork 0
mirror of https://github.com/mat-1/azalea.git synced 2025-08-02 06:16:04 +00:00

add function that gets full message content

This commit is contained in:
mat 2022-10-21 21:44:39 -05:00
parent aa1f2a55e0
commit b95e69be8f
3 changed files with 67 additions and 8 deletions

View file

@ -64,7 +64,7 @@ impl ChatPacket {
pub fn message(&self) -> Component { pub fn message(&self) -> Component {
match self { match self {
ChatPacket::System(p) => p.content.clone(), ChatPacket::System(p) => p.content.clone(),
ChatPacket::Player(p) => p.message.message(false), ChatPacket::Player(p) => p.message(false),
} }
} }
} }

View file

@ -1,5 +1,8 @@
use azalea_buf::McBuf; use azalea_buf::McBuf;
use azalea_chat::component::Component; use azalea_chat::{
component::Component,
translatable_component::{StringOrComponent, TranslatableComponent},
};
use azalea_core::BitSet; use azalea_core::BitSet;
use azalea_crypto::{MessageSignature, SignedMessageHeader}; use azalea_crypto::{MessageSignature, SignedMessageHeader};
use azalea_protocol_macros::ClientboundGamePacket; use azalea_protocol_macros::ClientboundGamePacket;
@ -47,7 +50,10 @@ pub struct SignedMessageBody {
} }
impl PlayerChatMessage { 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 { if only_secure_chat {
return self return self
.signed_body .signed_body
@ -58,7 +64,56 @@ impl PlayerChatMessage {
} }
self.unsigned_content self.unsigned_content
.clone() .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",
}
} }
} }

View file

@ -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: 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) json.dump(fabric_mod_json, f, indent=2)
try: os.system(f'cd {generator_mod_dir} && chmod u+x ./gradlew') try:
except: pass 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 # set the server port to something other than 25565 so it doesn't
# conflict with anything else that's running # conflict with anything else that's running
try: os.makedirs(get_dir_location(f'{generator_mod_dir}/run')) try:
except: pass 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: with open(get_dir_location(f'{generator_mod_dir}/run/server.properties'), 'w') as f:
f.write('server-port=56553') f.write('server-port=56553')