1pub mod combat;
2pub mod debug;
3pub mod movement;
4
5use azalea::{
6 Client, brigadier::prelude::*, chat::ChatPacket, ecs::prelude::*, entity::metadata::Player,
7 player::GameProfileComponent,
8};
9use parking_lot::Mutex;
10
11use crate::State;
12
13pub type Ctx = CommandContext<Mutex<CommandSource>>;
14
15pub struct CommandSource {
16 pub bot: Client,
17 pub state: State,
18 pub chat: ChatPacket,
19}
20
21impl CommandSource {
22 pub fn reply(&self, message: impl Into<String>) {
23 let message = message.into();
24 if self.chat.is_whisper() {
25 self.bot
26 .chat(format!("/w {} {message}", self.chat.sender().unwrap()));
27 } else {
28 self.bot.chat(message);
29 }
30 }
31
32 pub fn entity(&mut self) -> Option<Entity> {
33 let username = self.chat.sender()?;
34 self.bot
35 .any_entity_by::<&GameProfileComponent, With<Player>>(
36 |profile: &GameProfileComponent| profile.name == username,
37 )
38 }
39}
40
41pub fn register_commands(commands: &mut CommandDispatcher<Mutex<CommandSource>>) {
42 combat::register(commands);
43 debug::register(commands);
44 movement::register(commands);
45}