use std::{collections::HashMap, error::Error};
use serde::{Deserialize, Serialize};
use serde_json::Value;
use crate::{context::Context, util};
#[derive(Serialize, Deserialize, Clone, Debug)]
pub struct Advancements {
pub data_version: i32,
#[serde(flatten)]
other: HashMap<String, Value>,
}
impl Advancements {
pub fn new(ctx: &Context, uuid: String) -> Result<Self, Box<dyn Error>> {
let advancements = ctx.path().join("advancements");
let path = util::player_file(&uuid, advancements);
if let Some(path) = path {
let contents = std::fs::read_to_string(path)?;
let advancements: Advancements = serde_json::from_str(&contents)?;
return Ok(advancements);
}
Err("No advancements found".into())
}
pub fn get(&self, key: &str) -> Option<&Value> {
self.other.get(key)
}
pub fn get_mut(&mut self, key: &str) -> Option<&mut Value> {
self.other.get_mut(key)
}
}