refactor: convert to Player struct

This commit is contained in:
2025-02-21 21:36:24 -05:00
parent bd6698c4b4
commit 2f9e4f50cf
4 changed files with 44 additions and 15 deletions

35
src/lua/player.rs Normal file
View File

@@ -0,0 +1,35 @@
use azalea::PlayerInfo;
use mlua::{IntoLua, Lua, Result, Value};
#[derive(Clone)]
pub struct Player {
pub display_name: Option<String>,
pub gamemode: String,
pub latency: i32,
pub name: String,
pub uuid: String,
}
impl From<PlayerInfo> for Player {
fn from(p: PlayerInfo) -> Self {
Self {
display_name: p.display_name.map(|n| n.to_string()),
gamemode: p.gamemode.name().to_owned(),
latency: p.latency,
name: p.profile.name,
uuid: p.uuid.to_string(),
}
}
}
impl IntoLua for Player {
fn into_lua(self, lua: &Lua) -> Result<Value> {
let table = lua.create_table()?;
table.set("display_name", self.display_name)?;
table.set("gamemode", self.gamemode)?;
table.set("latency", self.latency)?;
table.set("name", self.name)?;
table.set("uuid", self.uuid)?;
Ok(Value::Table(table))
}
}