Fix interact bug

This commit is contained in:
ErrorNoInternet 2023-02-22 20:35:57 +08:00
parent 7ebe1e1a51
commit 05b67b8a0d
Signed by untrusted user who does not match committer: ErrorNoInternet
GPG Key ID: 2486BFB7B1E6A4A3

View File

@ -669,14 +669,12 @@ pub async fn process_command(
return "Please give me IDs to interact with!".to_string(); return "Please give me IDs to interact with!".to_string();
} }
let mut found = false;
let mob_locations = state.mob_locations.lock().unwrap().to_owned(); let mob_locations = state.mob_locations.lock().unwrap().to_owned();
for (mob, _) in mob_locations { for (mob, _) in mob_locations {
if mob.id.to_string() == segments[0] if mob.id.to_string() == segments[0]
|| mob.uuid == segments[0] || mob.uuid == segments[0]
|| mob.entity_type == segments[0] || mob.entity_type == segments[0]
{ {
found = true;
log_error( log_error(
client client
.write_packet(ServerboundGamePacket::Interact( .write_packet(ServerboundGamePacket::Interact(
@ -691,18 +689,15 @@ pub async fn process_command(
)) ))
.await, .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(); let player_locations = state.player_locations.lock().unwrap().to_owned();
for (player, _) in player_locations { for (player, _) in player_locations {
if player.entity_id.to_string() == segments[0] if player.entity_id.to_string() == segments[0]
|| player.uuid == segments[0] || player.uuid == segments[0]
|| player.username == segments[0] || player.username == segments[0]
{ {
found = true;
log_error( log_error(
client client
.write_packet(ServerboundGamePacket::Interact( .write_packet(ServerboundGamePacket::Interact(
@ -717,27 +712,21 @@ pub async fn process_command(
)) ))
.await, .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 => { Command::Attack => {
if segments.len() < 1 { if segments.len() < 1 {
return "Please give me IDs to attack!".to_string(); return "Please give me IDs to attack!".to_string();
} }
let mut found = false;
let mob_locations = state.mob_locations.lock().unwrap().to_owned(); let mob_locations = state.mob_locations.lock().unwrap().to_owned();
for (mob, _) in mob_locations { for (mob, _) in mob_locations {
if mob.id.to_string() == segments[0] if mob.id.to_string() == segments[0]
|| mob.uuid == segments[0] || mob.uuid == segments[0]
|| mob.entity_type == segments[0] || mob.entity_type == segments[0]
{ {
found = true;
log_error( log_error(
client client
.write_packet(ServerboundGamePacket::Interact( .write_packet(ServerboundGamePacket::Interact(
@ -749,18 +738,15 @@ pub async fn process_command(
)) ))
.await, .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(); let player_locations = state.player_locations.lock().unwrap().to_owned();
for (player, _) in player_locations { for (player, _) in player_locations {
if player.entity_id.to_string() == segments[0] if player.entity_id.to_string() == segments[0]
|| player.uuid == segments[0] || player.uuid == segments[0]
|| player.username == segments[0] || player.username == segments[0]
{ {
found = true;
log_error( log_error(
client client
.write_packet(ServerboundGamePacket::Interact( .write_packet(ServerboundGamePacket::Interact(
@ -772,13 +758,9 @@ pub async fn process_command(
)) ))
.await, .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 => { Command::Jump => {
client.jump(); client.jump();