Skip to content

Commit

Permalink
Fix: deadlock when removing player
Browse files Browse the repository at this point in the history
  • Loading branch information
Snowiiii committed Oct 31, 2024
1 parent 3f2bbcc commit 3fb191f
Showing 1 changed file with 6 additions and 3 deletions.
9 changes: 6 additions & 3 deletions pumpkin/src/world/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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],
Expand All @@ -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());
Expand Down

0 comments on commit 3fb191f

Please sign in to comment.