From 02337adbdf2b08a87c48d7a3544bf6256b010b38 Mon Sep 17 00:00:00 2001 From: lukas0008 Date: Sun, 4 Aug 2024 21:29:10 +0200 Subject: [PATCH] Add default gamemode to configuration --- pumpkin/src/configuration.rs | 5 ++++- pumpkin/src/entity/player.rs | 3 ++- pumpkin/src/server.rs | 8 ++++++-- 3 files changed, 12 insertions(+), 4 deletions(-) diff --git a/pumpkin/src/configuration.rs b/pumpkin/src/configuration.rs index 32c2f737..f7166b87 100644 --- a/pumpkin/src/configuration.rs +++ b/pumpkin/src/configuration.rs @@ -2,7 +2,7 @@ use std::path::Path; use serde::{Deserialize, Serialize}; -use crate::server::Difficulty; +use crate::{entity::player::GameMode, server::Difficulty}; /// Current Config version of the Base Config const CURRENT_BASE_VERSION: &str = "1.0.0"; @@ -59,6 +59,8 @@ pub struct BasicConfiguration { pub prevent_proxy_connections: bool, /// The description send when Client performs a Status request, (e.g Multiplayer Screen) pub motd: String, + /// default gamemode (e.g. Survival, Creative...) + pub default_gamemode: GameMode, } impl Default for BasicConfiguration { @@ -80,6 +82,7 @@ impl Default for BasicConfiguration { encryption: true, prevent_proxy_connections: true, motd: "A Blazing fast Pumpkin Server!".to_string(), + default_gamemode: GameMode::Survival, } } } diff --git a/pumpkin/src/entity/player.rs b/pumpkin/src/entity/player.rs index 256df0e2..ff4fb467 100644 --- a/pumpkin/src/entity/player.rs +++ b/pumpkin/src/entity/player.rs @@ -1,4 +1,5 @@ use pumpkin_protocol::VarInt; +use serde::{Deserialize, Serialize}; use super::{Entity, EntityId}; @@ -74,7 +75,7 @@ impl ChatMode { } } -#[derive(Clone, Copy)] +#[derive(Clone, Copy, PartialEq, Serialize, Deserialize)] pub enum GameMode { Undefined, Survival, diff --git a/pumpkin/src/server.rs b/pumpkin/src/server.rs index bb0019d0..4fc9358e 100644 --- a/pumpkin/src/server.rs +++ b/pumpkin/src/server.rs @@ -131,8 +131,12 @@ impl Server { 0, "minecraft:overworld".into(), 0, // seed - GameMode::Survival.to_byte() as u8, - GameMode::Survival.to_byte(), + match self.base_config.default_gamemode { + GameMode::Undefined => GameMode::Survival, + game_mode => game_mode, + } + .to_byte() as u8, + self.base_config.default_gamemode.to_byte(), false, false, false, // deth loc