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 option to disable commands #305

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
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
48 changes: 47 additions & 1 deletion pumpkin-config/src/commands.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,60 @@ pub struct CommandsConfig {
/// Are commands from the Console accepted ?
pub use_console: bool,
/// Should be commands from players be logged in console?
pub log_console: bool, // TODO: commands...
pub log_console: bool,
pub enabled: EnabledCommands,
}

impl Default for CommandsConfig {
fn default() -> Self {
Self {
use_console: true,
log_console: true,
enabled: EnabledCommands::default(),
}
}
}

#[derive(Deserialize, Serialize)]
#[serde(default)]
pub struct EnabledCommands {
pub pumpkin: bool,
pub say: bool,
pub gamemode: bool,
pub stop: bool,
pub help: bool,
pub echest: bool,
pub craft: bool,
pub kill: bool,
pub kick: bool,
pub worldborder: bool,
pub teleport: bool,
pub give: bool,
pub list: bool,
pub clear: bool,
pub setblock: bool,
pub transfer: bool,
}

impl Default for EnabledCommands {
fn default() -> Self {
Self {
pumpkin: true,
say: true,
gamemode: true,
stop: true,
help: true,
echest: true,
craft: true,
kill: true,
kick: true,
worldborder: true,
teleport: true,
give: true,
list: true,
clear: true,
setblock: true,
transfer: true,
}
}
}
67 changes: 51 additions & 16 deletions pumpkin/src/command/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ use commands::{
cmd_list, cmd_pumpkin, cmd_say, cmd_setblock, cmd_stop, cmd_teleport, cmd_worldborder,
};
use dispatcher::CommandError;
use pumpkin_config::ADVANCED_CONFIG;
use pumpkin_core::math::vector3::Vector3;
use pumpkin_core::text::TextComponent;

Expand Down Expand Up @@ -107,23 +108,57 @@ impl<'a> CommandSender<'a> {
#[must_use]
pub fn default_dispatcher<'a>() -> Arc<CommandDispatcher<'a>> {
let mut dispatcher = CommandDispatcher::default();
let enabled = &ADVANCED_CONFIG.commands.enabled;

dispatcher.register(cmd_pumpkin::init_command_tree());
dispatcher.register(cmd_say::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.register(cmd_echest::init_command_tree());
dispatcher.register(cmd_craft::init_command_tree());
dispatcher.register(cmd_kill::init_command_tree());
dispatcher.register(cmd_kick::init_command_tree());
dispatcher.register(cmd_worldborder::init_command_tree());
dispatcher.register(cmd_teleport::init_command_tree());
dispatcher.register(cmd_give::init_command_tree());
dispatcher.register(cmd_list::init_command_tree());
dispatcher.register(cmd_clear::init_command_tree());
dispatcher.register(cmd_setblock::init_command_tree());
dispatcher.register(cmd_transfer::init_command_tree());
// TODO: Use an macro or fn for this
if enabled.pumpkin {
dispatcher.register(cmd_pumpkin::init_command_tree());
}
if enabled.say {
dispatcher.register(cmd_say::init_command_tree());
}
if enabled.gamemode {
dispatcher.register(cmd_gamemode::init_command_tree());
}
if enabled.stop {
dispatcher.register(cmd_stop::init_command_tree());
}
if enabled.help {
dispatcher.register(cmd_help::init_command_tree());
}
if enabled.echest {
dispatcher.register(cmd_echest::init_command_tree());
}
if enabled.craft {
dispatcher.register(cmd_craft::init_command_tree());
}
if enabled.kick {
dispatcher.register(cmd_kick::init_command_tree());
}
if enabled.kill {
dispatcher.register(cmd_kill::init_command_tree());
}
if enabled.worldborder {
dispatcher.register(cmd_worldborder::init_command_tree());
}
if enabled.teleport {
dispatcher.register(cmd_teleport::init_command_tree());
}
if enabled.give {
dispatcher.register(cmd_give::init_command_tree());
}
if enabled.list {
dispatcher.register(cmd_list::init_command_tree());
}
if enabled.clear {
dispatcher.register(cmd_clear::init_command_tree());
}
if enabled.setblock {
dispatcher.register(cmd_setblock::init_command_tree());
}
if enabled.transfer {
dispatcher.register(cmd_transfer::init_command_tree());
}

Arc::new(dispatcher)
}
Expand Down