feat(command): updating say commands to use the new node format (#2996)

* updating say commands to the new node format

* fix clippy
This commit is contained in:
kedor
2026-08-20 08:42:39 +02:00
committed by GitHub
parent c3e73c9f11
commit cb1f22f7e3
2 changed files with 26 additions and 39 deletions

View File

@@ -131,7 +131,6 @@ pub fn default_dispatcher(
dispatcher.register(rotate::init_command_tree(), "minecraft:command.rotate");
dispatcher.register(damage::init_command_tree(), "minecraft:command.damage");
dispatcher.register(bossbar::init_command_tree(), "minecraft:command.bossbar");
dispatcher.register(say::init_command_tree(), "minecraft:command.say");
dispatcher.register(gamemode::init_command_tree(), "minecraft:command.gamemode");
dispatcher.register(gamerule::init_command_tree(), "minecraft:command.gamerule");
dispatcher.register(
@@ -174,6 +173,7 @@ pub fn default_dispatcher(
wrapper_dispatcher
};
say::register(&mut dispatcher, registry);
banlist::register(&mut dispatcher, registry);
difficulty::register(&mut dispatcher, registry);
dialog::register(&mut dispatcher, registry);
@@ -506,13 +506,6 @@ fn register_level_2_permissions(registry: &PermissionRegistry) {
PermissionDefault::Op(PermissionLvl::Two),
))
.unwrap_or_else(|e| tracing::warn!("{e}"));
registry
.register_permission(Permission::new(
"minecraft:command.say",
"Broadcasts a message to multiple players",
PermissionDefault::Op(PermissionLvl::Two),
))
.unwrap_or_else(|e| tracing::warn!("{e}"));
registry
.register_permission(Permission::new(
"minecraft:command.gamemode",

View File

@@ -1,46 +1,32 @@
use pumpkin_data::world::SAY_COMMAND;
use pumpkin_util::text::TextComponent;
use crate::command::{
CommandError, CommandExecutor, CommandResult, CommandSender,
args::{Arg, ConsumedArgs, message::MsgArgConsumer},
tree::{CommandTree, builder::argument},
};
use CommandError::InvalidConsumption;
use crate::command::argument_builder::{ArgumentBuilder, argument, command};
use crate::command::argument_types::core::string::StringArgumentType;
use crate::command::context::command_context::CommandContext;
use crate::command::node::dispatcher::CommandDispatcher;
use crate::command::node::{CommandExecutor, CommandExecutorResult};
use pumpkin_util::PermissionLvl;
use pumpkin_util::permission::{Permission, PermissionDefault, PermissionRegistry};
const NAMES: [&str; 1] = ["say"];
const NAME: &str = "say";
const DESCRIPTION: &str = "Broadcast a message to all Players.";
const PERMISSION: &str = "minecraft:command.say";
const ARG_MESSAGE: &str = "message";
struct Executor;
impl CommandExecutor for Executor {
fn execute<'a>(
&'a self,
sender: &'a CommandSender,
server: &'a crate::server::Server,
args: &'a ConsumedArgs<'a>,
) -> CommandResult<'a> {
fn execute<'a>(&'a self, context: &'a CommandContext) -> CommandExecutorResult<'a> {
Box::pin(async move {
let Some(Arg::Msg(msg)) = args.get(ARG_MESSAGE) else {
return Err(InvalidConsumption(Some(ARG_MESSAGE.into())));
};
let msg = context.get_argument::<String>(ARG_MESSAGE)?;
let Some(server_arc) = sender
.world_or_first(server)
.and_then(|w| w.server.upgrade())
else {
return Err(CommandError::CommandFailed(TextComponent::text(
"Failed to get server instance",
)));
};
server_arc
context
.server()
.broadcast_message(
&TextComponent::text(msg.clone()),
&TextComponent::text(format!("{sender}")),
&context.source.display_name,
SAY_COMMAND,
None,
)
@@ -51,7 +37,15 @@ impl CommandExecutor for Executor {
}
}
pub fn init_command_tree() -> CommandTree {
CommandTree::new(NAMES, DESCRIPTION)
.then(argument(ARG_MESSAGE, MsgArgConsumer).execute(Executor))
pub fn register(dispatcher: &mut CommandDispatcher, registry: &PermissionRegistry) {
registry.register_permission_or_panic(Permission::new(
PERMISSION,
DESCRIPTION,
PermissionDefault::Op(PermissionLvl::Two),
));
dispatcher.register(
command(NAME, DESCRIPTION)
.requires(PERMISSION)
.then(argument(ARG_MESSAGE, StringArgumentType::GreedyPhrase).executes(Executor)),
);
}