aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authormat <git@matdoes.dev>2026-01-23 18:09:59 -0930
committermat <git@matdoes.dev>2026-01-23 18:09:59 -0930
commit53e630f73f5fcc82a6818448cdb105abb75dfcc7 (patch)
treead5f58874ab147483a42638aa04ef8936b983694
parentb7ad0e60f7b0a5f5a1f6a2c80abc865fdb250ee5 (diff)
downloadazalea-drasl-53e630f73f5fcc82a6818448cdb105abb75dfcc7.tar.xz
add Event::ConnectionFailed and add more plugins by default when using Client::join
-rw-r--r--azalea-client/src/plugins/join.rs8
-rw-r--r--azalea/src/client_impl/mod.rs4
-rw-r--r--azalea/src/events.rs24
-rw-r--r--azalea/src/swarm/builder.rs9
4 files changed, 37 insertions, 8 deletions
diff --git a/azalea-client/src/plugins/join.rs b/azalea-client/src/plugins/join.rs
index a6c9c586..0f5747e9 100644
--- a/azalea-client/src/plugins/join.rs
+++ b/azalea-client/src/plugins/join.rs
@@ -86,7 +86,8 @@ pub struct ConnectOpts {
#[derive(Message)]
pub struct ConnectionFailedEvent {
pub entity: Entity,
- pub error: ConnectionError,
+ // wrap it in Arc so it can be cloned
+ pub error: Arc<ConnectionError>,
}
pub fn handle_start_join_server_event(
@@ -197,7 +198,10 @@ pub fn poll_create_connection_task(
Ok(conn) => conn,
Err(error) => {
warn!("failed to create connection: {error}");
- connection_failed_events.write(ConnectionFailedEvent { entity, error });
+ connection_failed_events.write(ConnectionFailedEvent {
+ entity,
+ error: Arc::new(error),
+ });
return;
}
};
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.