From 6d7ec38e8d393c0746b8a9258e71f47bf7ba39ed Mon Sep 17 00:00:00 2001 From: vyPal Date: Mon, 23 Dec 2024 13:19:10 +0100 Subject: [PATCH] Fix clippy issues --- pumpkin/src/command/commands/cmd_plugin.rs | 20 ++++++++------------ pumpkin/src/main.rs | 2 +- pumpkin/src/plugin/mod.rs | 15 ++++++--------- 3 files changed, 15 insertions(+), 22 deletions(-) diff --git a/pumpkin/src/command/commands/cmd_plugin.rs b/pumpkin/src/command/commands/cmd_plugin.rs index 039bed8c..5d779e68 100644 --- a/pumpkin/src/command/commands/cmd_plugin.rs +++ b/pumpkin/src/command/commands/cmd_plugin.rs @@ -88,7 +88,7 @@ impl CommandExecutor for LoadExecutor { if plugin_manager.is_plugin_loaded(plugin_name) { sender .send_message( - TextComponent::text_string(format!("Plugin {} is already loaded", plugin_name)) + TextComponent::text_string(format!("Plugin {plugin_name} is already loaded")) .color_named(NamedColor::Red), ) .await; @@ -98,12 +98,11 @@ impl CommandExecutor for LoadExecutor { let result = plugin_manager.load_plugin(plugin_name).await; match result { - Ok(_) => { + Ok(()) => { sender .send_message( TextComponent::text_string(format!( - "Plugin {} loaded successfully", - plugin_name + "Plugin {plugin_name} loaded successfully" )) .color_named(NamedColor::Green), ) @@ -113,8 +112,7 @@ impl CommandExecutor for LoadExecutor { sender .send_message( TextComponent::text_string(format!( - "Failed to load plugin {}: {}", - plugin_name, e + "Failed to load plugin {plugin_name}: {e}" )) .color_named(NamedColor::Red), ) @@ -144,7 +142,7 @@ impl CommandExecutor for UnloadExecutor { if !plugin_manager.is_plugin_loaded(plugin_name) { sender .send_message( - TextComponent::text_string(format!("Plugin {} is not loaded", plugin_name)) + TextComponent::text_string(format!("Plugin {plugin_name} is not loaded")) .color_named(NamedColor::Red), ) .await; @@ -154,12 +152,11 @@ impl CommandExecutor for UnloadExecutor { let result = plugin_manager.unload_plugin(plugin_name).await; match result { - Ok(_) => { + Ok(()) => { sender .send_message( TextComponent::text_string(format!( - "Plugin {} unloaded successfully", - plugin_name + "Plugin {plugin_name} unloaded successfully", )) .color_named(NamedColor::Green), ) @@ -169,8 +166,7 @@ impl CommandExecutor for UnloadExecutor { sender .send_message( TextComponent::text_string(format!( - "Failed to unload plugin {}: {}", - plugin_name, e + "Failed to unload plugin {plugin_name}: {e}" )) .color_named(NamedColor::Red), ) diff --git a/pumpkin/src/main.rs b/pumpkin/src/main.rs index 59466078..85359508 100644 --- a/pumpkin/src/main.rs +++ b/pumpkin/src/main.rs @@ -183,7 +183,7 @@ async fn main() { let mut loader_lock = PLUGIN_MANAGER.lock().await; loader_lock.set_server(server.clone()); loader_lock.load_plugins().await.unwrap(); - } + }; log::info!("Started Server took {}ms", time.elapsed().as_millis()); log::info!("You now can connect to the server, Listening on {}", addr); diff --git a/pumpkin/src/plugin/mod.rs b/pumpkin/src/plugin/mod.rs index d265ba4c..d301e48c 100644 --- a/pumpkin/src/plugin/mod.rs +++ b/pumpkin/src/plugin/mod.rs @@ -117,6 +117,7 @@ impl PluginManager { .push((metadata.clone(), plugin_box, library, loaded)); } + #[must_use] pub fn is_plugin_loaded(&self, name: &str) -> bool { self.plugins .iter() @@ -131,7 +132,7 @@ impl PluginManager { if let Some((metadata, plugin, _, loaded)) = plugin { if *loaded { - return Err(format!("Plugin {} is already loaded", name)); + return Err(format!("Plugin {name} is already loaded")); } let context = handle_context( @@ -139,13 +140,11 @@ impl PluginManager { self.server.clone().expect("Server not set"), ); let res = plugin.on_load(&context).await; - if let Err(e) = res { - return Err(e); - } + res?; *loaded = true; Ok(()) } else { - Err(format!("Plugin {} not found", name)) + Err(format!("Plugin {name} not found")) } } @@ -161,13 +160,11 @@ impl PluginManager { self.server.clone().expect("Server not set"), ); let res = plugin.on_unload(&context).await; - if let Err(e) = res { - return Err(e); - } + res?; *loaded = false; Ok(()) } else { - Err(format!("Plugin {} not found", name)) + Err(format!("Plugin {name} not found")) } }