aboutsummaryrefslogtreecommitdiff
path: root/azalea/examples/testbot/commands.rs
diff options
context:
space:
mode:
authormat <git@matdoes.dev>2024-01-07 21:50:38 -0600
committermat <git@matdoes.dev>2024-01-07 21:50:38 -0600
commit0aa439d5caa8028b6d310de45258cbcef16ca2eb (patch)
tree7c8c201935eb62196c2d57718965861724d22fe8 /azalea/examples/testbot/commands.rs
parent5ea127114582e3320381d09e880f6a433ccb8710 (diff)
downloadazalea-drasl-0aa439d5caa8028b6d310de45258cbcef16ca2eb.tar.xz
rewrite testbot to use brigadier
Diffstat (limited to 'azalea/examples/testbot/commands.rs')
-rw-r--r--azalea/examples/testbot/commands.rs46
1 files changed, 46 insertions, 0 deletions
diff --git a/azalea/examples/testbot/commands.rs b/azalea/examples/testbot/commands.rs
new file mode 100644
index 00000000..db606aa6
--- /dev/null
+++ b/azalea/examples/testbot/commands.rs
@@ -0,0 +1,46 @@
+pub mod combat;
+pub mod debug;
+pub mod movement;
+
+use azalea::brigadier::prelude::*;
+use azalea::chat::ChatPacket;
+use azalea::ecs::prelude::Entity;
+use azalea::ecs::prelude::*;
+use azalea::entity::metadata::Player;
+use azalea::Client;
+use azalea::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: &str) {
+ if self.chat.is_whisper() {
+ self.bot
+ .chat(&format!("/w {} {}", self.chat.username().unwrap(), message));
+ } else {
+ self.bot.chat(message);
+ }
+ }
+
+ pub fn entity(&mut self) -> Option<Entity> {
+ let username = self.chat.username()?;
+ 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);
+}