diff --git a/azalea-client/src/chat.rs b/azalea-client/src/chat.rs index 5f566fe7..26f37d58 100755 --- a/azalea-client/src/chat.rs +++ b/azalea-client/src/chat.rs @@ -9,13 +9,16 @@ use azalea_protocol::packets::game::{ serverbound_chat_command_packet::ServerboundChatCommandPacket, serverbound_chat_packet::ServerboundChatPacket, }; -use std::time::{SystemTime, UNIX_EPOCH}; +use std::{ + sync::Arc, + time::{SystemTime, UNIX_EPOCH}, +}; /// A chat packet, either a system message or a chat message. #[derive(Debug, Clone, PartialEq)] pub enum ChatPacket { - System(ClientboundSystemChatPacket), - Player(Box), + System(Arc), + Player(Arc), } macro_rules! regex { diff --git a/azalea-client/src/client.rs b/azalea-client/src/client.rs index ce4ca4cf..1cd26aa8 100644 --- a/azalea-client/src/client.rs +++ b/azalea-client/src/client.rs @@ -65,11 +65,11 @@ pub enum Event { Chat(ChatPacket), /// Happens 20 times per second, but only when the world is loaded. Tick, - Packet(Box), + Packet(Arc), /// Happens when a player is added, removed, or updated in the tab list. UpdatePlayers(UpdatePlayersEvent), /// Emits when the player dies. - Death(Option>), + Death(Option>), } /// Happens when a player is added, removed, or updated in the tab list. @@ -421,8 +421,9 @@ impl Client { client: &Client, tx: &Sender, ) -> Result<(), HandleError> { - tx.send(Event::Packet(Box::new(packet.clone()))).await?; - match packet { + let packet = Arc::new(packet.clone()); + tx.send(Event::Packet(packet.clone())).await?; + match &*packet { ClientboundGamePacket::Login(p) => { debug!("Got login packet"); @@ -896,12 +897,13 @@ impl Client { } ClientboundGamePacket::PlayerChat(p) => { debug!("Got player chat packet {:?}", p); - tx.send(Event::Chat(ChatPacket::Player(Box::new(p.clone())))) + tx.send(Event::Chat(ChatPacket::Player(Arc::new(p.clone())))) .await?; } ClientboundGamePacket::SystemChat(p) => { debug!("Got system chat packet {:?}", p); - tx.send(Event::Chat(ChatPacket::System(p.clone()))).await?; + tx.send(Event::Chat(ChatPacket::System(Arc::new(p.clone())))) + .await?; } ClientboundGamePacket::Sound(_p) => { // debug!("Got sound packet {:?}", p); @@ -975,7 +977,7 @@ impl Client { // because of https://github.com/rust-lang/rust/issues/57478 if !*client.dead.lock() { *client.dead.lock() = true; - tx.send(Event::Death(Some(Box::new(p.clone())))).await?; + tx.send(Event::Death(Some(Arc::new(p.clone())))).await?; } } }