-
-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathauto_whitelist.rs
More file actions
52 lines (45 loc) · 1.59 KB
/
auto_whitelist.rs
File metadata and controls
52 lines (45 loc) · 1.59 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
use azalea::{
app::{App, Plugin, Update},
packet::game::ReceiveGamePacketEvent,
protocol::packets::game::ClientboundGamePacket,
registry::builtin::EntityKind,
};
use crate::prelude::*;
/// Automatically whitelist players that enter range
pub struct AutoWhitelistPlugin;
impl Plugin for AutoWhitelistPlugin {
fn build(&self, app: &mut App) {
app.add_systems(
Update,
Self::handle_add_entity_packets
.before(MinecraftParserPlugin::handle_chat_received_events)
.before(MinecraftParserPlugin::handle_send_msg_events)
.before(AutoLeavePlugin::handle_add_entity_packets),
);
}
}
impl AutoWhitelistPlugin {
pub fn handle_add_entity_packets(
mut packet_events: MessageReader<ReceiveGamePacketEvent>,
mut global_settings: ResMut<GlobalSettings>,
) {
for event in packet_events.read() {
let ClientboundGamePacket::AddEntity(packet) = event.packet.as_ref() else {
continue;
};
if packet.entity_type != EntityKind::Player {
continue;
}
if global_settings.users.contains_key(&packet.uuid) {
continue;
}
if global_settings.whitelist_in_range {
info!("Adding {} to whitelist", packet.uuid);
global_settings.users.insert(packet.uuid, User::default());
if let Err(error) = global_settings.save() {
error!("Failed to save global settings: {error}");
}
}
}
}
}