mirror of
https://github.com/Pumpkin-MC/Pumpkin.git
synced 2026-08-30 20:14:23 +00:00
feat(pumpkin): add /reload command (#2960)
Adds the vanilla /reload command (permission level 2), which reloads the server's datapacks: it re-reads the enabled packs, re-runs the #minecraft:load function tag and pushes the rebuilt recipes to every player, through the same Server::reload_datapacks path /datapack enable and /datapack disable already use. Feedback follows Vanilla and is sent before the reload starts, so it arrives even though reloading takes a moment. Co-authored-by: Mcxiaocaibug <Mcxiaocaibug@users.noreply.github.com>
This commit is contained in:
@@ -55,6 +55,7 @@ mod plugins;
|
||||
mod pumpkin;
|
||||
mod random;
|
||||
mod recipe;
|
||||
mod reload;
|
||||
mod ride;
|
||||
mod rotate;
|
||||
mod saveall;
|
||||
@@ -187,6 +188,7 @@ pub fn default_dispatcher(
|
||||
forceload::register(&mut dispatcher, registry);
|
||||
ride::register(&mut dispatcher, registry);
|
||||
recipe::register(&mut dispatcher, registry);
|
||||
reload::register(&mut dispatcher, registry);
|
||||
help::register(&mut dispatcher, registry);
|
||||
kill::register(&mut dispatcher, registry);
|
||||
op::register(&mut dispatcher, registry);
|
||||
|
||||
53
crates/pumpkin/src/command/commands/reload.rs
Normal file
53
crates/pumpkin/src/command/commands/reload.rs
Normal file
@@ -0,0 +1,53 @@
|
||||
use pumpkin_data::translation;
|
||||
use pumpkin_util::PermissionLvl;
|
||||
use pumpkin_util::permission::{Permission, PermissionDefault, PermissionRegistry};
|
||||
use pumpkin_util::text::TextComponent;
|
||||
|
||||
use crate::command::argument_builder::{ArgumentBuilder, command};
|
||||
use crate::command::context::command_context::CommandContext;
|
||||
use crate::command::node::dispatcher::CommandDispatcher;
|
||||
use crate::command::node::{CommandExecutor, CommandExecutorResult};
|
||||
|
||||
const DESCRIPTION: &str = "Reloads the server's datapacks.";
|
||||
const PERMISSION: &str = "minecraft:command.reload";
|
||||
|
||||
struct ReloadExecutor;
|
||||
|
||||
impl CommandExecutor for ReloadExecutor {
|
||||
fn execute<'a>(&'a self, context: &'a CommandContext) -> CommandExecutorResult<'a> {
|
||||
Box::pin(async move {
|
||||
// Vanilla announces the reload before doing it, so the feedback
|
||||
// arrives even though reloading takes a moment.
|
||||
context
|
||||
.source
|
||||
.send_feedback(
|
||||
TextComponent::translate_cross(
|
||||
translation::java::COMMANDS_RELOAD_SUCCESS,
|
||||
translation::java::COMMANDS_RELOAD_SUCCESS,
|
||||
[],
|
||||
),
|
||||
true,
|
||||
)
|
||||
.await;
|
||||
|
||||
let server = context.server();
|
||||
server.reload_datapacks(server).await;
|
||||
|
||||
Ok(0)
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
pub fn register(dispatcher: &mut CommandDispatcher, registry: &PermissionRegistry) {
|
||||
registry.register_permission_or_panic(Permission::new(
|
||||
PERMISSION,
|
||||
DESCRIPTION,
|
||||
PermissionDefault::Op(PermissionLvl::Two),
|
||||
));
|
||||
|
||||
dispatcher.register(
|
||||
command("reload", DESCRIPTION)
|
||||
.requires(PERMISSION)
|
||||
.executes(ReloadExecutor),
|
||||
);
|
||||
}
|
||||
Reference in New Issue
Block a user