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