Skip to content

Commit

Permalink
Merge pull request #107 from Alerty2/add-kill-command
Browse files Browse the repository at this point in the history
Add kill command
  • Loading branch information
Snowiiii authored Oct 1, 2024
2 parents fff7357 + f874047 commit 0603060
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_kill.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] = ["kill"];
const DESCRIPTION: &str = "Kills a target player.";

const ARG_TARGET: &str = "target";

pub fn consume_arg_target(_src: &CommandSender, args: &mut RawArgs) -> Option<String> {
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();

sender.send_message(
TextComponent::text("Player has been killed.").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 @@ -11,6 +11,7 @@ mod arg_player;
mod cmd_echest;
mod cmd_gamemode;
mod cmd_help;
mod cmd_kill;
mod cmd_pumpkin;
mod cmd_stop;
pub mod dispatcher;
Expand Down Expand Up @@ -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
}
Expand Down

0 comments on commit 0603060

Please sign in to comment.