Skip to content

Commit

Permalink
Cargo fmt and clippy fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
vyPal committed Dec 20, 2024
1 parent 64468e1 commit 237c280
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 15 deletions.
1 change: 1 addition & 0 deletions pumpkin/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ use plugin::PluginManager;
use pumpkin_core::text::TextComponent;
use tokio::sync::Mutex;

pub mod block;
pub mod client;
pub mod command;
pub mod entity;
Expand Down
11 changes: 8 additions & 3 deletions pumpkin/src/plugin/api/context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,10 @@ pub struct Context {
}
impl Context {
pub fn new(metadata: PluginMetadata<'static>, channel: Sender<ContextAction>) -> Context {
Context { metadata, _channel: channel }
Context {
metadata,
_channel: channel,
}
}

pub fn get_logger(&self) -> Logger {
Expand All @@ -26,7 +29,7 @@ impl Context {
}
path
}
/* TODO: Implement when dispatcher is mutable
/* TODO: Implement when dispatcher is mutable
pub async fn register_command(&self, tree: crate::command::tree::CommandTree<'static>) {
self.channel.send(ContextAction::RegisterCommand(tree)).await;
} */
Expand All @@ -36,7 +39,9 @@ pub enum ContextAction {
// TODO: Implement when dispatcher is mutable
}

pub fn handle_context(metadata: PluginMetadata<'static>/* , dispatcher: Arc<CommandDispatcher<'static>> */) -> Context {
pub fn handle_context(
metadata: PluginMetadata<'static>, /* , dispatcher: Arc<CommandDispatcher<'static>> */
) -> Context {
let (send, mut recv) = mpsc::channel(1);
tokio::spawn(async move {
while let Some(action) = recv.recv().await {
Expand Down
2 changes: 1 addition & 1 deletion pumpkin/src/plugin/api/events.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use async_trait::async_trait;

use super::types::player::PlayerEvent;
use super::context::Context;
use super::types::player::PlayerEvent;

#[derive(Eq, PartialEq, Ord, PartialOrd)]
pub enum EventPriority {
Expand Down
22 changes: 11 additions & 11 deletions pumpkin/src/plugin/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ type PluginData = (

pub struct PluginManager {
plugins: Vec<PluginData>,
command_dispatcher: Option<Arc<CommandDispatcher<'static>>>
command_dispatcher: Option<Arc<CommandDispatcher<'static>>>,
}

impl Default for PluginManager {
Expand All @@ -26,7 +26,10 @@ impl Default for PluginManager {
impl PluginManager {
#[must_use]
pub fn new() -> Self {
PluginManager { plugins: vec![], command_dispatcher: None }
PluginManager {
plugins: vec![],
command_dispatcher: None,
}
}

pub fn set_command_dispatcher(&mut self, dispatcher: Arc<CommandDispatcher<'static>>) {
Expand Down Expand Up @@ -56,7 +59,7 @@ impl PluginManager {
unsafe { &**library.get::<*const PluginMetadata>(b"METADATA").unwrap() };

// let dispatcher = self.command_dispatcher.clone().expect("Command dispatcher not set").clone();
let context = handle_context(metadata.clone()/* , dispatcher */);
let context = handle_context(metadata.clone() /* , dispatcher */);
let mut plugin_box = plugin_fn();
let res = plugin_box.on_load(&context);
let mut loaded = true;
Expand All @@ -82,8 +85,8 @@ impl PluginManager {
let mut non_blocking_hooks = Vec::new();

/* let dispatcher = self.command_dispatcher
.clone()
.expect("Command dispatcher not set"); // This should not happen */
.clone()
.expect("Command dispatcher not set"); // This should not happen */

for (metadata, hooks, _, loaded) in &mut self.plugins {
if !*loaded {
Expand All @@ -98,12 +101,9 @@ impl PluginManager {
}
};

if let Some(matching_event) = registered_events
.iter()
.find(|e| e.name == event_name)
{
let context = handle_context(metadata.clone()/* , dispatcher.clone() */);

if let Some(matching_event) = registered_events.iter().find(|e| e.name == event_name) {
let context = handle_context(metadata.clone() /* , dispatcher.clone() */);

if matching_event.blocking {
blocking_hooks.push((context, hooks));
} else {
Expand Down

0 comments on commit 237c280

Please sign in to comment.