Files
Pumpkin/pumpkin/src/command/commands/cmd_say.rs
Kyle Davis 6a5add8de5 Added native operator permission management (#348)
* Starting work on Operator permission system

This commit adds the ops.json configuration found in vanilla
servers, and updates the basic configuration to handle the default
permission level.

Server now uses ops file and defaults players to op level 0

The /op command has been added but needs players to rejoin for now.

* Clippy Fix + need to Rejoin after /op removed

I found the source of the DeadLock. Updated set permission function.

Fix cargo formatting issues and clippy issues.

* Remove temp warn message

* Move OperatorConfig to server

As Snowiii pointed out, OperatorConfig is runtime data.

Revert most changes in pumpkin-config.

op_permission_level must say in the basic configuration for
parity with Minecraft.

* cargo fmt + cargo clippy

* Sync permission change with client

* Fixs issues @Commandcracker found in review

- Move PermissionLvl to core and removed OpLevel
- Move ops.json to /data/ops.json
- Fix permissions issue with /op command
- Shorten /op command description

* refactor into `data` folder

* create data dir when needed

* add to readme

* fix: conflicts

---------

Co-authored-by: Alexander Medvedev <lilalexmed@proton.me>
2024-12-27 17:22:19 +01:00

50 lines
1.4 KiB
Rust

use async_trait::async_trait;
use pumpkin_core::text::TextComponent;
use pumpkin_protocol::client::play::CSystemChatMessage;
use crate::command::{
args::{arg_message::MsgArgConsumer, Arg, ConsumedArgs},
tree::CommandTree,
tree_builder::{argument, require},
CommandError, CommandExecutor, CommandSender,
};
use pumpkin_core::permission::PermissionLvl;
use CommandError::InvalidConsumption;
const NAMES: [&str; 1] = ["say"];
const DESCRIPTION: &str = "Broadcast a message to all Players.";
const ARG_MESSAGE: &str = "message";
struct SayExecutor;
#[async_trait]
impl CommandExecutor for SayExecutor {
async fn execute<'a>(
&self,
sender: &mut CommandSender<'a>,
server: &crate::server::Server,
args: &ConsumedArgs<'a>,
) -> Result<(), CommandError> {
let Some(Arg::Msg(msg)) = args.get(ARG_MESSAGE) else {
return Err(InvalidConsumption(Some(ARG_MESSAGE.into())));
};
server
.broadcast_packet_all(&CSystemChatMessage::new(
&TextComponent::text(&format!("[{sender}] {msg}")),
false,
))
.await;
Ok(())
}
}
pub fn init_command_tree() -> CommandTree {
CommandTree::new(NAMES, DESCRIPTION).with_child(
require(|sender| sender.has_permission_lvl(PermissionLvl::Two))
.with_child(argument(ARG_MESSAGE, MsgArgConsumer).execute(SayExecutor)),
)
}