From 38db231ea8fa0fb223e16637db0b6ec65b2b81ef Mon Sep 17 00:00:00 2001 From: mat Date: Thu, 12 Oct 2023 20:14:29 -0500 Subject: brigadier usages --- azalea-brigadier/src/tree/mod.rs | 20 +++++++++++++++++--- 1 file changed, 17 insertions(+), 3 deletions(-) (limited to 'azalea-brigadier/src/tree') diff --git a/azalea-brigadier/src/tree/mod.rs b/azalea-brigadier/src/tree/mod.rs index cec972dc..8ab3526e 100755 --- a/azalea-brigadier/src/tree/mod.rs +++ b/azalea-brigadier/src/tree/mod.rs @@ -10,7 +10,13 @@ use crate::{ modifier::RedirectModifier, string_reader::StringReader, }; -use std::{collections::HashMap, fmt::Debug, hash::Hash, ptr, sync::Arc}; +use std::{ + collections::{BTreeMap, HashMap}, + fmt::Debug, + hash::Hash, + ptr, + sync::Arc, +}; pub type Command = Option) -> i32 + Send + Sync>>; @@ -19,7 +25,8 @@ pub type Command = Option) -> i32 + Send + Sync pub struct CommandNode { pub value: ArgumentBuilderType, - pub children: HashMap>>>, + // this is a BTreeMap because children need to be ordered when getting command suggestions + pub children: BTreeMap>>>, pub literals: HashMap>>>, pub arguments: HashMap>>>, @@ -125,6 +132,13 @@ impl CommandNode { } } + pub fn usage_text(&self) -> String { + match &self.value { + ArgumentBuilderType::Argument(argument) => format!("<{}>", argument.name), + ArgumentBuilderType::Literal(literal) => literal.value.to_owned(), + } + } + pub fn child(&self, name: &str) -> Option>>> { self.children.get(name).cloned() } @@ -216,7 +230,7 @@ impl Default for CommandNode { Self { value: ArgumentBuilderType::Literal(Literal::default()), - children: HashMap::new(), + children: BTreeMap::new(), literals: HashMap::new(), arguments: HashMap::new(), -- cgit v1.2.3