From 9513f42e87f64c409cdb2a100500a50e5a713bac Mon Sep 17 00:00:00 2001 From: mat <27899617+mat-1@users.noreply.github.com> Date: Sat, 27 Dec 2025 22:02:00 -0600 Subject: Move Client struct to azalea crate (#297) * move the Client struct out of azalea-client into azalea * actually add client impls in azalea --- azalea/src/client_impl/chat.rs | 49 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 49 insertions(+) create mode 100644 azalea/src/client_impl/chat.rs (limited to 'azalea/src/client_impl/chat.rs') diff --git a/azalea/src/client_impl/chat.rs b/azalea/src/client_impl/chat.rs new file mode 100644 index 00000000..3ca98631 --- /dev/null +++ b/azalea/src/client_impl/chat.rs @@ -0,0 +1,49 @@ +use azalea_client::chat::{ChatKind, SendChatEvent, handler::SendChatKindEvent}; + +use crate::Client; + +impl Client { + /// Send a chat message to the server. + /// + /// This only sends the chat packet and not the command packet, which means + /// on some servers you can use this to send chat messages that start + /// with a `/`. The [`Client::chat`] function handles checking whether + /// the message is a command and using the proper packet for you, so you + /// should use that instead. + pub fn write_chat_packet(&self, message: &str) { + self.ecs.lock().write_message(SendChatKindEvent { + entity: self.entity, + content: message.to_owned(), + kind: ChatKind::Message, + }); + } + + /// Send a command packet to the server. The `command` argument should not + /// include the slash at the front. + /// + /// You can also just use [`Client::chat`] and start your message with a `/` + /// to send a command. + pub fn write_command_packet(&self, command: &str) { + self.ecs.lock().write_message(SendChatKindEvent { + entity: self.entity, + content: command.to_owned(), + kind: ChatKind::Command, + }); + } + + /// Send a message in chat. + /// + /// ```rust,no_run + /// # use azalea::Client; + /// # async fn example(bot: Client) -> anyhow::Result<()> { + /// bot.chat("Hello, world!"); + /// # Ok(()) + /// # } + /// ``` + pub fn chat(&self, content: impl Into) { + self.ecs.lock().write_message(SendChatEvent { + entity: self.entity, + content: content.into(), + }); + } +} -- cgit v1.2.3