From 2ba7b83490f5fb6e40a4e94da743bebe23cd7862 Mon Sep 17 00:00:00 2001 From: mat Date: Tue, 16 May 2023 23:26:45 -0500 Subject: ClientBuilder::new_without_plugins --- azalea/src/swarm/mod.rs | 41 +++++++++++++++++++++++++++++++++++++---- 1 file changed, 37 insertions(+), 4 deletions(-) (limited to 'azalea/src/swarm') diff --git a/azalea/src/swarm/mod.rs b/azalea/src/swarm/mod.rs index 2253f5bd..f138950f 100644 --- a/azalea/src/swarm/mod.rs +++ b/azalea/src/swarm/mod.rs @@ -5,7 +5,9 @@ mod events; pub mod prelude; use crate::{bot::DefaultBotPlugins, HandleFn}; -use azalea_client::{chat::ChatPacket, init_ecs_app, start_ecs, Account, Client, Event, JoinError}; +use azalea_client::{ + chat::ChatPacket, start_ecs, Account, Client, DefaultPlugins, Event, JoinError, +}; use azalea_protocol::{ connect::ConnectionError, resolver::{self, ResolverError}, @@ -83,10 +85,43 @@ where /// 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`] but without adding the plugins by default. This is useful + /// if you want to disable a default plugin. + /// + /// You **must** add [`DefaultPlugins`], [`DefaultBotPlugins`], and + /// [`DefaultSwarmPlugins`] to this. + /// + /// ``` + /// # use azalea::{prelude::*, swarm::prelude::*}; + /// use azalea::{app::PluginGroup, DefaultBotPlugins, DefaultPlugins, swarm::{DefaultSwarmPlugins}}; + /// use bevy_log::LogPlugin; + /// + /// let client = SwarmBuilder::new_without_plugins() + /// .add_plugins(DefaultPlugins.build().disable::()) + /// .add_plugins(DefaultBotPlugins) + /// .add_plugins(DefaultSwarmPlugins); + /// # client.set_handler(handle).set_swarm_handler(swarm_handle); + /// # #[derive(Component, Resource, Clone, Default)] + /// # pub struct State; + /// # async fn handle(mut bot: Client, event: Event, state: State) -> anyhow::Result<()> { + /// # Ok(()) + /// # } + /// # async fn swarm_handle(swarm: Swarm, event: SwarmEvent, state: State) -> anyhow::Result<()> { + /// # Ok(()) + /// # } + /// ``` + #[must_use] + pub fn new_without_plugins() -> Self { Self { // we create the app here so plugins can add onto it. // the schedules won't run until [`Self::start`] is called. - app: init_ecs_app(), + app: App::new(), accounts: Vec::new(), states: Vec::new(), @@ -95,8 +130,6 @@ where swarm_handler: None, join_delay: None, } - .add_plugins(DefaultSwarmPlugins) - .add_plugins(DefaultBotPlugins) } /// Add a vec of [`Account`]s to the swarm. -- cgit v1.2.3 From e2f9d59c458bb226e88dca50355dbe49ce7f6fc7 Mon Sep 17 00:00:00 2001 From: mat Date: Tue, 16 May 2023 23:32:10 -0500 Subject: better variable naming in doc --- azalea/src/lib.rs | 4 ++-- azalea/src/swarm/mod.rs | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) (limited to 'azalea/src/swarm') diff --git a/azalea/src/lib.rs b/azalea/src/lib.rs index 09e88534..fd735585 100644 --- a/azalea/src/lib.rs +++ b/azalea/src/lib.rs @@ -96,10 +96,10 @@ where /// use azalea::{app::PluginGroup, DefaultBotPlugins, DefaultPlugins}; /// use bevy_log::LogPlugin; /// - /// let client = ClientBuilder::new_without_plugins() + /// let client_builder = ClientBuilder::new_without_plugins() /// .add_plugins(DefaultPlugins.build().disable::()) /// .add_plugins(DefaultBotPlugins); - /// # client.set_handler(handle); + /// # client_builder.set_handler(handle); /// # #[derive(Component, Clone, Default)] /// # pub struct State; /// # async fn handle(mut bot: Client, event: Event, state: State) -> anyhow::Result<()> { diff --git a/azalea/src/swarm/mod.rs b/azalea/src/swarm/mod.rs index f138950f..0bb9f7cd 100644 --- a/azalea/src/swarm/mod.rs +++ b/azalea/src/swarm/mod.rs @@ -102,11 +102,11 @@ where /// use azalea::{app::PluginGroup, DefaultBotPlugins, DefaultPlugins, swarm::{DefaultSwarmPlugins}}; /// use bevy_log::LogPlugin; /// - /// let client = SwarmBuilder::new_without_plugins() + /// let swarm_builder = SwarmBuilder::new_without_plugins() /// .add_plugins(DefaultPlugins.build().disable::()) /// .add_plugins(DefaultBotPlugins) /// .add_plugins(DefaultSwarmPlugins); - /// # client.set_handler(handle).set_swarm_handler(swarm_handle); + /// # swarm_builder.set_handler(handle).set_swarm_handler(swarm_handle); /// # #[derive(Component, Resource, Clone, Default)] /// # pub struct State; /// # async fn handle(mut bot: Client, event: Event, state: State) -> anyhow::Result<()> { -- cgit v1.2.3