use std::collections::HashMap; use std::path::Path; /// Parse a Java .properties file into key-value pairs. pub fn read_properties(path: &Path) -> HashMap { let mut map = HashMap::new(); let Ok(contents) = std::fs::read_to_string(path) else { return map; }; for line in contents.lines() { let line = line.trim(); if line.is_empty() || line.starts_with('#') || line.starts_with('!') { continue; } if let Some((key, value)) = line.split_once('=') { map.insert(key.trim().to_string(), value.trim().to_string()); } else if let Some((key, value)) = line.split_once(':') { map.insert(key.trim().to_string(), value.trim().to_string()); } } map } /// Read the level-seed from an instance's server.properties. /// Returns None if the file doesn't exist or the seed is empty. pub fn read_instance_seed(server_dir: &Path, instance_name: &str) -> Option { let props_path = server_dir .join("instances") .join(instance_name) .join("data") .join("server.properties"); let props = read_properties(&props_path); let seed = props.get("level-seed")?; if seed.is_empty() { None } else { Some(seed.clone()) } }