Skip to content

Commit

Permalink
fix: conflicts
Browse files Browse the repository at this point in the history
  • Loading branch information
Snowiiii committed Dec 27, 2024
1 parent 70801d4 commit a03f554
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 30 deletions.
4 changes: 2 additions & 2 deletions pumpkin/src/command/commands/cmd_kick.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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))
}
6 changes: 3 additions & 3 deletions pumpkin/src/command/commands/cmd_op.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)),
)
}
4 changes: 2 additions & 2 deletions pumpkin/src/command/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -78,15 +78,15 @@ 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(),
}
}

#[must_use]
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),
}
}

Expand Down
2 changes: 1 addition & 1 deletion pumpkin/src/data/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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.",
);
}
Expand Down
33 changes: 11 additions & 22 deletions pumpkin/src/entity/player.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -119,12 +119,10 @@ pub struct Player {
pub last_keep_alive_time: AtomicCell<Instant>,
/// Amount of ticks since last attack
pub last_attacked_ticks: AtomicU32,

/// The players op permission level
pub permission_lvl: AtomicCell<PermissionLvl>,
/// Tell tasks to stop if we are closing
cancel_tasks: Notify,

/// the players op permission level
permission_lvl: parking_lot::Mutex<PermissionLvl>,
}

impl Player {
Expand Down Expand Up @@ -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)
}),
}
}
Expand Down Expand Up @@ -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;
}
Expand All @@ -454,22 +452,13 @@ impl Player {
pub async fn set_permission_lvl(
self: &Arc<Self>,
lvl: PermissionLvl,
command_dispatcher: &Arc<CommandDispatcher<'static>>,
command_dispatcher: &RwLock<CommandDispatcher>,
) {
{
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;
Expand Down

0 comments on commit a03f554

Please sign in to comment.