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/client.rs | |
| parent | 913f17299b85fb58c5c463a3dc4db8eb7e2d9f76 (diff) | |
| download | azalea-drasl-1b3d6f9581689e9caa0e2dd14dcf48c20fb06ed7.tar.xz | |
DisconnectEvent
Diffstat (limited to 'azalea-client/src/client.rs')
| -rw-r--r-- | azalea-client/src/client.rs | 33 |
1 files changed, 25 insertions, 8 deletions
diff --git a/azalea-client/src/client.rs b/azalea-client/src/client.rs index 13b0522a..8e1a7938 100644 --- a/azalea-client/src/client.rs +++ b/azalea-client/src/client.rs @@ -1,12 +1,13 @@ use crate::{ chat::ChatPlugin, + disconnect::{DisconnectEvent, DisconnectPlugin}, events::{Event, EventPlugin, LocalPlayerEvents}, local_player::{ death_event, handle_send_packet_event, update_in_loaded_chunk, GameProfileComponent, LocalPlayer, PhysicsState, SendPacketEvent, }, movement::{local_player_ai_step, send_position, sprint_listener, walk_listener}, - packet_handling::{self, PacketHandlerPlugin}, + packet_handling::{self, PacketHandlerPlugin, PacketReceiver}, player::retroactively_add_game_profile_component, task_pool::TaskPoolPlugin, Account, PlayerInfo, StartSprintEvent, StartWalkEvent, @@ -16,6 +17,7 @@ use azalea_auth::{game_profile::GameProfile, sessionserver::ClientSessionServerE use azalea_chat::FormattedText; use azalea_ecs::{ app::{App, Plugin, PluginGroup, PluginGroupBuilder}, + bundle::Bundle, component::Component, entity::Entity, schedule::{IntoSystemDescriptor, Schedule, Stage, SystemSet}, @@ -225,14 +227,14 @@ impl Client { local_player.tasks.push(read_packets_task); local_player.tasks.push(write_packets_task); - ecs.entity_mut(entity).insert(( + ecs.entity_mut(entity).insert(JoinedClientBundle { local_player, packet_receiver, - GameProfileComponent(game_profile), - PhysicsState::default(), - Local, - LocalPlayerEvents(tx), - )); + game_profile: GameProfileComponent(game_profile), + physics_state: PhysicsState::default(), + local_player_events: LocalPlayerEvents(tx), + _local: Local, + }); Ok((client, rx)) } @@ -371,7 +373,9 @@ impl Client { /// The OwnedReadHalf for the TCP connection is in one of the tasks, so it /// automatically closes the connection when that's dropped. pub fn disconnect(&self) { - self.local_player_mut(&mut self.ecs.lock()).disconnect(); + self.ecs.lock().send_event(DisconnectEvent { + entity: self.entity, + }); } pub fn local_player<'a>(&'a self, ecs: &'a mut Ecs) -> &'a LocalPlayer { @@ -468,6 +472,18 @@ impl Client { } } +/// A bundle for the components that are present on a local player that received +/// a login packet. If you want to filter for this, just use [`Local`]. +#[derive(Bundle)] +pub struct JoinedClientBundle { + pub local_player: LocalPlayer, + pub packet_receiver: PacketReceiver, + pub game_profile: GameProfileComponent, + pub physics_state: PhysicsState, + pub local_player_events: LocalPlayerEvents, + pub _local: Local, +} + pub struct AzaleaPlugin; impl Plugin for AzaleaPlugin { fn build(&self, app: &mut App) { @@ -596,5 +612,6 @@ impl PluginGroup for DefaultPlugins { .add(EventPlugin) .add(TaskPoolPlugin::default()) .add(ChatPlugin) + .add(DisconnectPlugin) } } |
