chore: merge config files

This commit is contained in:
Alexander Medvedev 2026-05-11 16:59:45 +02:00
parent 6d63a72354
commit c8633b78d7
3 changed files with 57 additions and 50 deletions

3
.gitignore vendored
View File

@ -107,8 +107,7 @@ crash-reports/
data/*
# project's configurations
configuration.toml
features.toml
pumpkin.toml
*.local.nbt

View File

@ -45,6 +45,26 @@ use player_data::PlayerDataConfig;
use resource_pack::ResourcePackConfig;
use world::LevelConfig;
#[derive(Deserialize, Serialize, Default)]
#[serde(default)]
pub struct PumpkinConfig {
#[serde(flatten)]
pub basic: BasicConfiguration,
#[serde(flatten)]
pub advanced: AdvancedConfiguration,
}
impl LoadConfiguration for PumpkinConfig {
fn get_path() -> &'static Path {
Path::new("pumpkin.toml")
}
fn validate(&self) {
self.basic.validate();
self.advanced.validate();
}
}
/// Advanced configuration for optional and feature-specific server settings.
///
/// Allows enabling/disabling features, customizing behaviour, and
@ -179,6 +199,38 @@ impl BasicConfiguration {
pub fn get_world_path(&self) -> PathBuf {
PathBuf::from(&self.default_level_name)
}
pub fn validate(&self) {
let min = NonZeroU8::new(2).unwrap();
let max = NonZeroU8::new(64).unwrap();
assert!(
self.view_distance.ge(&min),
"View distance must be at least 2"
);
assert!(
self.view_distance.le(&max),
"View distance must be less than 64"
);
if self.online_mode {
assert!(
self.encryption,
"When online mode is enabled, encryption must be enabled"
);
}
if self.allow_chat_reports {
assert!(
self.online_mode,
"When allow_chat_reports is enabled, online_mode must be enabled"
);
}
}
}
impl AdvancedConfiguration {
pub const fn validate(&self) {
//self.resource_pack.validate();
}
}
/// Trait for loading and validating configuration from a TOML file.
@ -312,45 +364,3 @@ pub trait LoadConfiguration {
/// Validates the configuration after loading or merging.
fn validate(&self);
}
impl LoadConfiguration for AdvancedConfiguration {
fn get_path() -> &'static Path {
Path::new("features.toml")
}
fn validate(&self) {
//self.resource_pack.validate();
}
}
impl LoadConfiguration for BasicConfiguration {
fn get_path() -> &'static Path {
Path::new("configuration.toml")
}
fn validate(&self) {
let min = NonZeroU8::new(2).unwrap();
let max = NonZeroU8::new(64).unwrap();
assert!(
self.view_distance.ge(&min),
"View distance must be at least 2"
);
assert!(
self.view_distance.le(&max),
"View distance must be less than 64"
);
if self.online_mode {
assert!(
self.encryption,
"When online mode is enabled, encryption must be enabled"
);
}
if self.allow_chat_reports {
assert!(
self.online_mode,
"When allow_chat_reports is enabled, online_mode must be enabled"
);
}
}
}

View File

@ -27,7 +27,7 @@ use pumpkin::{
};
use pumpkin::{LoggerOption, PumpkinServer, SHOULD_STOP, STOP_INTERRUPT, stop_server};
use pumpkin_config::{AdvancedConfiguration, BasicConfiguration, LoadConfiguration};
use pumpkin_config::{LoadConfiguration, PumpkinConfig};
use pumpkin_util::text::{
TextComponent,
color::{Color, NamedColor},
@ -75,14 +75,12 @@ async fn main() {
let time = Instant::now();
let exec_dir = std::env::current_dir().unwrap();
let config_dir = exec_dir.join("config");
let basic_config = BasicConfiguration::load(&config_dir);
let advanced_config = AdvancedConfiguration::load(&config_dir);
let config = PumpkinConfig::load(&exec_dir);
let vanilla_data = VanillaData::load();
pumpkin::init_logger(&advanced_config);
pumpkin::init_logger(&config.advanced);
info!(
"{}",
@ -120,7 +118,7 @@ async fn main() {
.expect("Unable to setup signal handlers");
});
let pumpkin_server = PumpkinServer::new(basic_config, advanced_config, vanilla_data).await;
let pumpkin_server = PumpkinServer::new(config.basic, config.advanced, vanilla_data).await;
let plugin_wait_time = pumpkin_server.init_plugins().await;
let time_elapsed = time.elapsed().saturating_sub(plugin_wait_time);