From a5e7ff771d657258cedcc7a8b3ce265c655f0860 Mon Sep 17 00:00:00 2001 From: mat Date: Fri, 30 May 2025 20:07:28 -0330 Subject: implement missing brigadier features and cleanup some more --- azalea-brigadier/src/builder/argument_builder.rs | 11 +++++++++++ azalea-brigadier/src/builder/required_argument_builder.rs | 4 ++-- 2 files changed, 13 insertions(+), 2 deletions(-) (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 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}, }; @@ -89,6 +90,16 @@ impl ArgumentBuilder { pub fn executes(mut self, f: F) -> Self where F: Fn(&CommandContext) -> i32 + Send + Sync + 'static, + { + self.command = Some(Arc::new(move |ctx: &CommandContext| Ok(f(ctx)))); + self + } + + /// Same as [`Self::executes`] but returns a `Result`. + pub fn executes_result(mut self, f: F) -> Self + where + F: Fn(&CommandContext) -> Result + 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 Argument { } } - pub fn parse(&self, reader: &mut StringReader) -> Result, CommandSyntaxException> { + pub fn parse(&self, reader: &mut StringReader) -> Result, CommandSyntaxError> { self.parser.parse(reader) } -- cgit v1.2.3