diff options
| author | mat <git@matdoes.dev> | 2026-01-23 18:09:59 -0930 |
|---|---|---|
| committer | mat <git@matdoes.dev> | 2026-01-23 18:09:59 -0930 |
| commit | 53e630f73f5fcc82a6818448cdb105abb75dfcc7 (patch) | |
| tree | ad5f58874ab147483a42638aa04ef8936b983694 /azalea/src/events.rs | |
| parent | b7ad0e60f7b0a5f5a1f6a2c80abc865fdb250ee5 (diff) | |
| download | azalea-drasl-53e630f73f5fcc82a6818448cdb105abb75dfcc7.tar.xz | |
add Event::ConnectionFailed and add more plugins by default when using Client::join
Diffstat (limited to 'azalea/src/events.rs')
| -rw-r--r-- | azalea/src/events.rs | 24 |
1 files changed, 23 insertions, 1 deletions
diff --git a/azalea/src/events.rs b/azalea/src/events.rs index b0bc8cd1..fcd47e2f 100644 --- a/azalea/src/events.rs +++ b/azalea/src/events.rs @@ -4,9 +4,12 @@ use std::sync::Arc; use azalea_chat::FormattedText; +use azalea_client::join::ConnectionFailedEvent; use azalea_core::{entity_id::MinecraftEntityId, position::ChunkPos, tick::GameTick}; use azalea_entity::{Dead, InLoadedChunk}; -use azalea_protocol::packets::game::c_player_combat_kill::ClientboundPlayerCombatKill; +use azalea_protocol::{ + connect::ConnectionError, packets::game::c_player_combat_kill::ClientboundPlayerCombatKill, +}; use azalea_world::WorldName; use bevy_app::{App, Plugin, PreUpdate, Update}; use bevy_ecs::prelude::*; @@ -122,7 +125,14 @@ pub enum Event { /// A `KeepAlive` packet was sent by the server. KeepAlive(u64), /// The client disconnected from the server. + /// + /// Also see [`Event::ConnectionFailed`]. Disconnect(Option<FormattedText>), + /// The initial connection to the server failed. + /// + /// Also see [`Event::Disconnect`], and the related ECS event + /// [`ConnectionFailedEvent`]. + ConnectionFailed(Arc<ConnectionError>), ReceiveChunk(ChunkPos), } @@ -151,6 +161,7 @@ impl Plugin for EventsPlugin { keepalive_listener, death_listener.after(azalea_client::packet::death_event_on_0_health), disconnect_listener, + connection_failed_listener, receive_chunk_listener, ), ) @@ -301,6 +312,17 @@ pub fn disconnect_listener( } } +pub fn connection_failed_listener( + query: Query<&LocalPlayerEvents>, + mut events: MessageReader<ConnectionFailedEvent>, +) { + for event in events.read() { + if let Ok(local_player_events) = query.get(event.entity) { + let _ = local_player_events.send(Event::ConnectionFailed(event.error.clone())); + } + } +} + pub fn receive_chunk_listener( query: Query<&LocalPlayerEvents>, mut events: MessageReader<ReceiveChunkEvent>, |
