add gamemode

This commit is contained in:
Raptorox 2026-08-01 14:59:24 +02:00
parent 75779c6fe9
commit 1485cf975d
No known key found for this signature in database
GPG key ID: 8B3556FC3ED1F6D8
2 changed files with 31 additions and 0 deletions

26
src/command/gamemode.rs Normal file
View file

@ -0,0 +1,26 @@
#[derive(Default)]
pub struct GamemodeCommand {
gamemode: Option<super::Gamemode>,
target: Option<super::Selector>
}
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)
}
}

View file

@ -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()
}
}