From e6c6e7b10bda81d0af4a6bda90989d398bc6aea7 Mon Sep 17 00:00:00 2001 From: didli789 <20859888+didli789@users.noreply.github.com> Date: Fri, 18 Oct 2024 14:22:07 +0300 Subject: [PATCH 1/2] /kick --- pumpkin/src/commands/cmd_kick.rs | 30 ++++++++++++++++++++++++++++++ pumpkin/src/commands/mod.rs | 2 ++ 2 files changed, 32 insertions(+) create mode 100644 pumpkin/src/commands/cmd_kick.rs diff --git a/pumpkin/src/commands/cmd_kick.rs b/pumpkin/src/commands/cmd_kick.rs new file mode 100644 index 000000000..50b8f9b3a --- /dev/null +++ b/pumpkin/src/commands/cmd_kick.rs @@ -0,0 +1,30 @@ +use crate::commands::arg_player::{consume_arg_player, parse_arg_player}; +use crate::commands::tree::CommandTree; +use crate::commands::tree::RawArgs; +use crate::commands::tree_builder::argument; +use crate::commands::CommandSender; +use pumpkin_core::text::{color::NamedColor, TextComponent}; + +const NAMES: [&str; 1] = ["kick"]; +const DESCRIPTION: &str = "Kicks the target player from the server."; + +const ARG_TARGET: &str = "target"; + +pub fn consume_arg_target(_src: &CommandSender, args: &mut RawArgs) -> Option { + consume_arg_player(_src, args) +} + +pub 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.kick(TextComponent::text("Kicked by an operator")); + + sender.send_message( + TextComponent::text("Player has been kicked.").color_named(NamedColor::Blue), + ); + + Ok(()) + }), + ) +} diff --git a/pumpkin/src/commands/mod.rs b/pumpkin/src/commands/mod.rs index a0e10041f..11934c142 100644 --- a/pumpkin/src/commands/mod.rs +++ b/pumpkin/src/commands/mod.rs @@ -10,6 +10,7 @@ mod cmd_echest; mod cmd_gamemode; mod cmd_help; mod cmd_kill; +mod cmd_kick; mod cmd_pumpkin; mod cmd_stop; pub mod dispatcher; @@ -75,6 +76,7 @@ pub fn default_dispatcher<'a>() -> CommandDispatcher<'a> { dispatcher.register(cmd_help::init_command_tree()); dispatcher.register(cmd_echest::init_command_tree()); dispatcher.register(cmd_kill::init_command_tree()); + dispatcher.register(cmd_kick::init_command_tree()); dispatcher } From bd1d1ebfe77a5208e2f55eb113e91e6a3219dae6 Mon Sep 17 00:00:00 2001 From: didli789 <20859888+didli789@users.noreply.github.com> Date: Fri, 18 Oct 2024 14:38:15 +0300 Subject: [PATCH 2/2] code formatting --- pumpkin/src/commands/mod.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pumpkin/src/commands/mod.rs b/pumpkin/src/commands/mod.rs index 11934c142..ef6e1b230 100644 --- a/pumpkin/src/commands/mod.rs +++ b/pumpkin/src/commands/mod.rs @@ -9,8 +9,8 @@ mod arg_player; mod cmd_echest; mod cmd_gamemode; mod cmd_help; -mod cmd_kill; mod cmd_kick; +mod cmd_kill; mod cmd_pumpkin; mod cmd_stop; pub mod dispatcher;