quectocraft2/src/plugin/event.rs
2023-07-26 00:53:51 -04:00

26 lines
641 B
Rust

use mlua::{Value, FromLua, Table};
use uuid::Uuid;
use crate::{Player, ClientInfo};
use super::UuidUD;
pub enum PluginEvent {
Kick(Uuid, Option<String>),
}
impl<'lua> FromLua<'lua> for PluginEvent {
fn from_lua(lua_value: Value<'lua>, lua: &'lua mlua::Lua) -> mlua::Result<Self> {
let table = Table::from_lua(lua_value, lua)?;
let ty: Box<str> = table.get("type")?;
match ty.as_ref() {
"kick" => Ok(Self::Kick(table.get::<_, UuidUD>("uuid")?.0, table.get("msg")?)),
_ => Err(mlua::Error::RuntimeError(format!("unknown event type {ty}"))),
}
}
}
pub enum ServerEvent {
Join(Player, ClientInfo),
Leave(Player),
}