From 0590a4f87d45839783810bceef93e418693a2c6a Mon Sep 17 00:00:00 2001 From: Alerty2 Date: Sun, 29 Sep 2024 17:06:23 +0200 Subject: [PATCH 1/4] adds the /kill command --- pumpkin/src/commands/cmd_kill.rs | 35 ++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) create mode 100644 pumpkin/src/commands/cmd_kill.rs diff --git a/pumpkin/src/commands/cmd_kill.rs b/pumpkin/src/commands/cmd_kill.rs new file mode 100644 index 00000000..747b7e96 --- /dev/null +++ b/pumpkin/src/commands/cmd_kill.rs @@ -0,0 +1,35 @@ +use pumpkin_core::text::{color::NamedColor, TextComponent}; +use crate::commands::tree::CommandTree; +use crate::commands::arg_player::{consume_arg_player, parse_arg_player}; +use crate::commands::tree::RawArgs; +use crate::commands::CommandSender; +use crate::commands::tree_builder::argument; + +const NAMES: [&str; 1] = ["kill"]; +const DESCRIPTION: &str = "Kills a target player."; + +const ARG_TARGET: &str = "target"; + +pub fn consume_arg_target(_src: &CommandSender, args: &mut RawArgs) -> Option { + consume_arg_player(_src, args) +} + +pub(crate) fn init_command_tree<'a>() -> CommandTree<'a> { + CommandTree::new(NAMES, DESCRIPTION) + .with_child( + argument(ARG_TARGET, consume_arg_target) + .execute(&|sender, server, args| { + let target = parse_arg_player(sender, server, ARG_TARGET, args)?; + target.entity.kill(); + target.send_system_message(TextComponent::text( + "You have been killed." + ).color_named(NamedColor::Red)); + + sender.send_message(TextComponent::text( + "Player has been killed." + ).color_named(NamedColor::Blue)); + + Ok(()) + }) + ) +} From 100f313c491ff039536fa3e663bf5a47462f2f33 Mon Sep 17 00:00:00 2001 From: Alerty2 Date: Sun, 29 Sep 2024 17:15:10 +0200 Subject: [PATCH 2/4] adds the /kill command --- pumpkin/src/commands/mod.rs | 2 ++ 1 file changed, 2 insertions(+) diff --git a/pumpkin/src/commands/mod.rs b/pumpkin/src/commands/mod.rs index 17393346..f3e260ad 100644 --- a/pumpkin/src/commands/mod.rs +++ b/pumpkin/src/commands/mod.rs @@ -13,6 +13,7 @@ mod cmd_gamemode; mod cmd_help; mod cmd_pumpkin; mod cmd_stop; +mod cmd_kill; pub mod dispatcher; mod tree; mod tree_builder; @@ -75,6 +76,7 @@ pub fn default_dispatcher<'a>() -> CommandDispatcher<'a> { dispatcher.register(cmd_stop::init_command_tree()); dispatcher.register(cmd_help::init_command_tree()); dispatcher.register(cmd_echest::init_command_tree()); + dispatcher.register(cmd_kill::init_command_tree()); dispatcher } From f15db29d2966727da35a813eb7e0aaa4ba62a6d0 Mon Sep 17 00:00:00 2001 From: Alerty2 Date: Mon, 30 Sep 2024 20:50:00 +0200 Subject: [PATCH 3/4] adds the /kill command --- pumpkin/src/commands/cmd_kill.rs | 34 +++++++++++++++----------------- pumpkin/src/commands/mod.rs | 2 +- 2 files changed, 17 insertions(+), 19 deletions(-) diff --git a/pumpkin/src/commands/cmd_kill.rs b/pumpkin/src/commands/cmd_kill.rs index 747b7e96..9f1e3f20 100644 --- a/pumpkin/src/commands/cmd_kill.rs +++ b/pumpkin/src/commands/cmd_kill.rs @@ -1,9 +1,9 @@ -use pumpkin_core::text::{color::NamedColor, TextComponent}; -use crate::commands::tree::CommandTree; use crate::commands::arg_player::{consume_arg_player, parse_arg_player}; +use crate::commands::tree::CommandTree; use crate::commands::tree::RawArgs; -use crate::commands::CommandSender; use crate::commands::tree_builder::argument; +use crate::commands::CommandSender; +use pumpkin_core::text::{color::NamedColor, TextComponent}; const NAMES: [&str; 1] = ["kill"]; const DESCRIPTION: &str = "Kills a target player."; @@ -15,21 +15,19 @@ pub fn consume_arg_target(_src: &CommandSender, args: &mut RawArgs) -> Option() -> CommandTree<'a> { - CommandTree::new(NAMES, DESCRIPTION) - .with_child( - argument(ARG_TARGET, consume_arg_target) - .execute(&|sender, server, args| { - let target = parse_arg_player(sender, server, ARG_TARGET, args)?; - target.entity.kill(); - target.send_system_message(TextComponent::text( - "You have been killed." - ).color_named(NamedColor::Red)); + CommandTree::new(NAMES, DESCRIPTION).with_child( + argument(ARG_TARGET, consume_arg_target).execute(&|sender, server, args| { + let target = parse_arg_player(sender, server, ARG_TARGET, args)?; + target.entity.kill(); + target.send_system_message( + TextComponent::text("You have been killed.").color_named(NamedColor::Red), + ); - sender.send_message(TextComponent::text( - "Player has been killed." - ).color_named(NamedColor::Blue)); + sender.send_message( + TextComponent::text("Player has been killed.").color_named(NamedColor::Blue), + ); - Ok(()) - }) - ) + Ok(()) + }), + ) } diff --git a/pumpkin/src/commands/mod.rs b/pumpkin/src/commands/mod.rs index f3e260ad..912b0318 100644 --- a/pumpkin/src/commands/mod.rs +++ b/pumpkin/src/commands/mod.rs @@ -11,9 +11,9 @@ mod arg_player; mod cmd_echest; mod cmd_gamemode; mod cmd_help; +mod cmd_kill; mod cmd_pumpkin; mod cmd_stop; -mod cmd_kill; pub mod dispatcher; mod tree; mod tree_builder; From f8740479e045e740ebaeaf85b38fdae08ca04a9c Mon Sep 17 00:00:00 2001 From: Alerty2 Date: Tue, 1 Oct 2024 21:19:29 +0200 Subject: [PATCH 4/4] adds the /kick command --- pumpkin/src/commands/cmd_kill.rs | 3 --- 1 file changed, 3 deletions(-) diff --git a/pumpkin/src/commands/cmd_kill.rs b/pumpkin/src/commands/cmd_kill.rs index 9f1e3f20..d3b8135e 100644 --- a/pumpkin/src/commands/cmd_kill.rs +++ b/pumpkin/src/commands/cmd_kill.rs @@ -19,9 +19,6 @@ pub(crate) fn init_command_tree<'a>() -> CommandTree<'a> { argument(ARG_TARGET, consume_arg_target).execute(&|sender, server, args| { let target = parse_arg_player(sender, server, ARG_TARGET, args)?; target.entity.kill(); - target.send_system_message( - TextComponent::text("You have been killed.").color_named(NamedColor::Red), - ); sender.send_message( TextComponent::text("Player has been killed.").color_named(NamedColor::Blue),