Skip to content

Commit

Permalink
Fix fmt and clippy
Browse files Browse the repository at this point in the history
  • Loading branch information
vyPal committed Dec 26, 2024
1 parent 87f23ec commit 5354835
Show file tree
Hide file tree
Showing 6 changed files with 23 additions and 69 deletions.
27 changes: 14 additions & 13 deletions plugins/hello-plugin-source/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,18 +1,17 @@
use async_trait::async_trait;
use pumpkin::command::args::ConsumedArgs;
use pumpkin::command::dispatcher::CommandError;
use pumpkin::command::tree::CommandTree;
use pumpkin::command::CommandExecutor;
use pumpkin::command::CommandSender;
use pumpkin::plugin::api::types::player::PlayerEvent;
use pumpkin::plugin::*;
use pumpkin::server::Server;
use pumpkin_api_macros::{plugin_event, plugin_impl, plugin_method};
use pumpkin_core::text::color::NamedColor;
use pumpkin_core::text::TextComponent;
use serde::{Deserialize, Serialize};
use std::fs;
use pumpkin::command::tree::CommandTree;
use pumpkin::command::dispatcher::CommandError;
use pumpkin::command::args::ConsumedArgs;
use pumpkin::server::Server;
use pumpkin::command::CommandSender;
use pumpkin::command::CommandExecutor;
use async_trait::async_trait;
use pumpkin_protocol::client::play::CSystemChatMessage;

#[derive(Serialize, Deserialize, Debug)]
struct Config {
Expand Down Expand Up @@ -80,11 +79,7 @@ async fn on_unload(&mut self, server: &Context) -> Result<(), String> {
}

#[plugin_event(blocking = true, priority = Highest)]
async fn on_player_join(
&mut self,
server: &Context,
player: &PlayerEvent,
) -> Result<bool, String> {
async fn on_player_join(&mut self, server: &Context, player: &PlayerEvent) -> Result<bool, String> {
server.get_logger().info(
format!(
"Player {} joined the game. Config is {:#?}",
Expand Down Expand Up @@ -138,3 +133,9 @@ impl MyPlugin {
}
}
}

impl Default for MyPlugin {
fn default() -> Self {
Self::new()
}
}
3 changes: 3 additions & 0 deletions pumpkin/src/command/tree_builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ use super::CommandExecutor;

impl<'a> CommandTree<'a> {
/// Add a child [Node] to the root of this [`CommandTree`].
#[must_use]
pub fn with_child(mut self, child: impl NodeBuilder<'a>) -> Self {
let node = child.build(&mut self);
self.children.push(self.nodes.len());
Expand All @@ -15,6 +16,7 @@ impl<'a> CommandTree<'a> {
}

/// provide at least one name
#[must_use]
pub fn new<const NAME_COUNT: usize>(
names: [&'a str; NAME_COUNT],
description: &'a str,
Expand Down Expand Up @@ -42,6 +44,7 @@ impl<'a> CommandTree<'a> {
/// desired type.
///
/// Also see [`NonLeafNodeBuilder::execute`].
#[must_use]
pub fn execute(mut self, executor: &'a dyn CommandExecutor) -> Self {
let node = Node {
node_type: NodeType::ExecuteLeaf { executor },
Expand Down
2 changes: 1 addition & 1 deletion pumpkin/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -240,7 +240,7 @@ async fn main() {

let client_clone = client.clone();
tokio::spawn(async move {
while let Some(_) = rx.recv().await {
while (rx.recv().await).is_some() {
let mut enc = client_clone.enc.lock().await;
let buf = enc.take();
if let Err(e) = connection_writer.lock().await.write_all(&buf).await {
Expand Down
50 changes: 0 additions & 50 deletions pumpkin/src/net/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -501,56 +501,6 @@ impl Client {
Ok(())
}

/// Reads the connection until our buffer of len 4096 is full, then decode
/// Close connection when an error occurs or when the Client closed the connection
/// Returns if connection is still open
/* pub async fn poll(&self) -> bool {
loop {
if self.closed.load(std::sync::atomic::Ordering::Relaxed) {
// If we manually close (like a kick) we dont want to keep reading bytes
return false;
}
let mut dec = self.dec.lock().await;
match dec.decode() {
Ok(Some(packet)) => {
self.add_packet(packet).await;
return true;
}
Ok(None) => (), //log::debug!("Waiting for more data to complete packet..."),
Err(err) => {
log::warn!("Failed to decode packet for: {}", err.to_string());
self.close();
return false; // return to avoid reserving additional bytes
}
}
dec.reserve(4096);
let mut buf = dec.take_capacity();
let bytes_read = self.connection_reader.lock().await.read_buf(&mut buf).await;
match bytes_read {
Ok(cnt) => {
//log::debug!("Read {} bytes", cnt);
if cnt == 0 {
self.close();
return false;
}
}
Err(error) => {
log::error!("Error while reading incoming packet {}", error);
self.close();
return false;
}
};
// This should always be an O(1) unsplit because we reserved space earlier and
// the call to `read_buf` shouldn't have grown the allocation.
dec.queue_bytes(buf);
}
} */

/// Disconnects a client from the server with a specified reason.
///
/// This function kicks a client identified by its ID from the server. The appropriate disconnect packet is sent based on the client's current connection state.
Expand Down
2 changes: 1 addition & 1 deletion pumpkin/src/plugin/api/context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ pub enum ContextAction {

pub fn handle_context(
metadata: PluginMetadata<'static>, /* , dispatcher: Arc<CommandDispatcher<'static>> */
server: Arc<Server>,
server: &Arc<Server>,
) -> Context {
let (send, mut recv) = mpsc::channel(1);
let server = server.clone();
Expand Down
8 changes: 4 additions & 4 deletions pumpkin/src/plugin/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ impl PluginManager {
// The chance that this will panic is non-existent, but just in case
let context = handle_context(
metadata.clone(), /* , dispatcher */
self.server.clone().expect("Server not set"),
&self.server.clone().expect("Server not set"),
);
let mut plugin_box = plugin_fn();
let res = plugin_box.on_load(&context).await;
Expand Down Expand Up @@ -137,7 +137,7 @@ impl PluginManager {

let context = handle_context(
metadata.clone(), /* , dispatcher */
self.server.clone().expect("Server not set"),
&self.server.clone().expect("Server not set"),
);
let res = plugin.on_load(&context).await;
res?;
Expand All @@ -157,7 +157,7 @@ impl PluginManager {
if let Some((metadata, plugin, _, loaded)) = plugin {
let context = handle_context(
metadata.clone(), /* , dispatcher */
self.server.clone().expect("Server not set"),
&self.server.clone().expect("Server not set"),
);
let res = plugin.on_unload(&context).await;
res?;
Expand Down Expand Up @@ -200,7 +200,7 @@ impl PluginManager {
if let Some(matching_event) = registered_events.iter().find(|e| e.name == event_name) {
let context = handle_context(
metadata.clone(), /* , dispatcher.clone() */
self.server.clone().expect("Server not set"),
&self.server.clone().expect("Server not set"),
);

if matching_event.blocking {
Expand Down

0 comments on commit 5354835

Please sign in to comment.