Pumpkin/pumpkin/src/command/commands/cmd_stop.rs
Snowiiii 9f70b95b9b Split commands into their own Folder
Now its much nicer separate from the command base
2024-10-29 22:47:52 +01:00

36 lines
1.0 KiB
Rust

use async_trait::async_trait;
use pumpkin_core::text::color::NamedColor;
use pumpkin_core::text::TextComponent;
use crate::command::tree::CommandTree;
use crate::command::tree_builder::require;
use crate::command::{tree::ConsumedArgs, CommandExecutor, CommandSender, InvalidTreeError};
const NAMES: [&str; 1] = ["stop"];
const DESCRIPTION: &str = "Stop the server.";
struct StopExecutor {}
#[async_trait]
impl CommandExecutor for StopExecutor {
async fn execute<'a>(
&self,
sender: &mut CommandSender<'a>,
_server: &crate::server::Server,
_args: &ConsumedArgs<'a>,
) -> Result<(), InvalidTreeError> {
sender
.send_message(TextComponent::text("Stopping Server").color_named(NamedColor::Red))
.await;
// TODO: Gracefully stop
std::process::exit(0)
}
}
pub fn init_command_tree<'a>() -> CommandTree<'a> {
CommandTree::new(NAMES, DESCRIPTION)
.with_child(require(&|sender| sender.permission_lvl() >= 4).execute(&StopExecutor {}))
}