aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--azalea-client/src/account.rs4
-rw-r--r--azalea-client/src/lib.rs1
-rw-r--r--azalea-client/src/local_player.rs28
-rw-r--r--azalea-client/src/plugins/join.rs8
-rw-r--r--azalea-client/src/plugins/mod.rs4
-rw-r--r--azalea-client/src/plugins/packet/mod.rs4
-rw-r--r--azalea/src/auto_reconnect.rs (renamed from azalea-client/src/plugins/auto_reconnect.rs)15
-rw-r--r--azalea/src/bot.rs6
-rw-r--r--azalea/src/builder.rs2
-rw-r--r--azalea/src/client_impl/mod.rs12
-rw-r--r--azalea/src/client_impl/movement.rs2
-rw-r--r--azalea/src/events.rs (renamed from azalea-client/src/plugins/events.rs)9
-rw-r--r--azalea/src/lib.rs9
-rw-r--r--azalea/src/prelude.rs4
-rw-r--r--azalea/src/swarm/builder.rs7
-rw-r--r--azalea/src/swarm/mod.rs10
16 files changed, 41 insertions, 84 deletions
diff --git a/azalea-client/src/account.rs b/azalea-client/src/account.rs
index f988ade9..4db19d0e 100644
--- a/azalea-client/src/account.rs
+++ b/azalea-client/src/account.rs
@@ -14,7 +14,7 @@ use uuid::Uuid;
/// Something that can join Minecraft servers.
///
-/// To join a server using this account, use [`Client::join`] or
+/// To join a server using this account, use [`StartJoinServerEvent`] or
/// [`azalea::ClientBuilder`].
///
/// This is also an ECS component that is present on our client entities.
@@ -31,7 +31,7 @@ use uuid::Uuid;
/// # }
/// ```
///
-/// [`Client::join`]: crate::Client::join
+/// [`StartJoinServerEvent`]: crate::join::StartJoinServerEvent
/// [`azalea::ClientBuilder`]: https://docs.rs/azalea/latest/azalea/struct.ClientBuilder.html
#[derive(Clone, Component, Debug)]
pub struct Account {
diff --git a/azalea-client/src/lib.rs b/azalea-client/src/lib.rs
index d9e66333..6bdc2713 100644
--- a/azalea-client/src/lib.rs
+++ b/azalea-client/src/lib.rs
@@ -22,6 +22,5 @@ pub use bevy_tasks;
pub use client::{
InConfigState, InGameState, JoinedClientBundle, LocalPlayerBundle, start_ecs_runner,
};
-pub use events::Event;
pub use movement::{StartSprintEvent, StartWalkEvent};
pub use plugins::*;
diff --git a/azalea-client/src/local_player.rs b/azalea-client/src/local_player.rs
index 977b38f3..cc2a28dc 100644
--- a/azalea-client/src/local_player.rs
+++ b/azalea-client/src/local_player.rs
@@ -1,19 +1,13 @@
-use std::{
- collections::HashMap,
- error, io,
- sync::{Arc, PoisonError},
-};
+use std::{collections::HashMap, sync::Arc};
use azalea_core::game_type::GameMode;
use azalea_world::{Instance, PartialInstance};
use bevy_ecs::{component::Component, prelude::*};
use derive_more::{Deref, DerefMut};
use parking_lot::RwLock;
-use thiserror::Error;
-use tokio::sync::mpsc;
use uuid::Uuid;
-use crate::{ClientInformation, events::Event as AzaleaEvent, player::PlayerInfo};
+use crate::{ClientInformation, player::PlayerInfo};
/// A component that keeps strong references to our [`PartialInstance`] and
/// [`Instance`] for local players.
@@ -145,21 +139,3 @@ impl InstanceHolder {
self.partial_instance.write().reset();
}
}
-
-#[derive(Debug, Error)]
-pub enum HandlePacketError {
- #[error("{0}")]
- Poison(String),
- #[error(transparent)]
- Io(#[from] io::Error),
- #[error(transparent)]
- Other(#[from] Box<dyn error::Error + Send + Sync>),
- #[error("{0}")]
- Send(#[from] mpsc::error::SendError<AzaleaEvent>),
-}
-
-impl<T> From<PoisonError<T>> for HandlePacketError {
- fn from(e: PoisonError<T>) -> Self {
- HandlePacketError::Poison(e.to_string())
- }
-}
diff --git a/azalea-client/src/plugins/join.rs b/azalea-client/src/plugins/join.rs
index b1759992..058f6c10 100644
--- a/azalea-client/src/plugins/join.rs
+++ b/azalea-client/src/plugins/join.rs
@@ -19,7 +19,6 @@ use parking_lot::RwLock;
use tokio::sync::mpsc;
use tracing::{debug, warn};
-use super::events::LocalPlayerEvents;
use crate::{
Account, LocalPlayerBundle,
connection::RawConnection,
@@ -51,7 +50,6 @@ impl Plugin for JoinPlugin {
pub struct StartJoinServerEvent {
pub account: Account,
pub connect_opts: ConnectOpts,
- pub event_sender: Option<mpsc::UnboundedSender<crate::Event>>,
// this is mpsc instead of oneshot so it can be cloned (since it's sent in an event)
pub start_join_callback_tx: Option<mpsc::UnboundedSender<Entity>>,
@@ -147,12 +145,6 @@ pub fn handle_start_join_server_event(
// immediately when the connection is created
));
- if let Some(event_sender) = &event.event_sender {
- // this is optional so we don't leak memory in case the user doesn't want to
- // handle receiving packets
- entity_mut.insert(LocalPlayerEvents(event_sender.clone()));
- }
-
let task_pool = IoTaskPool::get();
let connect_opts = event.connect_opts.clone();
let task = task_pool.spawn(async_compat::Compat::new(
diff --git a/azalea-client/src/plugins/mod.rs b/azalea-client/src/plugins/mod.rs
index a4aec19f..35e26f9e 100644
--- a/azalea-client/src/plugins/mod.rs
+++ b/azalea-client/src/plugins/mod.rs
@@ -1,7 +1,6 @@
use bevy_app::{PluginGroup, PluginGroupBuilder};
pub mod attack;
-pub mod auto_reconnect;
pub mod block_update;
pub mod brand;
pub mod chat;
@@ -12,7 +11,6 @@ pub mod client_information;
pub mod connection;
pub mod cookies;
pub mod disconnect;
-pub mod events;
pub mod interact;
pub mod inventory;
pub mod join;
@@ -41,7 +39,6 @@ impl PluginGroup for DefaultPlugins {
.add(crate::client::AzaleaPlugin)
.add(azalea_entity::EntityPlugin)
.add(azalea_physics::PhysicsPlugin)
- .add(events::EventsPlugin)
.add(task_pool::TaskPoolPlugin::default())
.add(inventory::InventoryPlugin)
.add(chat::ChatPlugin)
@@ -62,7 +59,6 @@ impl PluginGroup for DefaultPlugins {
.add(connection::ConnectionPlugin)
.add(login::LoginPlugin)
.add(join::JoinPlugin)
- .add(auto_reconnect::AutoReconnectPlugin)
.add(cookies::CookiesPlugin);
#[cfg(feature = "online-mode")]
{
diff --git a/azalea-client/src/plugins/packet/mod.rs b/azalea-client/src/plugins/packet/mod.rs
index 30503d50..9d842dc6 100644
--- a/azalea-client/src/plugins/packet/mod.rs
+++ b/azalea-client/src/plugins/packet/mod.rs
@@ -6,7 +6,7 @@ use bevy_ecs::{
};
use self::game::DeathEvent;
-use crate::{chat::ChatReceivedEvent, events::death_listener};
+use crate::chat::ChatReceivedEvent;
pub mod config;
pub mod game;
@@ -33,7 +33,7 @@ impl Plugin for PacketPlugin {
app.add_observer(game::handle_outgoing_packets_observer)
.add_observer(config::handle_outgoing_packets_observer)
.add_observer(login::handle_outgoing_packets_observer)
- .add_systems(Update, death_event_on_0_health.before(death_listener))
+ .add_systems(Update, death_event_on_0_health)
.add_message::<game::ReceiveGamePacketEvent>()
.add_message::<config::ReceiveConfigPacketEvent>()
.add_message::<login::ReceiveLoginPacketEvent>()
diff --git a/azalea-client/src/plugins/auto_reconnect.rs b/azalea/src/auto_reconnect.rs
index 4851a4e7..dd353b7a 100644
--- a/azalea-client/src/plugins/auto_reconnect.rs
+++ b/azalea/src/auto_reconnect.rs
@@ -9,7 +9,6 @@ use bevy_ecs::prelude::*;
use super::{
disconnect::DisconnectEvent,
- events::LocalPlayerEvents,
join::{ConnectOpts, ConnectionFailedEvent, StartJoinServerEvent},
};
use crate::Account;
@@ -89,15 +88,9 @@ fn get_delay(
pub fn rejoin_after_delay(
mut commands: Commands,
mut join_events: MessageWriter<StartJoinServerEvent>,
- query: Query<(
- Entity,
- &InternalReconnectAfter,
- &Account,
- &ConnectOpts,
- Option<&LocalPlayerEvents>,
- )>,
+ query: Query<(Entity, &InternalReconnectAfter, &Account, &ConnectOpts)>,
) {
- for (entity, reconnect_after, account, connect_opts, local_player_events) in query.iter() {
+ for (entity, reconnect_after, account, connect_opts) in query.iter() {
if Instant::now() >= reconnect_after.instant {
// don't keep trying to reconnect
commands.entity(entity).remove::<InternalReconnectAfter>();
@@ -106,10 +99,6 @@ pub fn rejoin_after_delay(
join_events.write(StartJoinServerEvent {
account: account.clone(),
connect_opts: connect_opts.clone(),
- // not actually necessary since we're reusing the same entity and LocalPlayerEvents
- // isn't removed, but this is more readable and just in case it's changed in the
- // future
- event_sender: local_player_events.map(|e| e.0.clone()),
start_join_callback_tx: None,
});
}
diff --git a/azalea/src/bot.rs b/azalea/src/bot.rs
index 6f39c2fe..73b225b2 100644
--- a/azalea/src/bot.rs
+++ b/azalea/src/bot.rs
@@ -130,9 +130,7 @@ impl Client {
/// Mine a block.
///
/// This won't turn the bot's head towards the block, so if that's necessary
- /// you'll have to do that yourself with [`look_at`].
- ///
- /// [`look_at`]: crate::prelude::BotClientExt::look_at
+ /// you'll have to do that yourself with [`look_at`](Client::look_at).
pub async fn mine(&self, position: BlockPos) {
self.start_mining(position);
@@ -211,5 +209,7 @@ impl PluginGroup for DefaultBotPlugins {
.add(crate::auto_respawn::AutoRespawnPlugin)
.add(crate::accept_resource_packs::AcceptResourcePacksPlugin)
.add(crate::tick_broadcast::TickBroadcastPlugin)
+ .add(crate::events::EventsPlugin)
+ .add(crate::auto_reconnect::AutoReconnectPlugin)
}
}
diff --git a/azalea/src/builder.rs b/azalea/src/builder.rs
index 91fb9d5e..8151b3a1 100644
--- a/azalea/src/builder.rs
+++ b/azalea/src/builder.rs
@@ -150,7 +150,7 @@ where
/// If this function isn't called, then our client will reconnect after
/// [`DEFAULT_RECONNECT_DELAY`].
///
- /// [`DEFAULT_RECONNECT_DELAY`]: azalea_client::auto_reconnect::DEFAULT_RECONNECT_DELAY
+ /// [`DEFAULT_RECONNECT_DELAY`]: crate::auto_reconnect::DEFAULT_RECONNECT_DELAY
#[must_use]
pub fn reconnect_after(mut self, delay: impl Into<Option<Duration>>) -> Self {
self.swarm.reconnect_after = delay.into();
diff --git a/azalea/src/client_impl/mod.rs b/azalea/src/client_impl/mod.rs
index 2f5fbf7d..36995656 100644
--- a/azalea/src/client_impl/mod.rs
+++ b/azalea/src/client_impl/mod.rs
@@ -2,7 +2,7 @@ use std::{collections::HashMap, sync::Arc};
use azalea_auth::game_profile::GameProfile;
use azalea_client::{
- Account, DefaultPlugins, Event,
+ Account, DefaultPlugins,
connection::RawConnection,
disconnect::DisconnectEvent,
join::{ConnectOpts, StartJoinServerEvent},
@@ -40,6 +40,8 @@ use parking_lot::{Mutex, RwLock};
use tokio::sync::mpsc;
use uuid::Uuid;
+use crate::events::{Event, LocalPlayerEvents};
+
pub mod attack;
pub mod chat;
pub mod client_information;
@@ -210,7 +212,6 @@ impl Client {
ecs_lock.lock().write_message(StartJoinServerEvent {
account,
connect_opts,
- event_sender,
start_join_callback_tx: Some(start_join_callback_tx),
});
@@ -218,6 +219,13 @@ impl Client {
"start_join_callback should not be dropped before sending a message, this is a bug in Azalea",
);
+ if let Some(event_sender) = event_sender {
+ ecs_lock
+ .lock()
+ .entity_mut(entity)
+ .insert(LocalPlayerEvents(event_sender));
+ }
+
Client::new(entity, ecs_lock)
}
diff --git a/azalea/src/client_impl/movement.rs b/azalea/src/client_impl/movement.rs
index 08624263..b47da9a7 100644
--- a/azalea/src/client_impl/movement.rs
+++ b/azalea/src/client_impl/movement.rs
@@ -28,7 +28,7 @@ impl Client {
/// Whether the client is currently trying to sneak.
///
- /// You may want to check the [`Pose`] instead.
+ /// You may want to check the [`Pose`](azalea_entity::Pose) instead.
pub fn crouching(&self) -> bool {
self.query_self::<&PhysicsState, _>(|p| p.trying_to_crouch)
}
diff --git a/azalea-client/src/plugins/events.rs b/azalea/src/events.rs
index bd0419cb..0920dbd8 100644
--- a/azalea-client/src/plugins/events.rs
+++ b/azalea/src/events.rs
@@ -93,7 +93,7 @@ pub enum Event {
/// We received a packet from the server.
///
/// ```
- /// # use azalea_client::Event;
+ /// # use azalea::Event;
/// # use azalea_protocol::packets::game::ClientboundGamePacket;
/// # async fn example(event: Event) {
/// # match event {
@@ -129,9 +129,8 @@ pub enum Event {
/// A component that contains an event sender for events that are only
/// received by local players.
///
-/// The receiver for this is returned by [`Client::start_client`].
-///
-/// [`Client::start_client`]: crate::Client::start_client
+/// The receiver for this is returned by
+/// [`Client::start_client`](crate::Client::start_client).
#[derive(Component, Deref, DerefMut)]
pub struct LocalPlayerEvents(pub mpsc::UnboundedSender<Event>);
@@ -150,7 +149,7 @@ impl Plugin for EventsPlugin {
update_player_listener,
remove_player_listener,
keepalive_listener,
- death_listener,
+ death_listener.after(azalea_client::packet::death_event_on_0_health),
disconnect_listener,
receive_chunk_listener,
),
diff --git a/azalea/src/lib.rs b/azalea/src/lib.rs
index 2105daee..351c956a 100644
--- a/azalea/src/lib.rs
+++ b/azalea/src/lib.rs
@@ -2,12 +2,14 @@
#![feature(type_changing_struct_update)]
pub mod accept_resource_packs;
+pub mod auto_reconnect;
pub mod auto_respawn;
pub mod auto_tool;
pub mod bot;
mod builder;
mod client_impl;
pub mod container;
+pub mod events;
mod join_opts;
pub mod nearest_entity;
pub mod pathfinder;
@@ -51,11 +53,10 @@ pub use builder::ClientBuilder;
use futures::future::BoxFuture;
pub use join_opts::JoinOpts;
-pub use crate::client_impl::Client;
+pub use crate::{client_impl::Client, events::Event};
-pub type BoxHandleFn<S, R> =
- Box<dyn Fn(Client, azalea_client::Event, S) -> BoxFuture<'static, R> + Send>;
-pub type HandleFn<S, Fut> = fn(Client, azalea_client::Event, S) -> Fut;
+pub type BoxHandleFn<S, R> = Box<dyn Fn(Client, Event, S) -> BoxFuture<'static, R> + Send>;
+pub type HandleFn<S, Fut> = fn(Client, Event, S) -> Fut;
/// A marker that can be used in place of a State in [`ClientBuilder`] or
/// [`SwarmBuilder`].
diff --git a/azalea/src/prelude.rs b/azalea/src/prelude.rs
index 2675c8f5..d39e50c4 100644
--- a/azalea/src/prelude.rs
+++ b/azalea/src/prelude.rs
@@ -1,14 +1,14 @@
//! The Azalea prelude. Things that are necessary for a bare-bones bot are
//! re-exported here.
-pub use azalea_client::{Account, Event};
+pub use azalea_client::Account;
pub use azalea_core::tick::GameTick;
pub use bevy_app::AppExit;
// this is necessary to make the macros that reference bevy_ecs work
pub use crate::ecs as bevy_ecs;
pub use crate::{
- Client, ClientBuilder,
+ Client, ClientBuilder, Event,
ecs::{component::Component, resource::Resource},
pathfinder::PathfinderClientExt,
};
diff --git a/azalea/src/swarm/builder.rs b/azalea/src/swarm/builder.rs
index 4eae7eab..860e47be 100644
--- a/azalea/src/swarm/builder.rs
+++ b/azalea/src/swarm/builder.rs
@@ -8,11 +8,7 @@ use std::{
time::Duration,
};
-use azalea_client::{
- Account, DefaultPlugins,
- auto_reconnect::{AutoReconnectDelay, DEFAULT_RECONNECT_DELAY},
- start_ecs_runner,
-};
+use azalea_client::{Account, DefaultPlugins, start_ecs_runner};
use azalea_protocol::address::{ResolvableAddr, ResolvedAddr};
use azalea_world::InstanceContainer;
use bevy_app::{App, AppExit, Plugins, SubApp};
@@ -24,6 +20,7 @@ use tracing::{debug, error, warn};
use crate::{
BoxHandleFn, HandleFn, JoinOpts, NoState,
+ auto_reconnect::{AutoReconnectDelay, DEFAULT_RECONNECT_DELAY},
bot::DefaultBotPlugins,
swarm::{
BoxSwarmHandleFn, DefaultSwarmPlugins, NoSwarmState, Swarm, SwarmEvent, SwarmHandleFn,
diff --git a/azalea/src/swarm/mod.rs b/azalea/src/swarm/mod.rs
index c0f9cbca..48ac20a3 100644
--- a/azalea/src/swarm/mod.rs
+++ b/azalea/src/swarm/mod.rs
@@ -12,7 +12,7 @@ use std::sync::{
atomic::{self, AtomicBool},
};
-use azalea_client::{Account, Event, chat::ChatPacket, join::ConnectOpts};
+use azalea_client::{Account, chat::ChatPacket, join::ConnectOpts};
use azalea_entity::LocalEntity;
use azalea_protocol::address::ResolvedAddr;
use azalea_world::InstanceContainer;
@@ -45,7 +45,7 @@ pub struct Swarm {
pub instance_container: Arc<RwLock<InstanceContainer>>,
/// This is used internally to make the client handler function work.
- pub(crate) bots_tx: mpsc::UnboundedSender<(Option<Event>, Client)>,
+ pub(crate) bots_tx: mpsc::UnboundedSender<(Option<crate::Event>, Client)>,
/// This is used internally to make the swarm handler function work.
pub(crate) swarm_tx: mpsc::UnboundedSender<SwarmEvent>,
}
@@ -207,9 +207,9 @@ impl Swarm {
/// Copy the events from a client's receiver into bots_tx, until the bot is
/// removed from the ECS.
async fn event_copying_task(
- mut rx: mpsc::UnboundedReceiver<Event>,
+ mut rx: mpsc::UnboundedReceiver<crate::Event>,
swarm_tx: mpsc::UnboundedSender<SwarmEvent>,
- bots_tx: mpsc::UnboundedSender<(Option<Event>, Client)>,
+ bots_tx: mpsc::UnboundedSender<(Option<crate::Event>, Client)>,
bot: Client,
join_opts: JoinOpts,
) {
@@ -246,7 +246,7 @@ impl Swarm {
}
}
- if let Event::Disconnect(_) = event {
+ if let crate::Event::Disconnect(_) = event {
debug!(
"Sending SwarmEvent::Disconnect due to receiving an Event::Disconnect from client {}",
bot.entity