diff --git a/pumpkin-config/src/advancement.rs b/pumpkin-config/src/advancement.rs new file mode 100644 index 000000000..4a4a1ec35 --- /dev/null +++ b/pumpkin-config/src/advancement.rs @@ -0,0 +1,18 @@ +use serde::{Deserialize, Serialize}; +/// Configuration for advancements +/// +/// Controls whether the advancements should be saved and loaded +#[derive(Deserialize, Serialize)] +#[serde(default)] +pub struct AdvancementConfig { + /// Whether saving advancements is enabled. + pub save_advancements: bool, +} + +impl Default for AdvancementConfig { + fn default() -> Self { + Self { + save_advancements: true, + } + } +} diff --git a/pumpkin-config/src/lib.rs b/pumpkin-config/src/lib.rs index faea0b021..57ce9cae5 100644 --- a/pumpkin-config/src/lib.rs +++ b/pumpkin-config/src/lib.rs @@ -34,12 +34,14 @@ pub mod chunk; pub mod lighting; pub mod op; +mod advancement; mod player_data; mod pvp; mod server_links; pub mod whitelist; pub mod world; +use advancement::AdvancementConfig; use networking::NetworkingConfig; use player_data::PlayerDataConfig; use resource_pack::ResourcePackConfig; @@ -98,6 +100,8 @@ pub struct AdvancedConfiguration { pub recipe: RecipeConfig, /// Plugin-related configuration. pub plugins: PluginsConfig, + /// Advancement configuration + pub advancement: AdvancementConfig, } /// Basic configuration for core server settings. diff --git a/pumpkin/src/entity/player/advancement.rs b/pumpkin/src/entity/player/advancement.rs index 7246b9a07..47d4c1c4b 100644 --- a/pumpkin/src/entity/player/advancement.rs +++ b/pumpkin/src/entity/player/advancement.rs @@ -282,7 +282,7 @@ impl PlayerAdvancement { /// Loads the player's advancement progress from disk. pub async fn load(&mut self) -> Result<(), AdvancementDataError> { - if !self.path.exists() { + if !self.path.exists() || !self.is_save_enabled() { return Ok(()); } @@ -777,4 +777,26 @@ mod tests { serde_json::from_str(&content).unwrap(); assert_eq!(saved_data.len(), 2, "Should have saved both advancements"); } + + #[tokio::test] + async fn ignore_loading() { + let temp_dir = tempdir().unwrap(); + let manager = Arc::new(AdvancementManager::new(temp_dir.path(), false)); + + let id = Uuid::new_v4(); + let mut pa = PlayerAdvancement::new(manager, id); + // Create a JSON file with advancement data + let adv = Advancement::STORY_ROOT; + let data = serde_json::json!({ adv.id.to_string(): { "complete": true } }); + std::fs::write(&pa.path, data.to_string()).unwrap(); + + //try load the file + assert!(pa.load().await.is_ok(), "Load should succeed"); + + // Verify that the advancement was not loaded + assert!( + pa.progress.is_empty(), + "The advancement shouldn't have been loaded" + ); + } } diff --git a/pumpkin/src/server/mod.rs b/pumpkin/src/server/mod.rs index 4f89810f9..f4d12ec54 100644 --- a/pumpkin/src/server/mod.rs +++ b/pumpkin/src/server/mod.rs @@ -204,7 +204,10 @@ impl Server { Duration::from_secs(advanced_config.player_data.save_player_cron_interval), advanced_config.player_data.save_player_data, ); - let advancement_manager = Arc::new(AdvancementManager::new(players_dir.clone(), true)); + let advancement_manager = Arc::new(AdvancementManager::new( + players_dir.clone(), + advanced_config.advancement.save_advancements, + )); let white_list = AtomicBool::new(basic_config.white_list); let tick_rate_manager = Arc::new(ServerTickRateManager::new(basic_config.tps));