1use azalea_protocol::packets::game::s_client_command::{self, ServerboundClientCommand};
2use bevy_app::{App, Plugin, Update};
3use bevy_ecs::prelude::*;
4
5use crate::packet_handling::game::{handle_send_packet_event, SendPacketEvent};
6
7#[derive(Event, Debug, Clone)]
9pub struct PerformRespawnEvent {
10 pub entity: Entity,
11}
12
13pub struct RespawnPlugin;
15impl Plugin for RespawnPlugin {
16 fn build(&self, app: &mut App) {
17 app.add_event::<PerformRespawnEvent>()
18 .add_systems(Update, perform_respawn.before(handle_send_packet_event));
19 }
20}
21
22pub fn perform_respawn(
23 mut events: EventReader<PerformRespawnEvent>,
24 mut send_packets: EventWriter<SendPacketEvent>,
25) {
26 for event in events.read() {
27 send_packets.send(SendPacketEvent::new(
28 event.entity,
29 ServerboundClientCommand {
30 action: s_client_command::Action::PerformRespawn,
31 },
32 ));
33 }
34}