Skip to content

Commit

Permalink
Merge pull request #146 from didli789/master
Browse files Browse the repository at this point in the history
/kick command
  • Loading branch information
Snowiiii authored Oct 18, 2024
2 parents c12fc46 + bd1d1eb commit 6915603
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 0 deletions.
30 changes: 30 additions & 0 deletions pumpkin/src/commands/cmd_kick.rs
Original file line number Diff line number Diff line change
@@ -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<String> {
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(())
}),
)
}
2 changes: 2 additions & 0 deletions pumpkin/src/commands/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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
}
Expand Down

0 comments on commit 6915603

Please sign in to comment.