From 05b67b8a0dc64c0e33833614e1886adea6cd6c5d Mon Sep 17 00:00:00 2001 From: ErrorNoInternet Date: Wed, 22 Feb 2023 20:35:57 +0800 Subject: [PATCH] Fix interact bug --- src/bot.rs | 26 ++++---------------------- 1 file changed, 4 insertions(+), 22 deletions(-) diff --git a/src/bot.rs b/src/bot.rs index 0a85e89..18cbb10 100644 --- a/src/bot.rs +++ b/src/bot.rs @@ -669,14 +669,12 @@ pub async fn process_command( return "Please give me IDs to interact with!".to_string(); } - let mut found = false; let mob_locations = state.mob_locations.lock().unwrap().to_owned(); for (mob, _) in mob_locations { if mob.id.to_string() == segments[0] || mob.uuid == segments[0] || mob.entity_type == segments[0] { - found = true; log_error( client .write_packet(ServerboundGamePacket::Interact( @@ -691,18 +689,15 @@ pub async fn process_command( )) .await, ); + return "Successfully interacted with mob!".to_string(); } } - if found { - return "Successfully interacted with mob!".to_string(); - } let player_locations = state.player_locations.lock().unwrap().to_owned(); for (player, _) in player_locations { if player.entity_id.to_string() == segments[0] || player.uuid == segments[0] || player.username == segments[0] { - found = true; log_error( client .write_packet(ServerboundGamePacket::Interact( @@ -717,27 +712,21 @@ pub async fn process_command( )) .await, ); + return "Successfully interacted with player!".to_string(); } } - if found { - return "Successfully interacted with player!".to_string(); - } else { - return "Unable to find entity!".to_string(); - } } Command::Attack => { if segments.len() < 1 { return "Please give me IDs to attack!".to_string(); } - let mut found = false; let mob_locations = state.mob_locations.lock().unwrap().to_owned(); for (mob, _) in mob_locations { if mob.id.to_string() == segments[0] || mob.uuid == segments[0] || mob.entity_type == segments[0] { - found = true; log_error( client .write_packet(ServerboundGamePacket::Interact( @@ -749,18 +738,15 @@ pub async fn process_command( )) .await, ); + return "Successfully attacked mob!".to_string(); } } - if found { - return "Successfully attacked mob!".to_string(); - } let player_locations = state.player_locations.lock().unwrap().to_owned(); for (player, _) in player_locations { if player.entity_id.to_string() == segments[0] || player.uuid == segments[0] || player.username == segments[0] { - found = true; log_error( client .write_packet(ServerboundGamePacket::Interact( @@ -772,13 +758,9 @@ pub async fn process_command( )) .await, ); + return "Successfully attacked player!".to_string(); } } - if found { - return "Successfully attacked player!".to_string(); - } else { - return "Unable to find entity!".to_string(); - } } Command::Jump => { client.jump();