aboutsummaryrefslogtreecommitdiff
path: root/bot/src
diff options
context:
space:
mode:
authormat <github@matdoes.dev>2022-09-19 23:05:05 -0500
committermat <github@matdoes.dev>2022-09-19 23:05:05 -0500
commite63f605c824d62231bc2741347f8743a62e00617 (patch)
treef43846da56ef9813d2a6a7384bc00f4053c70260 /bot/src
parenta87c4cf718fcf7b16fecf463333bd46310c88c87 (diff)
downloadazalea-drasl-e63f605c824d62231bc2741347f8743a62e00617.tar.xz
add shutdown function
Diffstat (limited to 'bot/src')
-rw-r--r--bot/src/main.rs14
1 files changed, 13 insertions, 1 deletions
diff --git a/bot/src/main.rs b/bot/src/main.rs
index 5423e017..92c1bc91 100644
--- a/bot/src/main.rs
+++ b/bot/src/main.rs
@@ -1,8 +1,11 @@
use azalea_client::{Account, Client, Event, MoveDirection};
+use azalea_protocol::packets::game::ClientboundGamePacket;
use std::convert::TryInto;
#[tokio::main]
async fn main() {
+ env_logger::init();
+
let bot = Account::offline("bot");
let (bot, mut rx) = bot.join(&"localhost".try_into().unwrap()).await.unwrap();
@@ -12,7 +15,7 @@ async fn main() {
}
}
-async fn handle_event(event: Event, mut bot: Client) {
+async fn handle_event(event: Event, mut bot: Client) -> anyhow::Result<()> {
match event {
Event::Login => {
// tokio::time::sleep(std::time::Duration::from_secs(1)).await;
@@ -22,6 +25,15 @@ async fn handle_event(event: Event, mut bot: Client) {
// }
// bot.walk(MoveDirection::None);
}
+ Event::Packet(packet) => {
+ if let ClientboundGamePacket::SetHealth(_) = *packet {
+ println!("got set health");
+ bot.shutdown().await?;
+ panic!();
+ }
+ }
_ => {}
}
+
+ Ok(())
}