Compare commits

...

4 Commits

2 changed files with 29 additions and 15 deletions

View File

@ -5,7 +5,10 @@ use crate::{
lua::{self, direction::Direction, player::Player, vec3::Vec3},
particle,
};
use azalea::{prelude::*, protocol::packets::game::ClientboundGamePacket};
use azalea::{
brigadier::exceptions::BuiltInExceptions::DispatcherUnknownCommand, prelude::*,
protocol::packets::game::ClientboundGamePacket,
};
use hyper::{server::conn::http1, service::service_fn};
use hyper_util::rt::TokioIo;
use log::{debug, error, info, trace};
@ -29,9 +32,10 @@ pub async fn handle_event(client: Client, event: Event, state: State) -> anyhow:
let ansi_text = text.to_ansi();
info!("{ansi_text}");
let mut is_encrypted = false;
if let Some(ref sender) = sender {
let mut ncr_options = None;
if let Ok(options) = globals.get::<Table>("NcrOptions")
let ncr_options = globals.get::<Table>("NcrOptions").ok();
if let Some(ref options) = ncr_options
&& let Ok(decrypt) = globals.get::<Function>("ncr_decrypt")
&& let Some(plaintext) = decrypt
.call::<String>((options.clone(), content.clone()))
@ -39,13 +43,17 @@ pub async fn handle_event(client: Client, event: Event, state: State) -> anyhow:
.as_deref()
.and_then(|s| trim_header(s).ok())
{
ncr_options = Some(options);
is_encrypted = true;
plaintext.clone_into(&mut content);
info!("decrypted message from {sender}: {content}");
}
if is_whisper && globals.get::<Vec<String>>("Owners")?.contains(sender) {
if let Err(error) = state.commands.execute(
if is_whisper
&& globals
.get::<Vec<String>>("Owners")
.unwrap_or_default()
.contains(sender)
&& let Err(error) = state.commands.execute(
content.clone(),
CommandSource {
client: client.clone(),
@ -54,7 +62,9 @@ pub async fn handle_event(client: Client, event: Event, state: State) -> anyhow:
ncr_options: ncr_options.clone(),
}
.into(),
) {
)
&& error.type_ != DispatcherUnknownCommand
{
CommandSource {
client,
message,
@ -64,7 +74,6 @@ pub async fn handle_event(client: Client, event: Event, state: State) -> anyhow:
.reply(&format!("{error:?}"));
}
}
}
let table = state.lua.create_table()?;
table.set("text", text.to_string())?;
@ -73,6 +82,7 @@ pub async fn handle_event(client: Client, event: Event, state: State) -> anyhow:
table.set("content", content)?;
table.set("uuid", uuid)?;
table.set("is_whisper", is_whisper)?;
table.set("is_encrypted", is_encrypted)?;
call_listeners(&state, "chat", table).await;
}
Event::Death(packet) => {

View File

@ -51,7 +51,11 @@ pub fn find_blocks(
.collect())
}
pub async fn find_all_entities(lua: Lua, client: UserDataRef<Client>, (): ()) -> Result<Vec<Table>> {
pub async fn find_all_entities(
lua: Lua,
client: UserDataRef<Client>,
(): (),
) -> Result<Vec<Table>> {
let mut matched = Vec::new();
for (position, custom_name, kind, uuid, direction, id, owner_uuid, pose) in
get_entities!(client)