diff options
Diffstat (limited to 'azalea-client/src/plugins/packet')
| -rw-r--r-- | azalea-client/src/plugins/packet/config/events.rs | 10 | ||||
| -rw-r--r-- | azalea-client/src/plugins/packet/config/mod.rs | 6 | ||||
| -rw-r--r-- | azalea-client/src/plugins/packet/game/events.rs | 18 | ||||
| -rw-r--r-- | azalea-client/src/plugins/packet/game/mod.rs | 5 |
4 files changed, 31 insertions, 8 deletions
diff --git a/azalea-client/src/plugins/packet/config/events.rs b/azalea-client/src/plugins/packet/config/events.rs index 9ed6c097..d0a7f3be 100644 --- a/azalea-client/src/plugins/packet/config/events.rs +++ b/azalea-client/src/plugins/packet/config/events.rs @@ -109,3 +109,13 @@ fn packet_interrupts(packet: &ClientboundConfigPacket) -> bool { | ClientboundConfigPacket::Transfer(_) ) } + +/// A Bevy trigger that's sent when our client receives a [`ClientboundPing`] +/// packet in the config state. +/// +/// See [`PingEvent`] for more information. +/// +/// [`ClientboundPing`]: azalea_protocol::packets::config::ClientboundPing +/// [`PingEvent`]: crate::packet::game::PingEvent +#[derive(Event, Debug, Clone)] +pub struct ConfigPingEvent(pub azalea_protocol::packets::config::ClientboundPing); diff --git a/azalea-client/src/plugins/packet/config/mod.rs b/azalea-client/src/plugins/packet/config/mod.rs index c9b84eac..ae601793 100644 --- a/azalea-client/src/plugins/packet/config/mod.rs +++ b/azalea-client/src/plugins/packet/config/mod.rs @@ -142,10 +142,8 @@ impl ConfigPacketHandler<'_> { pub fn ping(&mut self, p: ClientboundPing) { debug!("Got ping packet (in configuration) {p:?}"); - as_system::<Query<&RawConnection>>(self.ecs, |query| { - let raw_conn = query.get(self.player).unwrap(); - - raw_conn.write_packet(ServerboundPong { id: p.id }).unwrap(); + as_system::<Commands>(self.ecs, |mut commands| { + commands.trigger_targets(ConfigPingEvent(p), self.player); }); } diff --git a/azalea-client/src/plugins/packet/game/events.rs b/azalea-client/src/plugins/packet/game/events.rs index 8a5aca3c..ad81f9bd 100644 --- a/azalea-client/src/plugins/packet/game/events.rs +++ b/azalea-client/src/plugins/packet/game/events.rs @@ -212,3 +212,21 @@ pub struct InstanceLoadedEvent { pub name: ResourceLocation, pub instance: Weak<RwLock<Instance>>, } + +/// A Bevy trigger that's sent when our client receives a [`ClientboundPing`] +/// packet in the game state. +/// +/// Also see [`ConfigPingEvent`] which is used for the config state. +/// +/// This is not an event and can't be listened to from a normal system, +///so `EventReader<PingEvent>` will not work. +/// +/// To use it, add your "system" with `add_observer` instead of `add_systems` +/// and use `Trigger<PingEvent>` instead of `EventReader`. +/// +/// The client Entity that received the packet will be attached to the trigger. +/// +/// [`ClientboundPing`]: azalea_protocol::packets::game::ClientboundPing +/// [`ConfigPingEvent`]: crate::packet::config::ConfigPingEvent +#[derive(Event, Debug, Clone)] +pub struct PingEvent(pub azalea_protocol::packets::game::ClientboundPing); diff --git a/azalea-client/src/plugins/packet/game/mod.rs b/azalea-client/src/plugins/packet/game/mod.rs index 1e9232bf..cc67bcd7 100644 --- a/azalea-client/src/plugins/packet/game/mod.rs +++ b/azalea-client/src/plugins/packet/game/mod.rs @@ -1363,10 +1363,7 @@ impl GamePacketHandler<'_> { debug!("Got ping packet {p:?}"); as_system::<Commands>(self.ecs, |mut commands| { - commands.trigger(SendPacketEvent::new( - self.player, - ServerboundPong { id: p.id }, - )); + commands.trigger_targets(PingEvent(p.clone()), self.player); }); } |
