diff options
Diffstat (limited to 'azalea-brigadier/src/builder')
| -rw-r--r-- | azalea-brigadier/src/builder/argument_builder.rs | 11 | ||||
| -rw-r--r-- | azalea-brigadier/src/builder/required_argument_builder.rs | 4 |
2 files changed, 13 insertions, 2 deletions
diff --git a/azalea-brigadier/src/builder/argument_builder.rs b/azalea-brigadier/src/builder/argument_builder.rs index bc7f0ac6..1731d44d 100644 --- a/azalea-brigadier/src/builder/argument_builder.rs +++ b/azalea-brigadier/src/builder/argument_builder.rs @@ -5,6 +5,7 @@ use parking_lot::RwLock; use super::{literal_argument_builder::Literal, required_argument_builder::Argument}; use crate::{ context::CommandContext, + errors::CommandSyntaxError, modifier::RedirectModifier, tree::{Command, CommandNode}, }; @@ -90,6 +91,16 @@ impl<S> ArgumentBuilder<S> { where F: Fn(&CommandContext<S>) -> i32 + Send + Sync + 'static, { + self.command = Some(Arc::new(move |ctx: &CommandContext<S>| Ok(f(ctx)))); + self + } + + /// Same as [`Self::executes`] but returns a `Result<i32, + /// CommandSyntaxError>`. + pub fn executes_result<F>(mut self, f: F) -> Self + where + F: Fn(&CommandContext<S>) -> Result<i32, CommandSyntaxError> + Send + Sync + 'static, + { self.command = Some(Arc::new(f)); self } diff --git a/azalea-brigadier/src/builder/required_argument_builder.rs b/azalea-brigadier/src/builder/required_argument_builder.rs index 7c0f1015..3fc33143 100644 --- a/azalea-brigadier/src/builder/required_argument_builder.rs +++ b/azalea-brigadier/src/builder/required_argument_builder.rs @@ -8,7 +8,7 @@ use super::argument_builder::{ArgumentBuilder, ArgumentBuilderType}; use crate::{ arguments::ArgumentType, context::CommandContext, - exceptions::CommandSyntaxException, + errors::CommandSyntaxError, string_reader::StringReader, suggestion::{SuggestionProvider, Suggestions, SuggestionsBuilder}, }; @@ -33,7 +33,7 @@ impl<S> Argument<S> { } } - pub fn parse(&self, reader: &mut StringReader) -> Result<Arc<dyn Any>, CommandSyntaxException> { + pub fn parse(&self, reader: &mut StringReader) -> Result<Arc<dyn Any>, CommandSyntaxError> { self.parser.parse(reader) } |
