Add scripting system (part 2)

This commit is contained in:
ErrorNoInternet 2023-01-13 16:23:00 +08:00
parent 3507acd42d
commit faa0c12607
Signed by untrusted user who does not match committer: ErrorNoInternet
GPG Key ID: 2486BFB7B1E6A4A3
3 changed files with 7 additions and 9 deletions

2
Cargo.lock generated
View File

@ -665,13 +665,13 @@ name = "errornowatcher"
version = "0.1.0" version = "0.1.0"
dependencies = [ dependencies = [
"anyhow", "anyhow",
"async-recursion",
"azalea", "azalea",
"azalea-block", "azalea-block",
"azalea-core", "azalea-core",
"azalea-protocol", "azalea-protocol",
"chrono", "chrono",
"colored", "colored",
"futures",
"serde", "serde",
"strum", "strum",
"strum_macros", "strum_macros",

View File

@ -16,4 +16,4 @@ colored = "2.0.0"
chrono = "0.4.23" chrono = "0.4.23"
strum = "0.24.1" strum = "0.24.1"
strum_macros = "0.24.1" strum_macros = "0.24.1"
futures = "0.3.25" async-recursion = "1.0.0"

View File

@ -1,4 +1,5 @@
use crate::{logging::log_error, State}; use crate::{logging::log_error, State};
use async_recursion::async_recursion;
use azalea::{ use azalea::{
pathfinder::BlockPosGoal, prelude::*, BlockPos, SprintDirection, Vec3, WalkDirection, pathfinder::BlockPosGoal, prelude::*, BlockPos, SprintDirection, Vec3, WalkDirection,
}; };
@ -7,7 +8,6 @@ use azalea_protocol::packets::game::{
self, serverbound_interact_packet::InteractionHand, ServerboundGamePacket, self, serverbound_interact_packet::InteractionHand, ServerboundGamePacket,
}; };
use chrono::{Local, TimeZone}; use chrono::{Local, TimeZone};
use futures::future::{BoxFuture, FutureExt};
use strum::IntoEnumIterator; use strum::IntoEnumIterator;
use strum_macros::EnumIter; use strum_macros::EnumIter;
@ -44,12 +44,13 @@ pub enum Command {
Unknown, Unknown,
} }
#[async_recursion]
pub async fn process_command( pub async fn process_command(
command: &String, command: &String,
executor: &String, executor: &String,
client: &mut Client, client: &mut Client,
state: &mut State, state: &mut State,
) -> BoxFuture<'static, String> { ) -> String {
let mut segments: Vec<String> = command let mut segments: Vec<String> = command
.split(" ") .split(" ")
.map(|segment| segment.to_string()) .map(|segment| segment.to_string())
@ -649,12 +650,9 @@ pub async fn process_command(
Ok(script) => script, Ok(script) => script,
Err(error) => return format!("Unable to read script: {}", error), Err(error) => return format!("Unable to read script: {}", error),
}; };
async move { for line in script.split("\n") {
for line in script.split("\n") { process_command(&line.to_string(), &executor, client, state).await;
process_command(&line.to_string(), &executor, client, state).await;
}
} }
.boxed();
return "Finished executing script!".to_string(); return "Finished executing script!".to_string();
} }