From a03f554212b3c8329820b75cf73d9d51494758d0 Mon Sep 17 00:00:00 2001 From: Alexander Medvedev Date: Fri, 27 Dec 2024 17:16:53 +0100 Subject: [PATCH] fix: conflicts --- pumpkin/src/command/commands/cmd_kick.rs | 4 +-- pumpkin/src/command/commands/cmd_op.rs | 6 ++--- pumpkin/src/command/mod.rs | 4 +-- pumpkin/src/data/mod.rs | 2 +- pumpkin/src/entity/player.rs | 33 ++++++++---------------- 5 files changed, 19 insertions(+), 30 deletions(-) diff --git a/pumpkin/src/command/commands/cmd_kick.rs b/pumpkin/src/command/commands/cmd_kick.rs index feded74a..51832258 100644 --- a/pumpkin/src/command/commands/cmd_kick.rs +++ b/pumpkin/src/command/commands/cmd_kick.rs @@ -50,7 +50,7 @@ impl CommandExecutor for KickExecutor { } // TODO: Permission -pub fn init_command_tree<'a>() -> CommandTree<'a> { +pub fn init_command_tree() -> CommandTree { CommandTree::new(NAMES, DESCRIPTION) - .with_child(argument(ARG_TARGET, &PlayersArgumentConsumer).execute(&KickExecutor)) + .with_child(argument(ARG_TARGET, PlayersArgumentConsumer).execute(KickExecutor)) } diff --git a/pumpkin/src/command/commands/cmd_op.rs b/pumpkin/src/command/commands/cmd_op.rs index a98ce5b3..614ffcc7 100644 --- a/pumpkin/src/command/commands/cmd_op.rs +++ b/pumpkin/src/command/commands/cmd_op.rs @@ -72,9 +72,9 @@ impl CommandExecutor for OpExecutor { } } -pub fn init_command_tree<'a>() -> CommandTree<'a> { +pub fn init_command_tree() -> CommandTree { CommandTree::new(NAMES, DESCRIPTION).with_child( - require(&|sender| sender.has_permission_lvl(PermissionLvl::Three)) - .with_child(argument(ARG_TARGET, &PlayersArgumentConsumer).execute(&OpExecutor)), + require(|sender| sender.has_permission_lvl(PermissionLvl::Three)) + .with_child(argument(ARG_TARGET, PlayersArgumentConsumer).execute(OpExecutor)), ) } diff --git a/pumpkin/src/command/mod.rs b/pumpkin/src/command/mod.rs index 2633d4fb..c05017ed 100644 --- a/pumpkin/src/command/mod.rs +++ b/pumpkin/src/command/mod.rs @@ -78,7 +78,7 @@ impl<'a> CommandSender<'a> { pub fn permission_lvl(&self) -> PermissionLvl { match self { CommandSender::Console | CommandSender::Rcon(_) => PermissionLvl::Four, - CommandSender::Player(p) => p.permission_lvl(), + CommandSender::Player(p) => p.permission_lvl.load(), } } @@ -86,7 +86,7 @@ impl<'a> CommandSender<'a> { pub fn has_permission_lvl(&self, lvl: PermissionLvl) -> bool { match self { CommandSender::Console | CommandSender::Rcon(_) => true, - CommandSender::Player(p) => (p.permission_lvl() as i8) >= (lvl as i8), + CommandSender::Player(p) => p.permission_lvl.load().ge(&lvl), } } diff --git a/pumpkin/src/data/mod.rs b/pumpkin/src/data/mod.rs index 1bc17afe..7faf2d16 100644 --- a/pumpkin/src/data/mod.rs +++ b/pumpkin/src/data/mod.rs @@ -33,7 +33,7 @@ pub trait LoadJSONConfiguration { let content = Self::default(); if let Err(err) = fs::write(&path, serde_json::to_string_pretty(&content).unwrap()) { - eprintln!( + log::error!( "Couldn't write default data config to {path:?}. Reason: {err}. This is probably caused by a config update. Just delete the old data config and restart.", ); } diff --git a/pumpkin/src/entity/player.rs b/pumpkin/src/entity/player.rs index a87fe791..eae83b3e 100644 --- a/pumpkin/src/entity/player.rs +++ b/pumpkin/src/entity/player.rs @@ -55,20 +55,20 @@ use pumpkin_world::{ ItemStack, }, }; -use tokio::sync::{Mutex, Notify}; +use tokio::sync::{Mutex, Notify, RwLock}; use super::Entity; -use crate::{error::PumpkinError, net::GameProfile}; use crate::{ + command::{client_cmd_suggestions, dispatcher::CommandDispatcher}, + data::op_data::OPERATOR_CONFIG, net::{ combat::{self, player_attack_sound, AttackType}, Client, PlayerConfig, }, - command::{client_cmd_suggestions, dispatcher::CommandDispatcher}, - data::op_data::OPERATOR_CONFIG, server::Server, world::World, }; +use crate::{error::PumpkinError, net::GameProfile}; use super::living::LivingEntity; @@ -119,12 +119,10 @@ pub struct Player { pub last_keep_alive_time: AtomicCell, /// Amount of ticks since last attack pub last_attacked_ticks: AtomicU32, - + /// The players op permission level + pub permission_lvl: AtomicCell, /// Tell tasks to stop if we are closing cancel_tasks: Notify, - - /// the players op permission level - permission_lvl: parking_lot::Mutex, } impl Player { @@ -199,8 +197,8 @@ impl Player { .ops .iter() .find(|op| op.uuid == gameprofile_clone.id) - .map_or(parking_lot::Mutex::new(PermissionLvl::Zero), |op| { - parking_lot::Mutex::new(op.level) + .map_or(AtomicCell::new(PermissionLvl::Zero), |op| { + AtomicCell::new(op.level) }), } } @@ -445,7 +443,7 @@ impl Player { self.client .send_packet(&CEntityStatus::new( self.entity_id(), - 24 + self.permission_lvl() as i8, + 24 + self.permission_lvl.load() as i8, )) .await; } @@ -454,22 +452,13 @@ impl Player { pub async fn set_permission_lvl( self: &Arc, lvl: PermissionLvl, - command_dispatcher: &Arc>, + command_dispatcher: &RwLock, ) { - { - let mut level = self.permission_lvl.lock(); - *level = lvl; - } - + self.permission_lvl.store(lvl); self.send_permission_lvl_update().await; client_cmd_suggestions::send_c_commands_packet(self, command_dispatcher).await; } - /// get the players permission level - pub fn permission_lvl(&self) -> PermissionLvl { - *self.permission_lvl.lock() - } - /// Sends the world time to just the player. pub async fn send_time(&self, world: &World) { let l_world = world.level_time.lock().await;