Minor improvements
This commit is contained in:
parent
eba5e3f9e3
commit
b710cc1566
130
src/main.rs
130
src/main.rs
@ -360,6 +360,28 @@ async fn handle(mut client: Client, event: Event, mut state: State) -> anyhow::R
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
Event::Packet(packet) => match packet.as_ref() {
|
Event::Packet(packet) => match packet.as_ref() {
|
||||||
|
ClientboundGamePacket::AddEntity(packet) => {
|
||||||
|
if packet.entity_type.to_string() != "Player" {
|
||||||
|
let entity = Entity {
|
||||||
|
id: packet.id,
|
||||||
|
uuid: packet.uuid.as_hyphenated().to_string(),
|
||||||
|
entity_type: packet.entity_type.to_string().to_lowercase(),
|
||||||
|
};
|
||||||
|
|
||||||
|
let mut mob_locations = state.mob_locations.lock().unwrap().to_owned();
|
||||||
|
mob_locations.insert(
|
||||||
|
entity,
|
||||||
|
PositionTimeData {
|
||||||
|
position: vec![packet.x as i32, packet.y as i32, packet.z as i32],
|
||||||
|
time: SystemTime::now()
|
||||||
|
.duration_since(UNIX_EPOCH)
|
||||||
|
.unwrap()
|
||||||
|
.as_secs(),
|
||||||
|
},
|
||||||
|
);
|
||||||
|
*state.mob_locations.lock().unwrap() = mob_locations;
|
||||||
|
}
|
||||||
|
}
|
||||||
ClientboundGamePacket::MoveEntityPos(packet) => {
|
ClientboundGamePacket::MoveEntityPos(packet) => {
|
||||||
let world = client.world.read();
|
let world = client.world.read();
|
||||||
let raw_entity = match world.entity(packet.entity_id) {
|
let raw_entity = match world.entity(packet.entity_id) {
|
||||||
@ -381,71 +403,69 @@ async fn handle(mut client: Client, event: Event, mut state: State) -> anyhow::R
|
|||||||
let entity = Entity {
|
let entity = Entity {
|
||||||
id: raw_entity.id,
|
id: raw_entity.id,
|
||||||
uuid: raw_entity.uuid.as_hyphenated().to_string(),
|
uuid: raw_entity.uuid.as_hyphenated().to_string(),
|
||||||
entity_type,
|
entity_type: entity_type.to_owned(),
|
||||||
};
|
};
|
||||||
let entity_position = raw_entity.pos();
|
let entity_position = raw_entity.pos();
|
||||||
|
|
||||||
let mut is_player = false;
|
if entity_type == "player" {
|
||||||
let players = client.players.read().to_owned();
|
let players = client.players.read().to_owned();
|
||||||
for (uuid, player) in players.iter().map(|item| item.to_owned()) {
|
for (uuid, player) in players.iter().map(|item| item.to_owned()) {
|
||||||
if uuid.as_hyphenated().to_string() == entity.uuid {
|
if uuid.as_hyphenated().to_string() == entity.uuid {
|
||||||
is_player = true;
|
let mut player_locations =
|
||||||
|
state.player_locations.lock().unwrap().to_owned();
|
||||||
let mut player_locations =
|
player_locations.insert(
|
||||||
state.player_locations.lock().unwrap().to_owned();
|
Player {
|
||||||
player_locations.insert(
|
uuid: uuid.as_hyphenated().to_string(),
|
||||||
Player {
|
entity_id: entity.id,
|
||||||
uuid: uuid.as_hyphenated().to_string(),
|
username: player.profile.name.to_owned(),
|
||||||
entity_id: entity.id,
|
},
|
||||||
username: player.profile.name.to_owned(),
|
PositionTimeData {
|
||||||
},
|
position: vec![
|
||||||
PositionTimeData {
|
|
||||||
position: vec![
|
|
||||||
entity_position.x as i32,
|
|
||||||
entity_position.y as i32,
|
|
||||||
entity_position.z as i32,
|
|
||||||
],
|
|
||||||
time: SystemTime::now()
|
|
||||||
.duration_since(UNIX_EPOCH)
|
|
||||||
.unwrap()
|
|
||||||
.as_secs(),
|
|
||||||
},
|
|
||||||
);
|
|
||||||
*state.player_locations.lock().unwrap() = player_locations;
|
|
||||||
|
|
||||||
if ((state.bot_configuration.alert_location[0]
|
|
||||||
- state.bot_configuration.alert_radius as i32)
|
|
||||||
..(state.bot_configuration.alert_location[0]
|
|
||||||
+ state.bot_configuration.alert_radius as i32))
|
|
||||||
.contains(&(entity_position.x as i32))
|
|
||||||
&& ((state.bot_configuration.alert_location[1]
|
|
||||||
- state.bot_configuration.alert_radius as i32)
|
|
||||||
..(state.bot_configuration.alert_location[1]
|
|
||||||
+ state.bot_configuration.alert_radius as i32))
|
|
||||||
.contains(&(entity_position.z as i32))
|
|
||||||
{
|
|
||||||
if !state
|
|
||||||
.whitelist
|
|
||||||
.lock()
|
|
||||||
.unwrap()
|
|
||||||
.contains(&player.profile.name)
|
|
||||||
{
|
|
||||||
let mut alert_queue = state.alert_queue.lock().unwrap().to_owned();
|
|
||||||
alert_queue.insert(
|
|
||||||
player.profile.name.to_owned(),
|
|
||||||
vec![
|
|
||||||
entity_position.x as i32,
|
entity_position.x as i32,
|
||||||
entity_position.y as i32,
|
entity_position.y as i32,
|
||||||
entity_position.z as i32,
|
entity_position.z as i32,
|
||||||
],
|
],
|
||||||
);
|
time: SystemTime::now()
|
||||||
*state.alert_queue.lock().unwrap() = alert_queue;
|
.duration_since(UNIX_EPOCH)
|
||||||
|
.unwrap()
|
||||||
|
.as_secs(),
|
||||||
|
},
|
||||||
|
);
|
||||||
|
*state.player_locations.lock().unwrap() = player_locations;
|
||||||
|
|
||||||
|
if ((state.bot_configuration.alert_location[0]
|
||||||
|
- state.bot_configuration.alert_radius as i32)
|
||||||
|
..(state.bot_configuration.alert_location[0]
|
||||||
|
+ state.bot_configuration.alert_radius as i32))
|
||||||
|
.contains(&(entity_position.x as i32))
|
||||||
|
&& ((state.bot_configuration.alert_location[1]
|
||||||
|
- state.bot_configuration.alert_radius as i32)
|
||||||
|
..(state.bot_configuration.alert_location[1]
|
||||||
|
+ state.bot_configuration.alert_radius as i32))
|
||||||
|
.contains(&(entity_position.z as i32))
|
||||||
|
{
|
||||||
|
if !state
|
||||||
|
.whitelist
|
||||||
|
.lock()
|
||||||
|
.unwrap()
|
||||||
|
.contains(&player.profile.name)
|
||||||
|
{
|
||||||
|
let mut alert_queue =
|
||||||
|
state.alert_queue.lock().unwrap().to_owned();
|
||||||
|
alert_queue.insert(
|
||||||
|
player.profile.name.to_owned(),
|
||||||
|
vec![
|
||||||
|
entity_position.x as i32,
|
||||||
|
entity_position.y as i32,
|
||||||
|
entity_position.z as i32,
|
||||||
|
],
|
||||||
|
);
|
||||||
|
*state.alert_queue.lock().unwrap() = alert_queue;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
} else {
|
||||||
|
|
||||||
if !is_player {
|
|
||||||
let mut mob_locations = state.mob_locations.lock().unwrap().to_owned();
|
let mut mob_locations = state.mob_locations.lock().unwrap().to_owned();
|
||||||
mob_locations.insert(
|
mob_locations.insert(
|
||||||
entity,
|
entity,
|
||||||
|
Loading…
x
Reference in New Issue
Block a user