Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add kill command #107

Merged
merged 4 commits into from
Oct 1, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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