aboutsummaryrefslogtreecommitdiff
path: root/examples
diff options
context:
space:
mode:
authormat <27899617+mat-1@users.noreply.github.com>2022-07-29 04:56:21 +0000
committerGitHub <noreply@github.com>2022-07-29 04:56:21 +0000
commitaadf2de3cb751d563e743599a7fb345c08010f5a (patch)
treeaec2a9485c5057f1c148b87e23ee07a7a6b4978b /examples
parent3e43fc6c502573f9d48d801087e72cded37a30b8 (diff)
parent2211021105a7ce0ce9fcbc18f3b4f03b0f991a10 (diff)
downloadazalea-drasl-aadf2de3cb751d563e743599a7fb345c08010f5a.tar.xz
Merge pull request #8 from mat-1/1.19.1
Support 1.19.1. Signing stuff isn't implemented but auth isn't even in Azalea yet so that's fine.
Diffstat (limited to 'examples')
-rw-r--r--examples/craft_dig_straight_down.rs32
1 files changed, 26 insertions, 6 deletions
diff --git a/examples/craft_dig_straight_down.rs b/examples/craft_dig_straight_down.rs
index 54bf0015..47c4fe28 100644
--- a/examples/craft_dig_straight_down.rs
+++ b/examples/craft_dig_straight_down.rs
@@ -1,15 +1,35 @@
use azalea::{Bot, Event};
-let bot = Bot::offline("bot");
-// or let bot = azalea::Bot::microsoft("access token").await;
+struct Context {
+ pub started: bool
+}
+
+#[tokio::main]
+async fn main() {
+ let bot = Bot::offline("bot");
+ // or let bot = azalea::Bot::microsoft("access token").await;
+
+ bot.join("localhost".try_into().unwrap()).await.unwrap();
-bot.join("localhost".try_into().unwrap()).await.unwrap();
+ let ctx = Arc::new(Mutex::new(Context { started: false }));
-loop {
- match bot.next().await {
+ loop {
+ tokio::spawn(handle_event(bot.next().await, bot, ctx.clone()));
+ }
+}
+
+
+async fn handle_event(event: &Event, bot: &Bot, ctx: Arc<Context>) {
+ match event {
Event::Message(m) {
if m.username == bot.player.username { return };
if m.message = "go" {
+ // make sure we only start once
+ let ctx_lock = ctx.lock().unwrap();
+ if ctx_lock.started { return };
+ ctx_lock.started = true;
+ drop(ctx_lock);
+
bot.goto_goal(
pathfinder::Goals::NearXZ(5, azalea::BlockXZ(0, 0))
).await;
@@ -34,4 +54,4 @@ loop {
},
_ => {}
}
-}
+} \ No newline at end of file