diff --git a/pumpkin/src/commands/cmd_kick.rs b/pumpkin/src/commands/cmd_kick.rs new file mode 100644 index 00000000..50b8f9b3 --- /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 a0e10041..ef6e1b23 100644 --- a/pumpkin/src/commands/mod.rs +++ b/pumpkin/src/commands/mod.rs @@ -9,6 +9,7 @@ mod arg_player; mod cmd_echest; mod cmd_gamemode; mod cmd_help; +mod cmd_kick; mod cmd_kill; mod cmd_pumpkin; mod cmd_stop; @@ -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 }