Snowiiii / Pumpkin

Empowering everyone to host fast and efficient Minecraft servers.
https://snowiiii.github.io/Pumpkin/
MIT License
3.22k stars 109 forks source link

Nicer Config #316

Open Commandcracker opened 1 day ago

Commandcracker commented 1 day ago

I've searched existing issues and couldn't find a duplicate.

Is your feature request related to a problem? Please describe.

What I would like

Describe the solution you'd like

Using toml_edit, to keep comments and something custom to translate struct doc comments into toml comments. Console warning if a value has not been set correctly and the default is used.

example:

/// Basic Server Configuration
/// See https://snowiiii.github.io/Pumpkin/config/introduction.html
/// and https://snowiiii.github.io/Pumpkin/config/basic.html
/// for thirder information!
#[derive(Serialize, Deserialize)]
#[serde(default)]
pub struct BasicConfiguration {
    /// The address to bind the server to.
    pub server_address: SocketAddr,
    /// The seed for world generation.
    pub seed: String,
    /// The maximum number of players allowed on the server. Specifying `0` disables the limit.
    pub max_players: u32,
    /// The maximum view distance for players.
    pub view_distance: u8,
    /// The maximum simulated view distance.
    pub simulation_distance: u8,
    /// The default game difficulty.
    pub default_difficulty: Difficulty,
    /// Whether the Nether dimension is enabled.
    pub allow_nether: bool,
    /// Whether the server is in hardcore mode.
    pub hardcore: bool,
    /// Whether online mode is enabled. Requires valid Minecraft accounts.
    pub online_mode: bool,
    /// Whether packet encryption is enabled. Required when online mode is enabled.
    pub encryption: bool,
    /// The server's description displayed on the status screen.
    pub motd: String,
    pub tps: f32,
    /// The default game mode for players.
    pub default_gamemode: GameMode,
    /// Whether to remove IPs from logs or not
    pub scrub_ips: bool,
    /// Whether to use a server favicon
    pub use_favicon: bool,
    /// Path to server favicon
    pub favicon_path: String,
}

->

# Basic Server Configuration
# See https://snowiiii.github.io/Pumpkin/config/introduction.html
# and https://snowiiii.github.io/Pumpkin/config/basic.html
# for thirder information!

# The address to bind the server to.
server_address = "0.0.0.0:25565"
# The seed for world generation.
seed = ""
# The maximum number of players allowed on the server. Specifying `0` disables the limit.
max_players = 100000
# The maximum view distance for players.
view_distance = 10
# The maximum simulated view distance.
simulation_distance = 10
# The default game difficulty.
default_difficulty = "Normal"
# Whether the Nether dimension is enabled.
allow_nether = true
# Whether the server is in hardcore mode.
hardcore = false
# Whether online mode is enabled. Requires valid Minecraft accounts.
online_mode = true
# Whether packet encryption is enabled. Required when online mode is enabled.
encryption = true
# The server's description displayed on the status screen.
motd = "A Blazing fast Pumpkin Server!"
tps = 20.0
# The default game mode for players.
default_gamemode = "Survival"
# Whether to remove IPs from logs or not
scrub_ips = true
# Whether to use a server favicon
use_favicon = true
favicon_path = "icon.png"
# Path to server favicon

Many values could be better grouped like view_distance and simulation_distance into "rendering" or online_mode and encryption into "rendering" in order to make the whole config file better structured.

Snowiiii commented 1 day ago

Im not sure about comments. There is no good way to add them using toml or Serde. I just planned to link people to the docs where you can then see up-to-date defaults and descriptions.

In the features.toml config everything is "grouped" together in categories . This is not the case in the configuration.toml because it is and will stay very simple, much like "server.properties" from vanilla. IMOP There are so few values that categories are unnecessary