diff --git a/pumpkin/src/lib.rs b/pumpkin/src/lib.rs index f3715126..1c00f227 100644 --- a/pumpkin/src/lib.rs +++ b/pumpkin/src/lib.rs @@ -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; diff --git a/pumpkin/src/plugin/api/context.rs b/pumpkin/src/plugin/api/context.rs index 58264bab..66c44f6d 100644 --- a/pumpkin/src/plugin/api/context.rs +++ b/pumpkin/src/plugin/api/context.rs @@ -10,7 +10,10 @@ pub struct Context { } impl Context { pub fn new(metadata: PluginMetadata<'static>, channel: Sender) -> Context { - Context { metadata, _channel: channel } + Context { + metadata, + _channel: channel, + } } pub fn get_logger(&self) -> Logger { @@ -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; } */ @@ -36,7 +39,9 @@ pub enum ContextAction { // TODO: Implement when dispatcher is mutable } -pub fn handle_context(metadata: PluginMetadata<'static>/* , dispatcher: Arc> */) -> Context { +pub fn handle_context( + metadata: PluginMetadata<'static>, /* , dispatcher: Arc> */ +) -> Context { let (send, mut recv) = mpsc::channel(1); tokio::spawn(async move { while let Some(action) = recv.recv().await { diff --git a/pumpkin/src/plugin/api/events.rs b/pumpkin/src/plugin/api/events.rs index a73e7221..e4a845ee 100644 --- a/pumpkin/src/plugin/api/events.rs +++ b/pumpkin/src/plugin/api/events.rs @@ -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 { diff --git a/pumpkin/src/plugin/mod.rs b/pumpkin/src/plugin/mod.rs index 5d743b68..b4786b56 100644 --- a/pumpkin/src/plugin/mod.rs +++ b/pumpkin/src/plugin/mod.rs @@ -14,7 +14,7 @@ type PluginData = ( pub struct PluginManager { plugins: Vec, - command_dispatcher: Option>> + command_dispatcher: Option>>, } impl Default for PluginManager { @@ -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>) { @@ -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; @@ -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 { @@ -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 {