Skip to content

Commit

Permalink
Split commands into their own Folder
Browse files Browse the repository at this point in the history
Now its much nicer separate from the command base
  • Loading branch information
Snowiiii committed Oct 29, 2024
1 parent 74c4662 commit 9f70b95
Show file tree
Hide file tree
Showing 24 changed files with 105 additions and 108 deletions.
6 changes: 3 additions & 3 deletions docs/developer/networking.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,10 +39,10 @@ You can also can see all the information the Packets have, which we can either W
#[derive(Serialize)]
```

2. Next, you have set the packet using the packet macro, This uses the Packet ID from the enum order
2. Next, you have set the packet using the client_packet macro, This uses the Packet ID automatically sets the Packet ID from the JSON packets file

```rust
#[client_packet(ClientboundPlayPackets::Disconnect as i32)]
#[client_packet("play:disconnect")]
```

3. Now you can create the Struct.
Expand Down Expand Up @@ -85,7 +85,7 @@ impl CPlayDisconnect {

```rust
#[derive(Serialize)]
#[client_packet(ClientboundPlayPackets::Disconnect as i32)]
#[client_packet("play:disconnect")]
pub struct CPlayDisconnect {
reason: TextComponent,
}
Expand Down
2 changes: 1 addition & 1 deletion extractor/src/main/kotlin/de/snowii/extractor/Extractor.kt
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ import java.nio.file.Paths


