From 3a099b72f6def81874563f015b21d8b207183327 Mon Sep 17 00:00:00 2001 From: Raptorox <70806316+Raptorox@users.noreply.github.com> Date: Thu, 13 Aug 2026 23:13:54 +0200 Subject: [PATCH] use new() with primary argument instead of default() --- src/command/ban.rs | 12 ++++-------- src/command/banlist.rs | 1 - src/command/defaultgamemode.rs | 10 ++++------ src/command/deop.rs | 10 ++++------ src/command/difficulty.rs | 7 +++++-- src/command/gamemode.rs | 10 ++++------ src/command/kill.rs | 10 ++++------ src/command/list.rs | 5 ++++- src/command/mod.rs | 32 ++++++++++++++++---------------- src/command/op.rs | 10 ++++------ src/command/say.rs | 10 ++++------ 11 files changed, 53 insertions(+), 64 deletions(-) diff --git a/src/command/ban.rs b/src/command/ban.rs index 8783e2b..42e2dcf 100644 --- a/src/command/ban.rs +++ b/src/command/ban.rs @@ -1,16 +1,14 @@ use super::{Command, Selector}; -#[derive(Default)] pub struct BanCommand { - target: Option, + target: Selector, reason: Option, ip: Option, } impl BanCommand { - pub fn target(mut self, target: Selector) -> Self { - self.target = Some(target); - self + pub fn new(target: Selector) -> Self { + Self { target, reason: None, ip: None } } pub fn reason(mut self, reason: impl Into) -> Self { @@ -24,9 +22,7 @@ impl BanCommand { } pub fn build(self) -> Command { - let target = self - .target - .unwrap_or(Selector::Player("nonexistent".to_string())); + let target = self.target; let ip = self.ip.unwrap_or(false); let mut s = if ip { format!("ban-ip {target}") diff --git a/src/command/banlist.rs b/src/command/banlist.rs index 8ceba79..3d746b0 100644 --- a/src/command/banlist.rs +++ b/src/command/banlist.rs @@ -1,7 +1,6 @@ use super::Command; use std::marker::PhantomData; -#[derive(Default)] pub struct BanlistCommand { state: PhantomData, } diff --git a/src/command/defaultgamemode.rs b/src/command/defaultgamemode.rs index 6d2183c..6d89d24 100644 --- a/src/command/defaultgamemode.rs +++ b/src/command/defaultgamemode.rs @@ -1,18 +1,16 @@ use super::{Command, Gamemode}; -#[derive(Default)] pub struct DefaultGamemodeCommand { - gamemode: Option, + gamemode: Gamemode, } impl DefaultGamemodeCommand { - pub fn gamemode(mut self, gamemode: Gamemode) -> Self { - self.gamemode = Some(gamemode); - self + pub fn new(gamemode: Gamemode) -> Self { + Self { gamemode } } pub fn build(self) -> Command { - let gamemode = self.gamemode.unwrap_or(Gamemode::Survival); + let gamemode = self.gamemode; let s = format!("defaultgamemode {gamemode}"); Command(s) } diff --git a/src/command/deop.rs b/src/command/deop.rs index 05832dd..c30943e 100644 --- a/src/command/deop.rs +++ b/src/command/deop.rs @@ -1,18 +1,16 @@ use super::{Command, Selector}; -#[derive(Default)] pub struct DeopCommand { - target: Option, + target: Selector, } impl DeopCommand { - pub fn target(mut self, target: Selector) -> Self { - self.target = Some(target); - self + pub fn new(target: Selector) -> Self { + Self { target } } pub fn build(self) -> Command { - let target = self.target.unwrap_or(Selector::Executor); + let target = self.target; let s = format!("deop {target}"); Command(s) } diff --git a/src/command/difficulty.rs b/src/command/difficulty.rs index 4c01e6f..2c70da5 100644 --- a/src/command/difficulty.rs +++ b/src/command/difficulty.rs @@ -1,18 +1,21 @@ use super::{Command, Difficulty}; -#[derive(Default)] pub struct DifficultyCommand { difficulty: Option } impl DifficultyCommand { + pub fn new() -> Self { + Self { difficulty: None } + } + pub fn difficulty(mut self, difficulty: Difficulty) -> Self { self.difficulty = Some(difficulty); self } pub fn build(self) -> Command { - let mut s = format!("difficulty"); + let mut s = "difficulty".to_string(); if let Some(difficulty) = self.difficulty { s.push_str(&format!(" {difficulty}")) }; diff --git a/src/command/gamemode.rs b/src/command/gamemode.rs index 9a6b5d9..5a4e997 100644 --- a/src/command/gamemode.rs +++ b/src/command/gamemode.rs @@ -1,15 +1,13 @@ use super::{Command, Gamemode, Selector}; -#[derive(Default)] pub struct GamemodeCommand { - gamemode: Option, + gamemode: Gamemode, target: Option } impl GamemodeCommand { - pub fn gamemode(mut self, gamemode: Gamemode) -> Self { - self.gamemode = Some(gamemode); - self + pub fn new(gamemode: Gamemode) -> Self { + Self { gamemode, target: None } } pub fn target(mut self, target: Selector) -> Self { @@ -18,7 +16,7 @@ impl GamemodeCommand { } pub fn build(self) -> Command { - let gamemode = self.gamemode.unwrap_or(Gamemode::Survival); + let gamemode = self.gamemode; let mut s = format!("defaultgamemode {gamemode}"); if let Some(target) = self.target { s.push_str(&format!(" {target}")) diff --git a/src/command/kill.rs b/src/command/kill.rs index d365fbb..5e51a9b 100644 --- a/src/command/kill.rs +++ b/src/command/kill.rs @@ -1,18 +1,16 @@ use super::{Command, Selector}; -#[derive(Default)] pub struct KillCommand { - target: Option, + target: Selector, } impl KillCommand { - pub fn target(mut self, target: Selector) -> Self { - self.target = Some(target); - self + pub fn new(target: Selector) -> Self { + Self { target } } pub fn build(self) -> Command { - let target = self.target.unwrap_or(Selector::Executor); + let target = self.target; let s = format!("kill {target}"); Command(s) } diff --git a/src/command/list.rs b/src/command/list.rs index 398bdec..ad7f7b9 100644 --- a/src/command/list.rs +++ b/src/command/list.rs @@ -1,11 +1,14 @@ use super::Command; -#[derive(Default)] pub struct ListCommand { uuids: Option, } impl ListCommand { + pub fn new() -> Self { + Self { uuids: None } + } + pub fn uuids(mut self) -> Self { self.uuids = Some(true); self diff --git a/src/command/mod.rs b/src/command/mod.rs index 4ab2054..ce1f188 100644 --- a/src/command/mod.rs +++ b/src/command/mod.rs @@ -82,43 +82,43 @@ impl Command { &self.0 } - pub fn say() -> say::SayCommand { - say::SayCommand::default() + pub fn say(message: impl Into) -> say::SayCommand { + say::SayCommand::new(message.into()) } pub fn list() -> list::ListCommand { - list::ListCommand::default() + list::ListCommand::new() } - pub fn kill() -> kill::KillCommand { - kill::KillCommand::default() + pub fn kill(target: Selector) -> kill::KillCommand { + kill::KillCommand::new(target) } - pub fn ban() -> ban::BanCommand { - ban::BanCommand::default() + pub fn ban(target: Selector) -> ban::BanCommand { + ban::BanCommand::new(target) } pub fn banlist() -> banlist::BanlistCommand { banlist::BanlistCommand::new() } - pub fn defaultgamemode() -> defaultgamemode::DefaultGamemodeCommand { - defaultgamemode::DefaultGamemodeCommand::default() + pub fn defaultgamemode(gamemode: Gamemode) -> defaultgamemode::DefaultGamemodeCommand { + defaultgamemode::DefaultGamemodeCommand::new(gamemode) } - pub fn op() -> op::OpCommand { - op::OpCommand::default() + pub fn op(target: Selector) -> op::OpCommand { + op::OpCommand::new(target) } - pub fn deop() -> deop::DeopCommand { - deop::DeopCommand::default() + pub fn deop(target: Selector) -> deop::DeopCommand { + deop::DeopCommand::new(target) } pub fn difficulty() -> difficulty::DifficultyCommand { - difficulty::DifficultyCommand::default() + difficulty::DifficultyCommand::new() } - pub fn gamemode() -> gamemode::GamemodeCommand { - gamemode::GamemodeCommand::default() + pub fn gamemode(gamemode: Gamemode) -> gamemode::GamemodeCommand { + gamemode::GamemodeCommand::new(gamemode) } } \ No newline at end of file diff --git a/src/command/op.rs b/src/command/op.rs index 28e3cc2..94bb8de 100644 --- a/src/command/op.rs +++ b/src/command/op.rs @@ -1,18 +1,16 @@ use super::{Command, Selector}; -#[derive(Default)] pub struct OpCommand { - target: Option, + target: Selector, } impl OpCommand { - pub fn target(mut self, target: Selector) -> Self { - self.target = Some(target); - self + pub fn new(target: Selector) -> Self { + Self { target } } pub fn build(self) -> Command { - let target = self.target.unwrap_or(Selector::Executor); + let target = self.target; let s = format!("op {target}"); Command(s) } diff --git a/src/command/say.rs b/src/command/say.rs index 44e5fe5..acf940d 100644 --- a/src/command/say.rs +++ b/src/command/say.rs @@ -1,18 +1,16 @@ use super::Command; -#[derive(Default)] pub struct SayCommand { - message: Option, + message: String, } impl SayCommand { - pub fn message(mut self, msg: impl Into) -> Self { - self.message = Some(msg.into()); - self + pub fn new(message: String) -> Self { + Self { message } } pub fn build(self) -> Command { - let message = self.message.unwrap_or("Hello, world!".to_string()); + let message = self.message; let s = format!("say {message}"); Command(s) }