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
|
use azalea_protocol::{
common::client_information::ClientInformation,
packets::config::s_client_information::ServerboundClientInformation,
};
use bevy_app::prelude::*;
use bevy_ecs::prelude::*;
use tracing::{debug, warn};
use super::packet::config::SendConfigPacketEvent;
use crate::{brand::send_brand, packet::login::InLoginState};
/// Send [`ServerboundClientInformation`] on join.
pub struct ClientInformationPlugin;
impl Plugin for ClientInformationPlugin {
fn build(&self, app: &mut App) {
app.add_systems(Update, send_client_information.after(send_brand));
}
}
pub fn send_client_information(
mut commands: Commands,
mut removed: RemovedComponents<InLoginState>,
query: Query<&ClientInformation>,
) {
for entity in removed.read() {
let client_information = match query.get(entity).ok() {
Some(i) => i,
None => {
warn!(
"ClientInformation component was not set before leaving login state, using a default"
);
&ClientInformation::default()
}
};
debug!("Writing ClientInformation while in config state: {client_information:?}");
commands.trigger(SendConfigPacketEvent::new(
entity,
ServerboundClientInformation {
information: client_information.clone(),
},
));
}
}
|