diff --git a/pumpkin/src/commands/gamemode.rs b/pumpkin/src/commands/gamemode.rs index 4533f06e9..42f86cbce 100644 --- a/pumpkin/src/commands/gamemode.rs +++ b/pumpkin/src/commands/gamemode.rs @@ -1,3 +1,8 @@ +use num_traits::FromPrimitive; +use pumpkin_text::TextComponent; + +use crate::entity::player::GameMode; + use super::Command; pub struct GamemodeCommand {} @@ -12,8 +17,7 @@ impl<'a> Command<'a> for GamemodeCommand { let args: Vec<&str> = command.split_whitespace().collect(); if args.len() != 2 { - // TODO: red - player.send_system_message("Usage: /gamemode ".into()); + player.send_system_message(TextComponent::from("Usage: /gamemode ").color_named(pumpkin_text::color::NamedColor::Red)); return; } @@ -21,11 +25,24 @@ impl<'a> Command<'a> for GamemodeCommand { match mode_str.parse() { Ok(mode) => { player.set_gamemode(mode); - player.send_system_message(format!("Set own game mode to {mode_str}").into()); + player.send_system_message(format!("Set own game mode to {:?}", mode).into()); } Err(_) => { - // TODO: red - player.send_system_message("Invalid gamemode".into()); + // try to parse from number + match mode_str.parse::() { + Ok(i) => match GameMode::from_u8(i) { + Some(mode) => { + player.set_gamemode(mode); + player.send_system_message(format!("Set own game mode to {:?}", mode).into()); + return; + }, + None => {}, + }, + Err(_) => {}, + } + + + player.send_system_message(TextComponent::from("Invalid gamemode").color_named(pumpkin_text::color::NamedColor::Red)); } } } diff --git a/pumpkin/src/entity/player.rs b/pumpkin/src/entity/player.rs index 07ccab380..ae4b13472 100644 --- a/pumpkin/src/entity/player.rs +++ b/pumpkin/src/entity/player.rs @@ -50,7 +50,7 @@ pub enum ChatMode { Hidden, } -#[derive(Clone, Copy, PartialEq, Serialize, Deserialize, FromPrimitive, ToPrimitive)] +#[derive(Clone, Copy, Debug, PartialEq, Serialize, Deserialize, FromPrimitive, ToPrimitive)] pub enum GameMode { Undefined = -1, Survival,