From 3fb191fa3762bf1ba0a8722884fc46f6a65bf047 Mon Sep 17 00:00:00 2001 From: Snowiiii Date: Thu, 31 Oct 2024 17:47:01 +0100 Subject: [PATCH] Fix: deadlock when removing player --- pumpkin/src/world/mod.rs | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/pumpkin/src/world/mod.rs b/pumpkin/src/world/mod.rs index 36dd2c4fd..405dbfbb3 100644 --- a/pumpkin/src/world/mod.rs +++ b/pumpkin/src/world/mod.rs @@ -547,8 +547,11 @@ impl World { /// - This function assumes `broadcast_packet_expect` and `remove_entity` are defined elsewhere. /// - The disconnect message sending is currently optional. Consider making it a configurable option. pub async fn remove_player(&self, player: &Player) { - let mut current_players = self.current_players.lock().await; - current_players.remove(&player.gameprofile.id).unwrap(); + self.current_players + .lock() + .await + .remove(&player.gameprofile.id) + .unwrap(); let uuid = player.gameprofile.id; self.broadcast_packet_expect( &[player.gameprofile.id], @@ -562,7 +565,7 @@ impl World { let disconn_msg_txt = format!("{} left the game.", player.gameprofile.name.as_str()); let disconn_msg_cmp = TextComponent::text(disconn_msg_txt.as_str()).color_named(NamedColor::Yellow); - for player in current_players.values() { + for player in self.current_players.lock().await.values() { player.send_system_message(&disconn_msg_cmp).await; } log::info!("{}", disconn_msg_cmp.to_pretty_console());