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