azalea_client/plugins/
pong.rs1use azalea_protocol::packets::{config, game};
2use bevy_app::{App, Plugin};
3use bevy_ecs::prelude::*;
4
5use super::packet::{
6 config::{ConfigPingEvent, SendConfigPacketEvent},
7 game::GamePingEvent,
8};
9use crate::packet::game::SendGamePacketEvent;
10
11pub struct PongPlugin;
19impl Plugin for PongPlugin {
20 fn build(&self, app: &mut App) {
21 app.add_observer(reply_to_game_ping)
22 .add_observer(reply_to_config_ping);
23 }
24}
25
26pub fn reply_to_game_ping(ping: On<GamePingEvent>, mut commands: Commands) {
27 commands.trigger(SendGamePacketEvent::new(
28 ping.entity,
29 game::ServerboundPong { id: ping.packet.id },
30 ));
31}
32
33pub fn reply_to_config_ping(ping: On<ConfigPingEvent>, mut commands: Commands) {
34 commands.trigger(SendConfigPacketEvent::new(
35 ping.entity,
36 config::ServerboundPong { id: ping.packet.id },
37 ));
38}