74 lines
2.0 KiB
Rust
74 lines
2.0 KiB
Rust
use pumpkin_core::text::TextComponent;
|
|
|
|
use crate::commands::dispatcher::CommandDispatcher;
|
|
use crate::entity::player::Player;
|
|
mod arg_player;
|
|
mod cmd_gamemode;
|
|
mod cmd_help;
|
|
mod cmd_pumpkin;
|
|
mod cmd_stop;
|
|
pub mod dispatcher;
|
|
mod tree;
|
|
mod tree_builder;
|
|
mod tree_format;
|
|
|
|
pub enum CommandSender<'a> {
|
|
Rcon(&'a mut Vec<String>),
|
|
Console,
|
|
Player(&'a mut Player),
|
|
}
|
|
|
|
impl<'a> CommandSender<'a> {
|
|
pub fn send_message(&mut self, text: TextComponent) {
|
|
match self {
|
|
// TODO: add color and stuff to console
|
|
CommandSender::Console => log::info!("{}", text.to_pretty_console()),
|
|
CommandSender::Player(c) => c.send_system_message(text),
|
|
CommandSender::Rcon(s) => s.push(text.to_pretty_console()),
|
|
}
|
|
}
|
|
|
|
pub fn is_player(&self) -> bool {
|
|
match self {
|
|
CommandSender::Console => false,
|
|
CommandSender::Player(_) => true,
|
|
CommandSender::Rcon(_) => false,
|
|
}
|
|
}
|
|
|
|
pub fn is_console(&self) -> bool {
|
|
match self {
|
|
CommandSender::Console => true,
|
|
CommandSender::Player(_) => false,
|
|
CommandSender::Rcon(_) => true,
|
|
}
|
|
}
|
|
pub fn as_mut_player(&mut self) -> Option<&mut Player> {
|
|
match self {
|
|
CommandSender::Player(player) => Some(player),
|
|
CommandSender::Console => None,
|
|
CommandSender::Rcon(_) => None,
|
|
}
|
|
}
|
|
|
|
/// todo: implement
|
|
pub fn permission_lvl(&self) -> i32 {
|
|
match self {
|
|
CommandSender::Rcon(_) => 4,
|
|
CommandSender::Console => 4,
|
|
CommandSender::Player(_) => 4,
|
|
}
|
|
}
|
|
}
|
|
|
|
pub fn default_dispatcher<'a>() -> CommandDispatcher<'a> {
|
|
let mut dispatcher = CommandDispatcher::default();
|
|
|
|
dispatcher.register(cmd_pumpkin::init_command_tree());
|
|
dispatcher.register(cmd_gamemode::init_command_tree());
|
|
dispatcher.register(cmd_stop::init_command_tree());
|
|
// dispatcher.register(cmd_help::init_command_tree());
|
|
|
|
dispatcher
|
|
}
|