From 679b112deeee1be9f773c6bd369bc1a975fe1628 Mon Sep 17 00:00:00 2001 From: mat Date: Wed, 28 Jan 2026 05:41:51 +0600 Subject: add Client::exit and Swarm::exit, and write related docs --- azalea/src/swarm/mod.rs | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) (limited to 'azalea/src/swarm') diff --git a/azalea/src/swarm/mod.rs b/azalea/src/swarm/mod.rs index 4ecb0726..de4d2ebe 100644 --- a/azalea/src/swarm/mod.rs +++ b/azalea/src/swarm/mod.rs @@ -16,7 +16,7 @@ use azalea_client::{account::Account, chat::ChatPacket, join::ConnectOpts}; use azalea_entity::LocalEntity; use azalea_protocol::address::ResolvedAddr; use azalea_world::Worlds; -use bevy_app::{PluginGroup, PluginGroupBuilder}; +use bevy_app::{AppExit, PluginGroup, PluginGroupBuilder}; use bevy_ecs::prelude::*; pub use builder::SwarmBuilder; use futures::future::BoxFuture; @@ -291,6 +291,21 @@ impl Swarm { let mut query = ecs.query_filtered::>(); query.iter(&ecs).collect::>() } + + /// End the entire swarm and return from [`SwarmBuilder::start`]. + /// + /// You should typically avoid calling this if you intend on creating the + /// swarm again, because creating an entirely new swarm can be a + /// relatively expensive process. + /// + /// If you only want to change the server that the bots are connecting to, + /// it may be better to call [`Swarm::add_with_opts`] with a different + /// server address. + /// + /// This is also implemented on [`Client`] as [`Client::exit`]. + pub fn exit(&self) { + self.ecs.write().write_message(AppExit::Success); + } } impl IntoIterator for Swarm { -- cgit v1.2.3