Commands: Fix Bug, Refactor Arguments, Add /tp (#227)

* fix command dispatch, add/refactor arguments & add tp command

* implement teleport facing location/facing entity

* implement teleport facing location/facing entity

* implement arg_player/arg_entity and refactor commands accordingly

* implement ~ coordinate notation

* refactor arg_position_3d

* major command refactor

* add documentation

* add default names to more argument types

* add argument names to arg_bounded_nums

* change command argument api

---------

Co-authored-by: user622628252416 <nnew8715@gmail.com>
This commit is contained in:
user622628252416
2024-11-03 23:15:49 +01:00
committed by GitHub
parent 8db277f63e
commit 87aa5ec493
31 changed files with 1492 additions and 427 deletions

View File

@@ -1,22 +1,20 @@
use std::sync::Arc;
use args::ConsumedArgs;
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,
cmd_teleport, cmd_worldborder,
};
use dispatcher::InvalidTreeError;
use pumpkin_core::math::vector3::Vector3;
use pumpkin_core::text::TextComponent;
use tree::ConsumedArgs;
use crate::command::dispatcher::CommandDispatcher;
use crate::entity::player::Player;
use crate::server::Server;
mod arg_player;
mod arg_position;
mod arg_simple;
pub mod args;
mod commands;
pub mod dispatcher;
mod tree;
@@ -60,6 +58,14 @@ impl<'a> CommandSender<'a> {
pub const fn permission_lvl(&self) -> i32 {
4
}
#[must_use]
pub fn position(&self) -> Option<Vector3<f64>> {
match self {
CommandSender::Console | CommandSender::Rcon(..) => None,
CommandSender::Player(p) => Some(p.living_entity.entity.pos.load()),
}
}
}
#[must_use]
@@ -75,6 +81,7 @@ pub fn default_dispatcher<'a>() -> Arc<CommandDispatcher<'a>> {
dispatcher.register(cmd_kill::init_command_tree());
dispatcher.register(cmd_kick::init_command_tree());
dispatcher.register(cmd_worldborder::init_command_tree());
dispatcher.register(cmd_teleport::init_command_tree());
Arc::new(dispatcher)
}