Skip to content

Commit

Permalink
Fix: Commands
Browse files Browse the repository at this point in the history
Known Problems:
Target selection currently does not work
  • Loading branch information
Snowiiii committed Oct 25, 2024
1 parent 7347bae commit 3d0e423
Show file tree
Hide file tree
Showing 11 changed files with 24 additions and 24 deletions.
4 changes: 2 additions & 2 deletions pumpkin/src/commands/cmd_echest.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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"];

Expand All @@ -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,
Expand Down
6 changes: 3 additions & 3 deletions pumpkin/src/commands/cmd_gamemode.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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"];

Expand Down Expand Up @@ -71,7 +71,7 @@ pub fn parse_arg_gamemode(consumed_args: &ConsumedArgs) -> Result<GameMode, Inva
struct GamemodeTargetSelf {}

#[async_trait]
impl RunFunctionType for GamemodeTargetSelf {
impl CommandExecutor for GamemodeTargetSelf {
async fn execute(
&self,
sender: &mut CommandSender,
Expand Down Expand Up @@ -105,7 +105,7 @@ impl RunFunctionType for GamemodeTargetSelf {
struct GamemodeTargetPlayer {}

#[async_trait]
impl RunFunctionType for GamemodeTargetPlayer {
impl CommandExecutor for GamemodeTargetPlayer {
async fn execute(
&self,
sender: &mut CommandSender,
Expand Down
6 changes: 3 additions & 3 deletions pumpkin/src/commands/cmd_help.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ use crate::commands::tree_builder::argument;
use crate::commands::CommandSender;
use crate::server::Server;

use super::RunFunctionType;
use super::CommandExecutor;

const NAMES: [&str; 3] = ["help", "h", "?"];

Expand Down Expand Up @@ -44,7 +44,7 @@ fn parse_arg_command<'a>(
struct BaseHelpExecutor {}

#[async_trait]
impl RunFunctionType for BaseHelpExecutor {
impl CommandExecutor for BaseHelpExecutor {
async fn execute(
&self,
sender: &mut CommandSender,
Expand All @@ -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,
Expand Down
4 changes: 2 additions & 2 deletions pumpkin/src/commands/cmd_kick.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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.";
Expand All @@ -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,
Expand Down
4 changes: 2 additions & 2 deletions pumpkin/src/commands/cmd_kill.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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.";
Expand All @@ -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,
Expand Down
4 changes: 2 additions & 2 deletions pumpkin/src/commands/cmd_pumpkin.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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"];

Expand All @@ -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,
Expand Down
4 changes: 2 additions & 2 deletions pumpkin/src/commands/cmd_stop.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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"];

Expand All @@ -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,
Expand Down
2 changes: 1 addition & 1 deletion pumpkin/src/commands/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ pub fn default_dispatcher<'a>() -> Arc<CommandDispatcher<'a>> {
}

#[async_trait]
pub(crate) trait RunFunctionType: Sync {
pub(crate) trait CommandExecutor: Sync {
async fn execute(
&self,
sender: &mut CommandSender,
Expand Down
4 changes: 2 additions & 2 deletions pumpkin/src/commands/tree.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use super::RunFunctionType;
use super::CommandExecutor;
use crate::{commands::CommandSender, server::Server};
use std::collections::{HashMap, VecDeque};

Expand All @@ -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,
Expand Down
6 changes: 3 additions & 3 deletions pumpkin/src/commands/tree_builder.rs
Original file line number Diff line number Diff line change
@@ -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`].
Expand Down Expand Up @@ -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(),
Expand Down Expand Up @@ -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 },
});
Expand Down
4 changes: 2 additions & 2 deletions pumpkin/src/entity/player.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down

0 comments on commit 3d0e423

Please sign in to comment.