From 53d51a5ca92aa8ddea9d82b6b44ac7aaa06c2095 Mon Sep 17 00:00:00 2001 From: mat Date: Sun, 7 May 2023 02:50:52 -0500 Subject: more brigadier docs --- azalea-brigadier/src/builder/argument_builder.rs | 41 ++++++++++++++++++++++++ 1 file changed, 41 insertions(+) (limited to 'azalea-brigadier/src/builder') diff --git a/azalea-brigadier/src/builder/argument_builder.rs b/azalea-brigadier/src/builder/argument_builder.rs index c6f2146a..643a3bd0 100755 --- a/azalea-brigadier/src/builder/argument_builder.rs +++ b/azalea-brigadier/src/builder/argument_builder.rs @@ -43,15 +43,38 @@ impl ArgumentBuilder { } } + /// Continue building this node with a child node. + /// + /// ``` + /// # use azalea_brigadier::prelude::*; + /// # let mut subject = CommandDispatcher::<()>::new(); + /// literal("foo").then( + /// literal("bar").executes(|ctx: &CommandContext<()>| 42) + /// ) + /// # ; + /// ``` pub fn then(self, argument: ArgumentBuilder) -> Self { self.then_built(argument.build()) } + /// Add an already built child node to this node. + /// + /// You should usually use [`Self::then`] instead. pub fn then_built(mut self, argument: CommandNode) -> Self { self.arguments.add_child(&Arc::new(RwLock::new(argument))); self } + /// Set the command to be executed when this node is reached. If this is not + /// present on a node, it is not a valid command. + /// + /// ``` + /// # use azalea_brigadier::prelude::*; + /// # let mut subject = CommandDispatcher::<()>::new(); + /// # subject.register( + /// literal("foo").executes(|ctx: &CommandContext<()>| 42) + /// # ); + /// ``` pub fn executes(mut self, f: F) -> Self where F: Fn(&CommandContext) -> i32 + Send + Sync + 'static, @@ -60,6 +83,22 @@ impl ArgumentBuilder { self } + /// Set the requirement for this node to be considered. If this is not + /// present on a node, it is considered to always pass. + /// + /// ``` + /// # use azalea_brigadier::prelude::*; + /// # use std::sync::Arc; + /// # pub struct CommandSource { + /// # pub opped: bool, + /// # } + /// # let mut subject = CommandDispatcher::::new(); + /// # subject.register( + /// literal("foo") + /// .requires(|s: Arc| s.opped) + /// // ... + /// # .executes(|ctx: &CommandContext| 42) + /// # ); pub fn requires(mut self, requirement: F) -> Self where F: Fn(Arc) -> bool + Send + Sync + 'static, @@ -95,6 +134,8 @@ impl ArgumentBuilder { self } + /// Manually build this node into a [`CommandNode`]. You probably don't need + /// to do this yourself. pub fn build(self) -> CommandNode { let mut result = CommandNode { value: self.arguments.value, -- cgit v1.2.3