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