From 3d0e42315e394d477549b304f61c4d8a0b2f2440 Mon Sep 17 00:00:00 2001 From: Snowiiii Date: Fri, 25 Oct 2024 11:58:36 +0200 Subject: [PATCH] Fix: Commands Known Problems: Target selection currently does not work --- pumpkin/src/commands/cmd_echest.rs | 4 ++-- pumpkin/src/commands/cmd_gamemode.rs | 6 +++--- pumpkin/src/commands/cmd_help.rs | 6 +++--- pumpkin/src/commands/cmd_kick.rs | 4 ++-- pumpkin/src/commands/cmd_kill.rs | 4 ++-- pumpkin/src/commands/cmd_pumpkin.rs | 4 ++-- pumpkin/src/commands/cmd_stop.rs | 4 ++-- pumpkin/src/commands/mod.rs | 2 +- pumpkin/src/commands/tree.rs | 4 ++-- pumpkin/src/commands/tree_builder.rs | 6 +++--- pumpkin/src/entity/player.rs | 4 ++-- 11 files changed, 24 insertions(+), 24 deletions(-) diff --git a/pumpkin/src/commands/cmd_echest.rs b/pumpkin/src/commands/cmd_echest.rs index cfcb7379a..83824183f 100644 --- a/pumpkin/src/commands/cmd_echest.rs +++ b/pumpkin/src/commands/cmd_echest.rs @@ -3,7 +3,7 @@ use pumpkin_inventory::OpenContainer; use crate::commands::tree::CommandTree; -use super::RunFunctionType; +use super::CommandExecutor; const NAMES: [&str; 2] = ["echest", "enderchest"]; @@ -13,7 +13,7 @@ const DESCRIPTION: &str = struct EchestExecutor {} #[async_trait] -impl RunFunctionType for EchestExecutor { +impl CommandExecutor for EchestExecutor { async fn execute( &self, sender: &mut super::CommandSender, diff --git a/pumpkin/src/commands/cmd_gamemode.rs b/pumpkin/src/commands/cmd_gamemode.rs index 042dd2779..f8b10b7f8 100644 --- a/pumpkin/src/commands/cmd_gamemode.rs +++ b/pumpkin/src/commands/cmd_gamemode.rs @@ -18,7 +18,7 @@ use crate::commands::CommandSender; use crate::commands::CommandSender::Player; use crate::server::Server; -use super::RunFunctionType; +use super::CommandExecutor; const NAMES: [&str; 1] = ["gamemode"]; @@ -71,7 +71,7 @@ pub fn parse_arg_gamemode(consumed_args: &ConsumedArgs) -> Result( struct BaseHelpExecutor {} #[async_trait] -impl RunFunctionType for BaseHelpExecutor { +impl CommandExecutor for BaseHelpExecutor { async fn execute( &self, sender: &mut CommandSender, @@ -69,7 +69,7 @@ impl RunFunctionType for BaseHelpExecutor { struct CommandHelpExecutor {} #[async_trait] -impl RunFunctionType for CommandHelpExecutor { +impl CommandExecutor for CommandHelpExecutor { async fn execute( &self, sender: &mut CommandSender, diff --git a/pumpkin/src/commands/cmd_kick.rs b/pumpkin/src/commands/cmd_kick.rs index e4625b8bc..e0ff1ba5f 100644 --- a/pumpkin/src/commands/cmd_kick.rs +++ b/pumpkin/src/commands/cmd_kick.rs @@ -7,7 +7,7 @@ use crate::commands::tree::CommandTree; use crate::commands::tree_builder::argument; use super::arg_player::consume_arg_player; -use super::RunFunctionType; +use super::CommandExecutor; const NAMES: [&str; 1] = ["kick"]; const DESCRIPTION: &str = "Kicks the target player from the server."; @@ -17,7 +17,7 @@ const ARG_TARGET: &str = "target"; struct KickExecutor {} #[async_trait] -impl RunFunctionType for KickExecutor { +impl CommandExecutor for KickExecutor { async fn execute( &self, sender: &mut super::CommandSender, diff --git a/pumpkin/src/commands/cmd_kill.rs b/pumpkin/src/commands/cmd_kill.rs index 9475c6bbb..049328c6a 100644 --- a/pumpkin/src/commands/cmd_kill.rs +++ b/pumpkin/src/commands/cmd_kill.rs @@ -6,7 +6,7 @@ use crate::commands::arg_player::{consume_arg_player, parse_arg_player}; use crate::commands::tree::CommandTree; use crate::commands::tree_builder::argument; -use super::RunFunctionType; +use super::CommandExecutor; const NAMES: [&str; 1] = ["kill"]; const DESCRIPTION: &str = "Kills a target player."; @@ -16,7 +16,7 @@ const ARG_TARGET: &str = "target"; struct KillExecutor {} #[async_trait] -impl RunFunctionType for KillExecutor { +impl CommandExecutor for KillExecutor { async fn execute( &self, sender: &mut super::CommandSender, diff --git a/pumpkin/src/commands/cmd_pumpkin.rs b/pumpkin/src/commands/cmd_pumpkin.rs index c7b3daf17..508fa9575 100644 --- a/pumpkin/src/commands/cmd_pumpkin.rs +++ b/pumpkin/src/commands/cmd_pumpkin.rs @@ -4,7 +4,7 @@ use pumpkin_protocol::CURRENT_MC_PROTOCOL; use crate::{commands::tree::CommandTree, server::CURRENT_MC_VERSION}; -use super::RunFunctionType; +use super::CommandExecutor; const NAMES: [&str; 1] = ["pumpkin"]; @@ -13,7 +13,7 @@ const DESCRIPTION: &str = "Display information about Pumpkin."; struct PumpkinExecutor {} #[async_trait] -impl RunFunctionType for PumpkinExecutor { +impl CommandExecutor for PumpkinExecutor { async fn execute( &self, sender: &mut super::CommandSender, diff --git a/pumpkin/src/commands/cmd_stop.rs b/pumpkin/src/commands/cmd_stop.rs index fcef4bd84..6ae7d4992 100644 --- a/pumpkin/src/commands/cmd_stop.rs +++ b/pumpkin/src/commands/cmd_stop.rs @@ -5,7 +5,7 @@ use pumpkin_core::text::TextComponent; use crate::commands::tree::CommandTree; use crate::commands::tree_builder::require; -use super::RunFunctionType; +use super::CommandExecutor; const NAMES: [&str; 1] = ["stop"]; @@ -14,7 +14,7 @@ const DESCRIPTION: &str = "Stop the server."; struct StopExecutor {} #[async_trait] -impl RunFunctionType for StopExecutor { +impl CommandExecutor for StopExecutor { async fn execute( &self, sender: &mut super::CommandSender, diff --git a/pumpkin/src/commands/mod.rs b/pumpkin/src/commands/mod.rs index 5089d5aad..c9ec0213d 100644 --- a/pumpkin/src/commands/mod.rs +++ b/pumpkin/src/commands/mod.rs @@ -76,7 +76,7 @@ pub fn default_dispatcher<'a>() -> Arc> { } #[async_trait] -pub(crate) trait RunFunctionType: Sync { +pub(crate) trait CommandExecutor: Sync { async fn execute( &self, sender: &mut CommandSender, diff --git a/pumpkin/src/commands/tree.rs b/pumpkin/src/commands/tree.rs index d69b72bec..e9a69ea13 100644 --- a/pumpkin/src/commands/tree.rs +++ b/pumpkin/src/commands/tree.rs @@ -1,4 +1,4 @@ -use super::RunFunctionType; +use super::CommandExecutor; use crate::{commands::CommandSender, server::Server}; use std::collections::{HashMap, VecDeque}; @@ -20,7 +20,7 @@ pub struct Node<'a> { pub enum NodeType<'a> { ExecuteLeaf { - executor: &'a dyn RunFunctionType, + executor: &'a dyn CommandExecutor, }, Literal { string: &'a str, diff --git a/pumpkin/src/commands/tree_builder.rs b/pumpkin/src/commands/tree_builder.rs index b8899d5dc..aa645c1c7 100644 --- a/pumpkin/src/commands/tree_builder.rs +++ b/pumpkin/src/commands/tree_builder.rs @@ -1,7 +1,7 @@ use crate::commands::tree::{ArgumentConsumer, CommandTree, Node, NodeType}; use crate::commands::CommandSender; -use super::RunFunctionType; +use super::CommandExecutor; impl<'a> CommandTree<'a> { /// Add a child [Node] to the root of this [`CommandTree`]. @@ -40,7 +40,7 @@ impl<'a> CommandTree<'a> { /// desired type. /// /// Also see [`NonLeafNodeBuilder::execute`]. - pub fn execute(mut self, executor: &'a dyn RunFunctionType) -> Self { + pub fn execute(mut self, executor: &'a dyn CommandExecutor) -> Self { let node = Node { node_type: NodeType::ExecuteLeaf { executor }, children: Vec::new(), @@ -113,7 +113,7 @@ impl<'a> NonLeafNodeBuilder<'a> { /// desired type. /// /// Also see [`CommandTree::execute`]. - pub fn execute(mut self, executor: &'a dyn RunFunctionType) -> Self { + pub fn execute(mut self, executor: &'a dyn CommandExecutor) -> Self { self.leaf_nodes.push(LeafNodeBuilder { node_type: NodeType::ExecuteLeaf { executor }, }); diff --git a/pumpkin/src/entity/player.rs b/pumpkin/src/entity/player.rs index 09bb81f64..becbc4038 100644 --- a/pumpkin/src/entity/player.rs +++ b/pumpkin/src/entity/player.rs @@ -386,11 +386,11 @@ impl Player { ServerboundPlayPackets::SelectBundleItem => {} ServerboundPlayPackets::SetDifficulty => {} ServerboundPlayPackets::ChatAck => {} - ServerboundPlayPackets::ChatCommandUnsigned => {} - ServerboundPlayPackets::ChatCommand => { + ServerboundPlayPackets::ChatCommandUnsigned => { self.handle_chat_command(server, SChatCommand::read(bytebuf)?) .await; } + ServerboundPlayPackets::ChatCommand => {} ServerboundPlayPackets::ChatMessage => { self.handle_chat_message(SChatMessage::read(bytebuf)?).await; }