From 1485cf975dfd51bb6c4eac0efefa75d582f06d2e Mon Sep 17 00:00:00 2001 From: Raptorox <70806316+Raptorox@users.noreply.github.com> Date: Sat, 1 Aug 2026 14:59:24 +0200 Subject: [PATCH] add gamemode --- src/command/gamemode.rs | 26 ++++++++++++++++++++++++++ src/command/mod.rs | 5 +++++ 2 files changed, 31 insertions(+) create mode 100644 src/command/gamemode.rs diff --git a/src/command/gamemode.rs b/src/command/gamemode.rs new file mode 100644 index 0000000..d6759ae --- /dev/null +++ b/src/command/gamemode.rs @@ -0,0 +1,26 @@ +#[derive(Default)] +pub struct GamemodeCommand { + gamemode: Option, + target: Option +} + +impl GamemodeCommand { + pub fn gamemode(mut self, gamemode: super::Gamemode) -> Self { + self.gamemode = Some(gamemode); + self + } + + pub fn target(mut self, target: super::Selector) -> Self { + self.target = Some(target); + self + } + + pub fn build(self) -> super::Command { + let gamemode = self.gamemode.unwrap_or(super::Gamemode::Survival); + let mut s = format!("defaultgamemode {gamemode}"); + if let Some(target) = self.target { + s.push_str(&format!(" {target}")) + } + super::Command(s) + } +} \ No newline at end of file diff --git a/src/command/mod.rs b/src/command/mod.rs index 0e64490..4ab2054 100644 --- a/src/command/mod.rs +++ b/src/command/mod.rs @@ -71,6 +71,7 @@ mod defaultgamemode; mod op; mod deop; mod difficulty; +mod gamemode; impl Command { pub fn raw(cmd: &str) -> Self { @@ -116,4 +117,8 @@ impl Command { pub fn difficulty() -> difficulty::DifficultyCommand { difficulty::DifficultyCommand::default() } + + pub fn gamemode() -> gamemode::GamemodeCommand { + gamemode::GamemodeCommand::default() + } } \ No newline at end of file