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 | |
| 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')
| -rw-r--r-- | azalea/src/client_impl/mod.rs | 4 | ||||
| -rw-r--r-- | azalea/src/events.rs | 24 | ||||
| -rw-r--r-- | azalea/src/swarm/builder.rs | 9 |
3 files changed, 31 insertions, 6 deletions
diff --git a/azalea/src/client_impl/mod.rs b/azalea/src/client_impl/mod.rs index d55e5a38..343b8aef 100644 --- a/azalea/src/client_impl/mod.rs +++ b/azalea/src/client_impl/mod.rs @@ -33,8 +33,10 @@ use tokio::sync::mpsc; use uuid::Uuid; use crate::{ + bot::DefaultBotPlugins, entity_ref::EntityRef, events::{Event, LocalPlayerEvents}, + swarm::DefaultSwarmPlugins, }; pub mod attack; @@ -86,7 +88,7 @@ impl StartClientOpts { event_sender: Option<mpsc::UnboundedSender<Event>>, ) -> StartClientOpts { let mut app = App::new(); - app.add_plugins(DefaultPlugins); + app.add_plugins((DefaultPlugins, DefaultBotPlugins, DefaultSwarmPlugins)); // appexit_rx is unused here since the user should be able to handle it // themselves if they're using StartClientOpts::new 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>, diff --git a/azalea/src/swarm/builder.rs b/azalea/src/swarm/builder.rs index f42b4d4a..0adb4f26 100644 --- a/azalea/src/swarm/builder.rs +++ b/azalea/src/swarm/builder.rs @@ -75,10 +75,11 @@ impl SwarmBuilder<NoState, NoSwarmState, (), ()> { /// Start creating the swarm. #[must_use] pub fn new() -> Self { - Self::new_without_plugins() - .add_plugins(DefaultPlugins) - .add_plugins(DefaultBotPlugins) - .add_plugins(DefaultSwarmPlugins) + Self::new_without_plugins().add_plugins(( + DefaultPlugins, + DefaultBotPlugins, + DefaultSwarmPlugins, + )) } /// [`Self::new`] but without adding the plugins by default. |
