Skip to main content

azalea_client/plugins/
client_information.rs

1use azalea_protocol::{
2    common::client_information::ClientInformation,
3    packets::config::s_client_information::ServerboundClientInformation,
4};
5use bevy_app::prelude::*;
6use bevy_ecs::prelude::*;
7use tracing::{debug, warn};
8
9use super::packet::config::SendConfigPacketEvent;
10use crate::{brand::send_brand, packet::login::InLoginState};
11
12/// Send [`ServerboundClientInformation`] on join.
13pub struct ClientInformationPlugin;
14impl Plugin for ClientInformationPlugin {
15    fn build(&self, app: &mut App) {
16        app.add_systems(Update, send_client_information.after(send_brand));
17    }
18}
19
20pub fn send_client_information(
21    mut commands: Commands,
22    mut removed: RemovedComponents<InLoginState>,
23    query: Query<&ClientInformation>,
24) {
25    for entity in removed.read() {
26        let client_information = match query.get(entity).ok() {
27            Some(i) => i,
28            None => {
29                warn!(
30                    "ClientInformation component was not set before leaving login state, using a default"
31                );
32                &ClientInformation::default()
33            }
34        };
35
36        debug!("Writing ClientInformation while in config state: {client_information:?}");
37        commands.trigger(SendConfigPacketEvent::new(
38            entity,
39            ServerboundClientInformation {
40                information: client_information.clone(),
41            },
42        ));
43    }
44}