diff options
| author | mat <github@matdoes.dev> | 2023-02-12 22:56:20 -0600 |
|---|---|---|
| committer | mat <github@matdoes.dev> | 2023-02-12 22:56:20 -0600 |
| commit | 1b3d6f9581689e9caa0e2dd14dcf48c20fb06ed7 (patch) | |
| tree | 0fbc933e220ffd9d3a848c12c38d1889fcec39a6 /azalea-client/src/disconnect.rs | |
| parent | 913f17299b85fb58c5c463a3dc4db8eb7e2d9f76 (diff) | |
| download | azalea-drasl-1b3d6f9581689e9caa0e2dd14dcf48c20fb06ed7.tar.xz | |
DisconnectEvent
Diffstat (limited to 'azalea-client/src/disconnect.rs')
| -rw-r--r-- | azalea-client/src/disconnect.rs | 31 |
1 files changed, 31 insertions, 0 deletions
diff --git a/azalea-client/src/disconnect.rs b/azalea-client/src/disconnect.rs new file mode 100644 index 00000000..100618c3 --- /dev/null +++ b/azalea-client/src/disconnect.rs @@ -0,0 +1,31 @@ +//! Disconnect a client from the server. + +use azalea_ecs::{ + app::{App, CoreStage, Plugin}, + entity::Entity, + event::EventReader, + system::Commands, +}; + +use crate::client::JoinedClientBundle; + +pub struct DisconnectPlugin; +impl Plugin for DisconnectPlugin { + fn build(&self, app: &mut App) { + app.add_event::<DisconnectEvent>() + .add_system_to_stage(CoreStage::PostUpdate, handle_disconnect); + } +} + +/// An event sent when a client is getting disconnected. +pub struct DisconnectEvent { + pub entity: Entity, +} + +/// System that removes the [`JoinedClientBundle`] from the entity when it +/// receives a [`DisconnectEvent`]. +pub fn handle_disconnect(mut commands: Commands, mut events: EventReader<DisconnectEvent>) { + for DisconnectEvent { entity } in events.iter() { + commands.entity(*entity).remove::<JoinedClientBundle>(); + } +} |
