Skip to content

Commit

Permalink
Format and remove unnecessary files
Browse files Browse the repository at this point in the history
  • Loading branch information
Jakob committed Feb 18, 2025
1 parent c85eb39 commit fd96175
Show file tree
Hide file tree
Showing 7 changed files with 38 additions and 54 deletions.
2 changes: 0 additions & 2 deletions plugins/pumpkin_perms/config.toml

This file was deleted.

14 changes: 0 additions & 14 deletions plugins/pumpkin_perms/permissions.json

This file was deleted.

25 changes: 9 additions & 16 deletions pumpkin-util/src/atomic_linked_list.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@

use core::sync::atomic::{AtomicPtr, Ordering};
// use core::marker::PhantomData;


struct Node<T> {
data: T,
next: AtomicPtr<Node<T>>,
Expand Down Expand Up @@ -84,27 +82,29 @@ impl<T: PartialEq> AtomicLinkedList<T> {
false // Exceeded maximum attempts
}


/// add a new element to the front of the list, but will abort
/// if it fails to do so atomically after the given number of attempts.
pub fn push_front_timeout(&self, data: T, max_attempts: u64) -> Result<(), T> {

let max_attempts = core::cmp::max(max_attempts, 1); // ensure we try at least once

let node_ptr = Box::into_raw(Box::new(Node::new(data)));

// start the first attempt by obtaining the current head pointer
let mut orig_head_ptr = self.head.load(Ordering::Acquire);
for _attempt in 0..max_attempts {

// the new "node" will become the new head, so set the node's `next` pointer to `orig_head_ptr`
// SAFE: we know the node_ptr is valid since we just created it above.
unsafe {
(*node_ptr).next = AtomicPtr::new(orig_head_ptr);
}

// now try to atomically swap the new `node_ptr` into the current `head` ptr
match self.head.compare_exchange_weak(orig_head_ptr, node_ptr, Ordering::AcqRel, Ordering::Acquire) {
match self.head.compare_exchange_weak(
orig_head_ptr,
node_ptr,
Ordering::AcqRel,
Ordering::Acquire,
) {
// If compare_exchange succeeds, then the `head` ptr was properly updated, i.e.,
// no other thread was interleaved and snuck in to change `head` since we last loaded it.
Ok(_old_head_ptr) => return Ok(()),
Expand All @@ -120,19 +120,16 @@ impl<T: PartialEq> AtomicLinkedList<T> {
// Here, we exceeded the number of max attempts, so we failed.
// Reclaim the Boxed `Node`, drop the Box, and return the inner data of type `T`.
// SAFE: no one has touched this node except for us when we created it above.
let reclaimed_node = unsafe {
Box::from_raw(node_ptr)
};
let reclaimed_node = unsafe { Box::from_raw(node_ptr) };

Err(reclaimed_node.data)
}


/// returns a forward iterator through this linked list.
pub fn iter(&self) -> AtomicLinkedListIter<T> {
AtomicLinkedListIter {
curr: &self.head, //load(Ordering::Acquire),
// _phantom: PhantomData,
// _phantom: PhantomData,
}
}

Expand All @@ -141,12 +138,11 @@ impl<T: PartialEq> AtomicLinkedList<T> {
pub fn iter_mut(&self) -> AtomicLinkedListIterMut<T> {
AtomicLinkedListIterMut {
curr: &self.head, //load(Ordering::Acquire),
// _phantom: PhantomData,
// _phantom: PhantomData,
}
}
}


pub struct AtomicLinkedListIter<'a, T: 'a> {
curr: &'a AtomicPtr<Node<T>>,
// _phantom: PhantomData<&'a T>, // we don't need this with the &'a above
Expand All @@ -166,8 +162,6 @@ impl<'a, T: 'a> Iterator for AtomicLinkedListIter<'a, T> {
}
}



pub struct AtomicLinkedListIterMut<'a, T: 'a> {
curr: &'a AtomicPtr<Node<T>>,
// _phantom: PhantomData<&'a T>, // we don't need this with the &'a above
Expand All @@ -186,4 +180,3 @@ impl<'a, T: 'a> Iterator for AtomicLinkedListIterMut<'a, T> {
Some(&mut curr_node.data)
}
}

2 changes: 1 addition & 1 deletion pumpkin-util/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
pub mod atomic_linked_list;
pub mod gamemode;
pub mod math;
pub mod permission;
pub mod random;
pub mod text;
pub mod translation;
pub mod atomic_linked_list;

pub use gamemode::GameMode;
pub use permission::PermissionLvl;
Expand Down
11 changes: 7 additions & 4 deletions pumpkin/src/command/client_suggestions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,13 +27,16 @@ pub async fn send_c_commands_packet(player: &Arc<Player>, dispatcher: &RwLock<Co
};
match permission.as_str() {
"" => {
if cmd_src.has_permission_lvl(*permission_lvl) {} else {
continue
if cmd_src.has_permission_lvl(*permission_lvl) {
} else {
continue;
}
}
_ => {
if cmd_src.has_permission(permission) || cmd_src.has_permission_lvl(*permission_lvl) {} else {
continue
if cmd_src.has_permission(permission) || cmd_src.has_permission_lvl(*permission_lvl)
{
} else {
continue;
}
}
}
Expand Down
6 changes: 5 additions & 1 deletion pumpkin/src/command/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,11 @@ impl CommandSender<'_> {
match self {
CommandSender::Console | CommandSender::Rcon(_) => true,
CommandSender::Player(p) => {
let permissions = p.get_permissions().iter().map(std::string::String::as_str).collect::<Vec<_>>();
let permissions = p
.get_permissions()
.iter()
.map(std::string::String::as_str)
.collect::<Vec<_>>();
permissions.contains(&permission)
}
}
Expand Down
32 changes: 16 additions & 16 deletions pumpkin/src/entity/player.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,21 @@ use std::{
time::{Duration, Instant},
};

use super::{
combat::{self, player_attack_sound, AttackType},
hunger::HungerManager,
item::ItemEntity,
Entity, EntityBase, EntityId, NBTStorage,
};
use crate::{
block,
command::{client_suggestions, dispatcher::CommandDispatcher},
data::op_data::OPERATOR_CONFIG,
net::{Client, PlayerConfig},
server::Server,
world::World,
};
use crate::{error::PumpkinError, net::GameProfile};
use async_trait::async_trait;
use crossbeam::atomic::AtomicCell;
use pumpkin_config::{ADVANCED_CONFIG, BASIC_CONFIG};
Expand Down Expand Up @@ -48,6 +63,7 @@ use pumpkin_protocol::{
client::play::Metadata,
server::play::{SClickContainer, SKeepAlive},
};
use pumpkin_util::atomic_linked_list::AtomicLinkedList;
use pumpkin_util::{
math::{
boundingbox::{BoundingBox, EntityDimensions},
Expand All @@ -62,22 +78,6 @@ use pumpkin_util::{
};
use pumpkin_world::{cylindrical_chunk_iterator::Cylindrical, item::ItemStack};
use tokio::sync::{Mutex, Notify, RwLock};
use pumpkin_util::atomic_linked_list::AtomicLinkedList;
use super::{
combat::{self, player_attack_sound, AttackType},
hunger::HungerManager,
item::ItemEntity,
Entity, EntityBase, EntityId, NBTStorage,
};
use crate::{
block,
command::{client_suggestions, dispatcher::CommandDispatcher},
data::op_data::OPERATOR_CONFIG,
net::{Client, PlayerConfig},
server::Server,
world::World,
};
use crate::{error::PumpkinError, net::GameProfile};

use super::living::LivingEntity;

Expand Down

0 comments on commit fd96175

Please sign in to comment.