class Extractor : ModInitializer {
val MOD_ID: String = "valence_extractor"
val MOD_ID: String = "pumpkin_extractor"
val LOGGER: Logger = LoggerFactory.getLogger(MOD_ID)

override fun onInitialize() {
Expand Down
2 changes: 1 addition & 1 deletion pumpkin/src/client/player_packet.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use std::sync::Arc;

use crate::{
commands::CommandSender,
command::CommandSender,
entity::player::{ChatMode, Hand, Player},
server::Server,
world::player_chunker,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@ use std::sync::Arc;

use async_trait::async_trait;

use crate::commands::dispatcher::InvalidTreeError;
use crate::commands::dispatcher::InvalidTreeError::InvalidConsumptionError;
use crate::commands::tree::{ConsumedArgs, RawArgs};
use crate::commands::CommandSender;
use crate::command::dispatcher::InvalidTreeError;
use crate::command::dispatcher::InvalidTreeError::InvalidConsumptionError;
use crate::command::tree::{ConsumedArgs, RawArgs};
use crate::command::CommandSender;
use crate::server::Server;

use super::tree::ArgumentConsumer;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
use async_trait::async_trait;

use crate::commands::dispatcher::InvalidTreeError;
use crate::commands::tree::{ConsumedArgs, RawArgs};
use crate::commands::CommandSender;
use crate::command::dispatcher::InvalidTreeError;
use crate::command::tree::{ConsumedArgs, RawArgs};
use crate::command::CommandSender;
use crate::server::Server;

use super::tree::ArgumentConsumer;
Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
use async_trait::async_trait;
use pumpkin_inventory::OpenContainer;

use crate::commands::tree::CommandTree;

use super::CommandExecutor;
use crate::command::{
tree::CommandTree, tree::ConsumedArgs, CommandExecutor, CommandSender, InvalidTreeError,
};

const NAMES: [&str; 2] = ["echest", "enderchest"];

Expand All @@ -16,10 +16,10 @@ struct EchestExecutor {}
impl CommandExecutor for EchestExecutor {
async fn execute<'a>(
&self,
sender: &mut super::CommandSender<'a>,
sender: &mut CommandSender<'a>,
server: &crate::server::Server,
_args: &super::tree::ConsumedArgs<'a>,
) -> Result<(), super::dispatcher::InvalidTreeError> {
_args: &ConsumedArgs<'a>,
) -> Result<(), InvalidTreeError> {
if let Some(player) = sender.as_player() {
let entity_id = player.entity_id();
player.open_container.store(Some(0));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,22 +6,18 @@ use pumpkin_core::GameMode;

use crate::TextComponent;

use crate::commands::arg_player::parse_arg_player;
use crate::command::arg_player::{parse_arg_player, PlayerArgumentConsumer};

use crate::commands::dispatcher::InvalidTreeError;
use crate::commands::dispatcher::InvalidTreeError::{
use crate::command::dispatcher::InvalidTreeError;
use crate::command::dispatcher::InvalidTreeError::{
InvalidConsumptionError, InvalidRequirementError,
};
use crate::commands::tree::{CommandTree, ConsumedArgs, RawArgs};
use crate::commands::tree_builder::{argument, require};
use crate::commands::CommandSender;
use crate::commands::CommandSender::Player;
use crate::command::tree::{ArgumentConsumer, CommandTree, ConsumedArgs, RawArgs};
use crate::command::tree_builder::{argument, require};
use crate::command::CommandSender::Player;
use crate::command::{CommandExecutor, CommandSender};
use crate::server::Server;

use super::arg_player::PlayerArgumentConsumer;
use super::tree::ArgumentConsumer;
use super::CommandExecutor;

const NAMES: [&str; 1] = ["gamemode"];

const DESCRIPTION: &str = "Change a player's gamemode.";
Expand Down
Original file line number Diff line number Diff line change
@@ -1,16 +1,13 @@
use async_trait::async_trait;
use pumpkin_core::text::TextComponent;

use crate::commands::dispatcher::InvalidTreeError::InvalidConsumptionError;
use crate::commands::dispatcher::{CommandDispatcher, InvalidTreeError};
use crate::commands::tree::{Command, CommandTree, ConsumedArgs, RawArgs};
use crate::commands::tree_builder::argument;
use crate::commands::CommandSender;
use crate::command::dispatcher::InvalidTreeError::InvalidConsumptionError;
use crate::command::dispatcher::{CommandDispatcher, InvalidTreeError};
use crate::command::tree::{ArgumentConsumer, Command, CommandTree, ConsumedArgs, RawArgs};
use crate::command::tree_builder::argument;
use crate::command::{CommandExecutor, CommandSender};
use crate::server::Server;

use super::tree::ArgumentConsumer;
use super::CommandExecutor;

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

const DESCRIPTION: &str = "Print a help message.";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,11 @@ use async_trait::async_trait;
use pumpkin_core::text::color::NamedColor;
use pumpkin_core::text::TextComponent;

use crate::commands::arg_player::parse_arg_player;
use crate::commands::tree::CommandTree;
use crate::commands::tree_builder::argument;

use super::arg_player::PlayerArgumentConsumer;
use super::CommandExecutor;
use crate::command::arg_player::{parse_arg_player, PlayerArgumentConsumer};
use crate::command::tree::CommandTree;
use crate::command::tree_builder::argument;
use crate::command::InvalidTreeError;
use crate::command::{tree::ConsumedArgs, CommandExecutor, CommandSender};

const NAMES: [&str; 1] = ["kick"];
const DESCRIPTION: &str = "Kicks the target player from the server.";
Expand All @@ -20,10 +19,10 @@ struct KickExecutor {}
impl CommandExecutor for KickExecutor {
async fn execute<'a>(
&self,
sender: &mut super::CommandSender<'a>,
sender: &mut CommandSender<'a>,
server: &crate::server::Server,
args: &super::tree::ConsumedArgs<'a>,
) -> Result<(), super::dispatcher::InvalidTreeError> {
args: &ConsumedArgs<'a>,
) -> Result<(), InvalidTreeError> {
let target = parse_arg_player(sender, server, ARG_TARGET, args).await?;
target
.kick(TextComponent::text("Kicked by an operator"))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,10 @@ use async_trait::async_trait;
use pumpkin_core::text::color::NamedColor;
use pumpkin_core::text::TextComponent;

use crate::commands::arg_player::parse_arg_player;
use crate::commands::tree::CommandTree;
use crate::commands::tree_builder::argument;

use super::arg_player::PlayerArgumentConsumer;
use super::CommandExecutor;
use crate::command::arg_player::{parse_arg_player, PlayerArgumentConsumer};
use crate::command::tree::CommandTree;
use crate::command::tree_builder::argument;
use crate::command::{tree::ConsumedArgs, CommandExecutor, CommandSender, InvalidTreeError};

const NAMES: [&str; 1] = ["kill"];
const DESCRIPTION: &str = "Kills a target player.";
Expand All @@ -20,10 +18,10 @@ struct KillExecutor {}
impl CommandExecutor for KillExecutor {
async fn execute<'a>(
&self,
sender: &mut super::CommandSender<'a>,
sender: &mut CommandSender<'a>,
server: &crate::server::Server,
args: &super::tree::ConsumedArgs<'a>,
) -> Result<(), super::dispatcher::InvalidTreeError> {
args: &ConsumedArgs<'a>,
) -> Result<(), InvalidTreeError> {
// TODO parse entities not only players
let target = parse_arg_player(sender, server, ARG_TARGET, args).await?;
target.living_entity.kill().await;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,12 @@ use async_trait::async_trait;
use pumpkin_core::text::{color::NamedColor, TextComponent};
use pumpkin_protocol::CURRENT_MC_PROTOCOL;

use crate::{commands::tree::CommandTree, server::CURRENT_MC_VERSION};

use super::CommandExecutor;
use crate::{
command::{
tree::CommandTree, tree::ConsumedArgs, CommandExecutor, CommandSender, InvalidTreeError,
},
server::CURRENT_MC_VERSION,
};

const NAMES: [&str; 1] = ["pumpkin"];

Expand All @@ -16,10 +19,10 @@ struct PumpkinExecutor {}
impl CommandExecutor for PumpkinExecutor {
async fn execute<'a>(
&self,
sender: &mut super::CommandSender<'a>,
sender: &mut CommandSender<'a>,
_server: &crate::server::Server,
_args: &super::tree::ConsumedArgs<'a>,
) -> Result<(), super::dispatcher::InvalidTreeError> {
_args: &ConsumedArgs<'a>,
) -> Result<(), InvalidTreeError> {
let version = env!("CARGO_PKG_VERSION");
let description = env!("CARGO_PKG_DESCRIPTION");

Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
use super::{
arg_simple::SimpleArgConsumer,
tree::CommandTree,
tree_builder::{argument, require},
CommandExecutor, CommandSender,
};
use async_trait::async_trait;
use pumpkin_core::text::TextComponent;
use pumpkin_protocol::client::play::CSystemChatMessage;

use crate::command::{
arg_simple::SimpleArgConsumer,
tree::{CommandTree, ConsumedArgs},
tree_builder::{argument, require},
CommandExecutor, CommandSender, InvalidTreeError,
};

const NAMES: [&str; 1] = ["say"];

const DESCRIPTION: &str = "Broadcast a message to all Players.";
Expand All @@ -20,10 +21,10 @@ struct SayExecutor {}
impl CommandExecutor for SayExecutor {
async fn execute<'a>(
&self,
sender: &mut super::CommandSender<'a>,
sender: &mut CommandSender<'a>,
server: &crate::server::Server,
args: &super::tree::ConsumedArgs<'a>,
) -> Result<(), super::dispatcher::InvalidTreeError> {
args: &ConsumedArgs<'a>,
) -> Result<(), InvalidTreeError> {
let sender = match sender {
CommandSender::Console => "Console",
CommandSender::Rcon(_) => "Rcon",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,9 @@ use async_trait::async_trait;
use pumpkin_core::text::color::NamedColor;
use pumpkin_core::text::TextComponent;

use crate::commands::tree::CommandTree;
use crate::commands::tree_builder::require;

use super::CommandExecutor;
use crate::command::tree::CommandTree;
use crate::command::tree_builder::require;
use crate::command::{tree::ConsumedArgs, CommandExecutor, CommandSender, InvalidTreeError};

const NAMES: [&str; 1] = ["stop"];

Expand All @@ -17,10 +16,10 @@ struct StopExecutor {}
impl CommandExecutor for StopExecutor {
async fn execute<'a>(
&self,
sender: &mut super::CommandSender<'a>,
sender: &mut CommandSender<'a>,
_server: &crate::server::Server,
_args: &super::tree::ConsumedArgs<'a>,
) -> Result<(), super::dispatcher::InvalidTreeError> {
_args: &ConsumedArgs<'a>,
) -> Result<(), InvalidTreeError> {
sender
.send_message(TextComponent::text("Stopping Server").color_named(NamedColor::Red))
.await;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,15 @@ use pumpkin_core::text::{
TextComponent,
};

use crate::server::Server;

use super::{
arg_position::{parse_arg_position, PositionArgumentConsumer},
arg_simple::SimpleArgConsumer,
dispatcher::InvalidTreeError,
tree::{CommandTree, ConsumedArgs},
tree_builder::{argument, literal},
CommandExecutor, CommandSender,
use crate::{
command::{
arg_position::{parse_arg_position, PositionArgumentConsumer},
arg_simple::SimpleArgConsumer,
tree::{CommandTree, ConsumedArgs},
tree_builder::{argument, literal},
CommandExecutor, CommandSender, InvalidTreeError,
},
server::Server,
};

const NAMES: [&str; 1] = ["worldborder"];
Expand Down
9 changes: 9 additions & 0 deletions pumpkin/src/command/commands/mod.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
pub mod cmd_echest;
pub mod cmd_gamemode;
pub mod cmd_help;
pub mod cmd_kick;
pub mod cmd_kill;
pub mod cmd_pumpkin;
pub mod cmd_say;
pub mod cmd_stop;
pub mod cmd_worldborder;
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
use pumpkin_core::text::TextComponent;

use crate::commands::dispatcher::InvalidTreeError::{
use crate::command::dispatcher::InvalidTreeError::{
InvalidConsumptionError, InvalidRequirementError,
};
use crate::commands::tree::{Command, CommandTree, ConsumedArgs, NodeType, RawArgs};
use crate::commands::CommandSender;
use crate::command::tree::{Command, CommandTree, ConsumedArgs, NodeType, RawArgs};
use crate::command::CommandSender;
use crate::server::Server;
use std::collections::HashMap;

Expand Down
17 changes: 6 additions & 11 deletions pumpkin/src/commands/mod.rs → pumpkin/src/command/mod.rs
Original file line number Diff line number Diff line change
@@ -1,28 +1,23 @@
use std::sync::Arc;

use async_trait::async_trait;
use commands::{
cmd_echest, cmd_gamemode, cmd_help, cmd_kick, cmd_kill, cmd_pumpkin, cmd_say, cmd_stop,
cmd_worldborder,
};
use dispatcher::InvalidTreeError;
use pumpkin_core::text::TextComponent;
use tree::ConsumedArgs;

use crate::commands::dispatcher::CommandDispatcher;
use crate::command::dispatcher::CommandDispatcher;
use crate::entity::player::Player;
use crate::server::Server;

mod arg_player;
mod arg_position;
mod arg_simple;

mod cmd_echest;
mod cmd_gamemode;
mod cmd_help;
mod cmd_kick;
mod cmd_kill;
mod cmd_pumpkin;
mod cmd_say;
mod cmd_stop;
mod cmd_worldborder;

mod commands;
pub mod dispatcher;
mod tree;
mod tree_builder;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use async_trait::async_trait;

use super::CommandExecutor;
use crate::{commands::CommandSender, server::Server};
use crate::{command::CommandSender, server::Server};
use std::collections::{HashMap, VecDeque};

/// see [`crate::commands::tree_builder::argument`]
Expand Down
Loading

0 comments on commit 9f70b95

Please sign in to comment.