Split commands into their own Folder

Now its much nicer separate from the command base
This commit is contained in:
Snowiiii
2024-10-29 22:47:52 +01:00
parent 74c4662121
commit 9f70b95b9b
24 changed files with 105 additions and 108 deletions

View File

@@ -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.
@@ -85,7 +85,7 @@ impl CPlayDisconnect {
```rust
#[derive(Serialize)]
#[client_packet(ClientboundPlayPackets::Disconnect as i32)]
#[client_packet("play:disconnect")]
pub struct CPlayDisconnect {
reason: TextComponent,
}

View File

@@ -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() {

View File

@@ -1,7 +1,7 @@
use std::sync::Arc;
use crate::{
commands::CommandSender,
command::CommandSender,
entity::player::{ChatMode, Hand, Player},
server::Server,
world::player_chunker,

View File

@@ -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;

View File

@@ -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;

View File

@@ -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"];
@@ -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));

View File

@@ -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.";

View File

@@ -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.";

View File

@@ -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.";
@@ -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"))

View File

@@ -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.";
@@ -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;

View File

@@ -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"];
@@ -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");

View File

@@ -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.";
@@ -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",

View File

@@ -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"];
@@ -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;

View File

@@ -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"];

View File

@@ -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;

View File

@@ -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;

View File

@@ -1,11 +1,15 @@
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;
@@ -13,16 +17,7 @@ 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;

View File

@@ -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`]

View File

@@ -1,5 +1,5 @@
use crate::commands::tree::{ArgumentConsumer, CommandTree, Node, NodeType};
use crate::commands::CommandSender;
use crate::command::tree::{ArgumentConsumer, CommandTree, Node, NodeType};
use crate::command::CommandSender;
use super::CommandExecutor;

View File

@@ -1,4 +1,4 @@
use crate::commands::tree::{CommandTree, Node, NodeType};
use crate::command::tree::{CommandTree, Node, NodeType};
use std::collections::VecDeque;
use std::fmt::{Display, Formatter, Write};

View File

@@ -40,7 +40,7 @@ use std::time::Instant;
// Setup some tokens to allow us to identify which event is for which socket.
pub mod client;
pub mod commands;
pub mod command;
pub mod entity;
pub mod error;
pub mod proxy;
@@ -257,7 +257,7 @@ fn setup_console(server: Arc<Server>) {
if !out.is_empty() {
let dispatcher = server.command_dispatcher.clone();
dispatcher
.handle_command(&mut commands::CommandSender::Console, &server, &out)
.handle_command(&mut command::CommandSender::Console, &server, &out)
.await;
}
}

View File

@@ -119,7 +119,7 @@ impl RCONClient {
let dispatcher = server.command_dispatcher.clone();
dispatcher
.handle_command(
&mut crate::commands::CommandSender::Rcon(&output),
&mut crate::command::CommandSender::Rcon(&output),
server,
packet.get_body(),
)

View File

@@ -23,7 +23,7 @@ use tokio::sync::RwLock;
use crate::client::EncryptionError;
use crate::{
client::Client,
commands::{default_dispatcher, dispatcher::CommandDispatcher},
command::{default_dispatcher, dispatcher::CommandDispatcher},
entity::player::Player,
world::World,
};