aboutsummaryrefslogtreecommitdiff
path: root/azalea-brigadier/src/builder
diff options
context:
space:
mode:
authormat <git@matdoes.dev>2025-05-30 20:07:28 -0330
committermat <git@matdoes.dev>2025-05-30 16:37:40 -0700
commita5e7ff771d657258cedcc7a8b3ce265c655f0860 (patch)
treeea5fdbbee32c1b9917a7ece03f6a1a70ee8e63fa /azalea-brigadier/src/builder
parentda73b4316de4b26322c53f14222c7751a0be55a1 (diff)
downloadazalea-drasl-a5e7ff771d657258cedcc7a8b3ce265c655f0860.tar.xz
implement missing brigadier features and cleanup some more
Diffstat (limited to 'azalea-brigadier/src/builder')
-rw-r--r--azalea-brigadier/src/builder/argument_builder.rs11
-rw-r--r--azalea-brigadier/src/builder/required_argument_builder.rs4
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)
}