Skip to content

Commit

Permalink
Fix clippy issues
Browse files Browse the repository at this point in the history
  • Loading branch information
vyPal committed Dec 23, 2024
1 parent bb8f0ba commit 6d7ec38
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 22 deletions.
20 changes: 8 additions & 12 deletions pumpkin/src/command/commands/cmd_plugin.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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),
)
Expand All @@ -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),
)
Expand Down Expand Up @@ -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;
Expand All @@ -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),
)
Expand All @@ -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),
)
Expand Down
2 changes: 1 addition & 1 deletion pumpkin/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
15 changes: 6 additions & 9 deletions pumpkin/src/plugin/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand All @@ -131,21 +132,19 @@ 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(
metadata.clone(), /* , dispatcher */
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"))
}
}

Expand All @@ -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"))
}
}

Expand Down

0 comments on commit 6d7ec38

Please sign in to comment.