From 8af265e48bf9f3d5263c074d034770e4216bb3f3 Mon Sep 17 00:00:00 2001 From: mat Date: Tue, 25 Mar 2025 05:16:10 +0000 Subject: PongPlugin --- azalea-client/src/plugins/pong.rs | 37 +++++++++++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) create mode 100644 azalea-client/src/plugins/pong.rs (limited to 'azalea-client/src/plugins/pong.rs') diff --git a/azalea-client/src/plugins/pong.rs b/azalea-client/src/plugins/pong.rs new file mode 100644 index 00000000..827ddfb1 --- /dev/null +++ b/azalea-client/src/plugins/pong.rs @@ -0,0 +1,37 @@ +use bevy_app::{App, Plugin}; +use bevy_ecs::prelude::*; + +use super::packet::{ + config::{ConfigPingEvent, SendConfigPacketEvent}, + game::PingEvent, +}; +use crate::packet::game::SendPacketEvent; + +/// A plugin that replies to [`ClientboundPing`] packets with +/// [`ServerboundPong`]. +/// +/// This works in both the `game` and `config` states. +/// +/// [`ClientboundPing`]: azalea_protocol::packets::game::ClientboundPing +/// [`ServerboundPong`]: azalea_protocol::packets::game::ServerboundPong +pub struct PongPlugin; +impl Plugin for PongPlugin { + fn build(&self, app: &mut App) { + app.add_observer(reply_to_game_ping) + .add_observer(reply_to_config_ping); + } +} + +pub fn reply_to_game_ping(trigger: Trigger, mut commands: Commands) { + commands.trigger(SendPacketEvent::new( + trigger.entity(), + azalea_protocol::packets::game::ServerboundPong { id: trigger.0.id }, + )); +} + +pub fn reply_to_config_ping(trigger: Trigger, mut commands: Commands) { + commands.trigger(SendConfigPacketEvent::new( + trigger.entity(), + azalea_protocol::packets::config::ServerboundPong { id: trigger.0.id }, + )); +} -- cgit v1.2.3