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"
dependencies = [
"anyhow",
"async-recursion",
"azalea",
"azalea-block",
"azalea-core",
"azalea-protocol",
"chrono",
"colored",
"futures",
"serde",
"strum",
"strum_macros",

View File

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