From a72a47ced76065caf739898954cd18edbc39174b Mon Sep 17 00:00:00 2001 From: mat Date: Sun, 17 Apr 2022 14:02:13 -0500 Subject: Rewrite brigadier --- azalea-brigadier/src/modifier.rs | 9 +++++++++ 1 file changed, 9 insertions(+) create mode 100644 azalea-brigadier/src/modifier.rs (limited to 'azalea-brigadier/src/modifier.rs') diff --git a/azalea-brigadier/src/modifier.rs b/azalea-brigadier/src/modifier.rs new file mode 100644 index 00000000..84528696 --- /dev/null +++ b/azalea-brigadier/src/modifier.rs @@ -0,0 +1,9 @@ +use std::{any::Any, rc::Rc}; + +use crate::{ + context::CommandContext, exceptions::command_syntax_exception::CommandSyntaxException, +}; + +pub trait RedirectModifier { + fn apply(&self, context: &CommandContext) -> Result>, CommandSyntaxException>; +} -- cgit v1.2.3 From d68233e0b1ff61d09ab2c4e22a42f3326054539b Mon Sep 17 00:00:00 2001 From: mat Date: Sun, 17 Apr 2022 20:46:43 -0500 Subject: simplify the generic so it's not an Rc --- azalea-brigadier/src/builder/argument_builder.rs | 37 ++++- .../src/builder/literal_argument_builder.rs | 2 +- .../src/builder/required_argument_builder.rs | 2 +- azalea-brigadier/src/context.rs | 73 +++++++--- azalea-brigadier/src/dispatcher.rs | 161 ++++++++++++++++++++- azalea-brigadier/src/lib.rs | 2 +- azalea-brigadier/src/modifier.rs | 9 +- azalea-brigadier/src/parse_results.rs | 4 +- azalea-brigadier/src/parsers.rs | 2 +- azalea-brigadier/src/tree.rs | 56 +++++-- 10 files changed, 295 insertions(+), 53 deletions(-) (limited to 'azalea-brigadier/src/modifier.rs') diff --git a/azalea-brigadier/src/builder/argument_builder.rs b/azalea-brigadier/src/builder/argument_builder.rs index 3c9ae3ed..39edfbd3 100644 --- a/azalea-brigadier/src/builder/argument_builder.rs +++ b/azalea-brigadier/src/builder/argument_builder.rs @@ -1,4 +1,7 @@ -use crate::{context::CommandContext, modifier::RedirectModifier, tree::CommandNode}; +use crate::{ + context::CommandContext, exceptions::command_syntax_exception::CommandSyntaxException, + modifier::RedirectModifier, tree::CommandNode, +}; use super::{literal_argument_builder::Literal, required_argument_builder::Argument}; use std::{any::Any, cell::RefCell, fmt::Debug, rc::Rc}; @@ -10,8 +13,7 @@ pub enum ArgumentBuilderType { } /// A node that hasn't yet been built. -#[derive(Clone)] -pub struct ArgumentBuilder { +pub struct ArgumentBuilder { arguments: CommandNode, command: Option) -> i32>>, @@ -19,11 +21,24 @@ pub struct ArgumentBuilder { target: Option>>>, forks: bool, - modifier: Option>>, + modifier: Option>>, +} + +impl Clone for ArgumentBuilder { + fn clone(&self) -> Self { + Self { + arguments: self.arguments.clone(), + command: self.command.clone(), + requirement: self.requirement.clone(), + target: self.target.clone(), + forks: self.forks.clone(), + modifier: self.modifier.clone(), + } + } } /// A node that isn't yet built. -impl ArgumentBuilder { +impl ArgumentBuilder { pub fn new(value: ArgumentBuilderType) -> Self { Self { arguments: CommandNode { @@ -65,10 +80,18 @@ impl ArgumentBuilder { self.forward(target, None, false) } + pub fn fork( + &mut self, + target: Rc>>, + modifier: Rc>, + ) -> Self { + self.forward(target, Some(modifier), true) + } + pub fn forward( &mut self, target: Rc>>, - modifier: Option>>, + modifier: Option>>, fork: bool, ) -> Self { if !self.arguments.children.is_empty() { @@ -99,7 +122,7 @@ impl ArgumentBuilder { } } -impl Debug for ArgumentBuilder { +impl Debug for ArgumentBuilder { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { f.debug_struct("ArgumentBuilder") .field("arguments", &self.arguments) diff --git a/azalea-brigadier/src/builder/literal_argument_builder.rs b/azalea-brigadier/src/builder/literal_argument_builder.rs index e5e165d8..65a5644e 100644 --- a/azalea-brigadier/src/builder/literal_argument_builder.rs +++ b/azalea-brigadier/src/builder/literal_argument_builder.rs @@ -21,6 +21,6 @@ impl From for ArgumentBuilderType { } /// Shortcut for creating a new literal builder node. -pub fn literal(value: &str) -> ArgumentBuilder { +pub fn literal(value: &str) -> ArgumentBuilder { ArgumentBuilder::new(ArgumentBuilderType::Literal(Literal::new(value))) } diff --git a/azalea-brigadier/src/builder/required_argument_builder.rs b/azalea-brigadier/src/builder/required_argument_builder.rs index 0eb5d11a..cae0cddb 100644 --- a/azalea-brigadier/src/builder/required_argument_builder.rs +++ b/azalea-brigadier/src/builder/required_argument_builder.rs @@ -41,6 +41,6 @@ impl Debug for Argument { } /// Shortcut for creating a new argument builder node. -pub fn argument(name: &str, parser: impl Parser + 'static) -> ArgumentBuilder { +pub fn argument(name: &str, parser: impl Parser + 'static) -> ArgumentBuilder { ArgumentBuilder::new(Argument::new(name, Rc::new(parser)).into()) } diff --git a/azalea-brigadier/src/context.rs b/azalea-brigadier/src/context.rs index 5ffe2028..b798397b 100644 --- a/azalea-brigadier/src/context.rs +++ b/azalea-brigadier/src/context.rs @@ -1,25 +1,43 @@ use std::{any::Any, cell::RefCell, collections::HashMap, fmt::Debug, rc::Rc}; use crate::{ - dispatcher::CommandDispatcher, modifier::RedirectModifier, string_range::StringRange, - tree::CommandNode, + dispatcher::CommandDispatcher, + modifier::RedirectModifier, + string_range::StringRange, + tree::{CommandNode, ParsedCommandNode}, }; -#[derive(Clone)] -pub struct CommandContextBuilder { +pub struct CommandContextBuilder { pub arguments: HashMap, pub root: Rc>>, - pub nodes: Vec>>, + pub nodes: Vec>, pub dispatcher: Rc>, pub source: Rc, pub command: Option) -> i32>>, pub child: Option>>, pub range: StringRange, - pub modifier: Option>>, + pub modifier: Option>>, pub forks: bool, } -impl CommandContextBuilder { +impl Clone for CommandContextBuilder { + fn clone(&self) -> Self { + Self { + arguments: self.arguments.clone(), + root: self.root.clone(), + nodes: self.nodes.clone(), + dispatcher: self.dispatcher.clone(), + source: self.source.clone(), + command: self.command.clone(), + child: self.child.clone(), + range: self.range.clone(), + modifier: self.modifier.clone(), + forks: self.forks.clone(), + } + } +} + +impl CommandContextBuilder { // CommandDispatcher dispatcher, final S source, final CommandNode rootNode, final int start pub fn new( dispatcher: Rc>, @@ -58,11 +76,14 @@ impl CommandContextBuilder { self.arguments.insert(name.to_string(), argument); self } - pub fn with_node(&mut self, node: Rc>, range: StringRange) -> &Self { - self.nodes.push(node.clone()); + pub fn with_node(&mut self, node: Rc>>, range: StringRange) -> &Self { + self.nodes.push(ParsedCommandNode { + node: node.clone(), + range: range.clone(), + }); self.range = StringRange::encompassing(&self.range, &range); - self.modifier = node.modifier.clone(); - self.forks = node.forks; + self.modifier = node.borrow().modifier.clone(); + self.forks = node.borrow().forks; self } @@ -82,12 +103,12 @@ impl CommandContextBuilder { } } -impl Debug for CommandContextBuilder { +impl Debug for CommandContextBuilder { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { f.debug_struct("CommandContextBuilder") // .field("arguments", &self.arguments) .field("root", &self.root) - .field("nodes", &self.nodes) + // .field("nodes", &self.nodes) // .field("dispatcher", &self.dispatcher) // .field("source", &self.source) // .field("command", &self.command) @@ -105,22 +126,38 @@ pub struct ParsedArgument { pub result: Rc, } -#[derive(Clone)] /// A built `CommandContextBuilder`. -pub struct CommandContext { +pub struct CommandContext { pub source: Rc, pub input: String, pub arguments: HashMap, pub command: Option) -> i32>>, pub root_node: Rc>>, - pub nodes: Vec>>, + pub nodes: Vec>, pub range: StringRange, pub child: Option>>, - pub modifier: Option>>, + pub modifier: Option>>, pub forks: bool, } -impl CommandContext { +impl Clone for CommandContext { + fn clone(&self) -> Self { + Self { + source: self.source.clone(), + input: self.input.clone(), + arguments: self.arguments.clone(), + command: self.command.clone(), + root_node: self.root_node.clone(), + nodes: self.nodes.clone(), + range: self.range.clone(), + child: self.child.clone(), + modifier: self.modifier.clone(), + forks: self.forks.clone(), + } + } +} + +impl CommandContext { pub fn copy_for(&self, source: Rc) -> Self { if Rc::ptr_eq(&source, &self.source) { return self.clone(); diff --git a/azalea-brigadier/src/dispatcher.rs b/azalea-brigadier/src/dispatcher.rs index b62455f5..6031452e 100644 --- a/azalea-brigadier/src/dispatcher.rs +++ b/azalea-brigadier/src/dispatcher.rs @@ -13,12 +13,12 @@ use std::{ }; #[derive(Default)] -pub struct CommandDispatcher { +pub struct CommandDispatcher { root: Rc>>, _marker: PhantomData, } -impl CommandDispatcher { +impl CommandDispatcher { pub fn new() -> Self { Self { root: Rc::new(RefCell::new(CommandNode::default())), @@ -32,10 +32,10 @@ impl CommandDispatcher { build } - pub fn parse(&self, command: StringReader, source: S) -> ParseResults { + pub fn parse(&self, command: StringReader, source: Rc) -> ParseResults { let context = CommandContextBuilder::new( Rc::new(self.clone()), - Rc::new(source), + source, self.root.clone(), command.cursor(), ); @@ -153,7 +153,11 @@ impl CommandDispatcher { }) } - pub fn execute(&self, input: StringReader, source: S) -> Result { + pub fn execute( + &self, + input: StringReader, + source: Rc, + ) -> Result { let parse = self.parse(input, source); Self::execute_parsed(parse) } @@ -191,7 +195,7 @@ impl CommandDispatcher { found_command = true; let modifier = &context.modifier; if let Some(modifier) = modifier { - let results = modifier.apply(context); + let results = modifier(context); if let Ok(results) = results { if !results.is_empty() { next.extend(results.iter().map(|s| child.copy_for(s.clone()))); @@ -235,7 +239,7 @@ impl CommandDispatcher { } } -impl Clone for CommandDispatcher { +impl Clone for CommandDispatcher { fn clone(&self) -> Self { Self { root: self.root.clone(), @@ -244,11 +248,13 @@ impl Clone for CommandDispatcher { } } +/* #[cfg(test)] mod tests { use super::*; use crate::{ builder::{literal_argument_builder::literal, required_argument_builder::argument}, + modifier::RedirectModifier, parsers::integer, }; @@ -655,4 +661,145 @@ mod tests { 100 ); } + // @Test + // public void testExecuteRedirectedMultipleTimes() throws Exception { + // final LiteralCommandNode concreteNode = subject.register(literal("actual").executes(command)); + // final LiteralCommandNode redirectNode = subject.register(literal("redirected").redirect(subject.getRoot())); + + // final String input = "redirected redirected actual"; + + // final ParseResults parse = subject.parse(input, source); + // assertThat(parse.getContext().getRange().get(input), equalTo("redirected")); + // assertThat(parse.getContext().getNodes().size(), is(1)); + // assertThat(parse.getContext().getRootNode(), is(subject.getRoot())); + // assertThat(parse.getContext().getNodes().get(0).getRange(), equalTo(parse.getContext().getRange())); + // assertThat(parse.getContext().getNodes().get(0).getNode(), is(redirectNode)); + + // final CommandContextBuilder child1 = parse.getContext().getChild(); + // assertThat(child1, is(notNullValue())); + // assertThat(child1.getRange().get(input), equalTo("redirected")); + // assertThat(child1.getNodes().size(), is(1)); + // assertThat(child1.getRootNode(), is(subject.getRoot())); + // assertThat(child1.getNodes().get(0).getRange(), equalTo(child1.getRange())); + // assertThat(child1.getNodes().get(0).getNode(), is(redirectNode)); + + // final CommandContextBuilder child2 = child1.getChild(); + // assertThat(child2, is(notNullValue())); + // assertThat(child2.getRange().get(input), equalTo("actual")); + // assertThat(child2.getNodes().size(), is(1)); + // assertThat(child2.getRootNode(), is(subject.getRoot())); + // assertThat(child2.getNodes().get(0).getRange(), equalTo(child2.getRange())); + // assertThat(child2.getNodes().get(0).getNode(), is(concreteNode)); + + // assertThat(subject.execute(parse), is(42)); + // verify(command).run(any(CommandContext.class)); + // } + #[test] + fn test_execute_redirected_multiple_times() { + let mut subject = CommandDispatcher::new(); + + let concrete_node = subject.register(literal("actual").executes(|_| 42)); + let root = subject.root.clone(); + let redirect_node = subject.register(literal("redirected").redirect(root.clone())); + + let input = "redirected redirected actual"; + + let parse = subject.parse(input.into(), Rc::new(CommandSource {})); + assert_eq!(parse.context.range.get(input), "redirected"); + assert_eq!(parse.context.nodes.len(), 1); + assert_eq!(parse.context.root, root); + assert_eq!(parse.context.nodes[0].range, parse.context.range); + assert_eq!(parse.context.nodes[0].node, redirect_node); + + let child1 = parse.context.child.clone(); + assert!(child1.is_some()); + assert_eq!(child1.clone().unwrap().range.get(input), "redirected"); + assert_eq!(child1.clone().unwrap().nodes.len(), 1); + assert_eq!(child1.clone().unwrap().root, root); + assert_eq!( + child1.clone().unwrap().nodes[0].range, + child1.clone().unwrap().range + ); + assert_eq!(child1.clone().unwrap().nodes[0].node, redirect_node); + + let child2 = child1.unwrap().child.clone(); + assert!(child2.is_some()); + assert_eq!(child2.clone().unwrap().range.get(input), "actual"); + assert_eq!(child2.clone().unwrap().nodes.len(), 1); + assert_eq!(child2.clone().unwrap().root, root); + assert_eq!( + child2.clone().unwrap().nodes[0].range, + child2.clone().unwrap().range + ); + assert_eq!(child2.clone().unwrap().nodes[0].node, concrete_node); + + assert_eq!(CommandDispatcher::execute_parsed(parse).unwrap(), 42); + } + // @Test + // public void testExecuteRedirected() throws Exception { + // final RedirectModifier modifier = mock(RedirectModifier.class); + // final Object source1 = new Object(); + // final Object source2 = new Object(); + + // when(modifier.apply(argThat(hasProperty("source", is(source))))).thenReturn(Lists.newArrayList(source1, source2)); + + // final LiteralCommandNode concreteNode = subject.register(literal("actual").executes(command)); + // final LiteralCommandNode redirectNode = subject.register(literal("redirected").fork(subject.getRoot(), modifier)); + + // final String input = "redirected actual"; + // final ParseResults parse = subject.parse(input, source); + // assertThat(parse.getContext().getRange().get(input), equalTo("redirected")); + // assertThat(parse.getContext().getNodes().size(), is(1)); + // assertThat(parse.getContext().getRootNode(), equalTo(subject.getRoot())); + // assertThat(parse.getContext().getNodes().get(0).getRange(), equalTo(parse.getContext().getRange())); + // assertThat(parse.getContext().getNodes().get(0).getNode(), is(redirectNode)); + // assertThat(parse.getContext().getSource(), is(source)); + + // final CommandContextBuilder parent = parse.getContext().getChild(); + // assertThat(parent, is(notNullValue())); + // assertThat(parent.getRange().get(input), equalTo("actual")); + // assertThat(parent.getNodes().size(), is(1)); + // assertThat(parse.getContext().getRootNode(), equalTo(subject.getRoot())); + // assertThat(parent.getNodes().get(0).getRange(), equalTo(parent.getRange())); + // assertThat(parent.getNodes().get(0).getNode(), is(concreteNode)); + // assertThat(parent.getSource(), is(source)); + + // assertThat(subject.execute(parse), is(2)); + // verify(command).run(argThat(hasProperty("source", is(source1)))); + // verify(command).run(argThat(hasProperty("source", is(source2)))); + // } + #[test] + fn test_execute_redirected() { + let mut subject = CommandDispatcher::new(); + + let source1 = Rc::new(CommandSource {}); + let source2 = Rc::new(CommandSource {}); + + let modifier = move |source: &CommandContext>| -> Result>, CommandSyntaxException> { + Ok(vec![source1.clone(), source2.clone()]) + }; + + let concrete_node = subject.register(literal("actual").executes(|_| 42)); + let redirect_node = + subject.register(literal("redirected").fork(subject.root.clone(), modifier)); + + let input = "redirected actual"; + let parse = subject.parse(input.into(), Rc::new(CommandSource {})); + assert_eq!(parse.context.range.get(input), "redirected"); + assert_eq!(parse.context.nodes.len(), 1); + assert_eq!(parse.context.root, subject.root); + assert_eq!(parse.context.nodes[0].range, parse.context.range); + assert_eq!(parse.context.nodes[0].node, redirect_node); + + let parent = parse.context.child.clone(); + assert!(parent.is_some()); + let parent = parent.unwrap(); + assert_eq!(parent.range.get(input), "actual"); + assert_eq!(parent.nodes.len(), 1); + assert_eq!(parse.context.root, subject.root); + assert_eq!(parent.nodes[0].range, parent.range); + assert_eq!(parent.nodes[0].node, concrete_node); + // assert_eq!(parent.source, Rc::new(CommandSource {})); + } } +*/ diff --git a/azalea-brigadier/src/lib.rs b/azalea-brigadier/src/lib.rs index 2f4fffe9..d3db8dcf 100644 --- a/azalea-brigadier/src/lib.rs +++ b/azalea-brigadier/src/lib.rs @@ -27,7 +27,7 @@ mod tests { #[test] fn it_works() { - let mut dispatcher = CommandDispatcher::>::new(); + let mut dispatcher = CommandDispatcher::::new(); let source = Rc::new(CommandSourceStack { player: "player".to_string(), diff --git a/azalea-brigadier/src/modifier.rs b/azalea-brigadier/src/modifier.rs index 84528696..c1a9aaf0 100644 --- a/azalea-brigadier/src/modifier.rs +++ b/azalea-brigadier/src/modifier.rs @@ -4,6 +4,9 @@ use crate::{ context::CommandContext, exceptions::command_syntax_exception::CommandSyntaxException, }; -pub trait RedirectModifier { - fn apply(&self, context: &CommandContext) -> Result>, CommandSyntaxException>; -} +// pub trait RedirectModifier { +// fn apply(&self, context: &CommandContext) -> Result, CommandSyntaxException>; +// } + +pub type RedirectModifier = + dyn Fn(&CommandContext) -> Result>, CommandSyntaxException>; diff --git a/azalea-brigadier/src/parse_results.rs b/azalea-brigadier/src/parse_results.rs index fb862dec..e5db0400 100644 --- a/azalea-brigadier/src/parse_results.rs +++ b/azalea-brigadier/src/parse_results.rs @@ -4,13 +4,13 @@ use crate::{ }; use std::{any::Any, collections::HashMap, fmt::Debug, rc::Rc}; -pub struct ParseResults { +pub struct ParseResults { pub context: CommandContextBuilder, pub reader: StringReader, pub exceptions: HashMap>, CommandSyntaxException>, } -impl Debug for ParseResults { +impl Debug for ParseResults { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { f.debug_struct("ParseResults") .field("context", &self.context) diff --git a/azalea-brigadier/src/parsers.rs b/azalea-brigadier/src/parsers.rs index 77e57ace..1984b52f 100644 --- a/azalea-brigadier/src/parsers.rs +++ b/azalea-brigadier/src/parsers.rs @@ -49,7 +49,7 @@ impl Parser for Integer { pub fn integer() -> impl Parser { Integer::default() } -pub fn get_integer(context: &CommandContext, name: &str) -> Option { +pub fn get_integer(context: &CommandContext, name: &str) -> Option { context .argument(name) .unwrap() diff --git a/azalea-brigadier/src/tree.rs b/azalea-brigadier/src/tree.rs index b68fbdcf..cf480eaa 100644 --- a/azalea-brigadier/src/tree.rs +++ b/azalea-brigadier/src/tree.rs @@ -14,9 +14,8 @@ use crate::{ use std::{any::Any, cell::RefCell, collections::BTreeMap, fmt::Debug, hash::Hash, ptr, rc::Rc}; /// An ArgumentBuilder that has been built. -#[derive(Clone)] #[non_exhaustive] -pub struct CommandNode { +pub struct CommandNode { pub value: ArgumentBuilderType, // we use BTreeMap instead of HashMap because it can be hashed @@ -28,10 +27,41 @@ pub struct CommandNode { pub requirement: Rc) -> bool>, pub redirect: Option>>>, pub forks: bool, - pub modifier: Option>>, + pub modifier: Option>>, } -impl CommandNode { +impl Clone for CommandNode { + fn clone(&self) -> Self { + Self { + value: self.value.clone(), + children: self.children.clone(), + literals: self.literals.clone(), + arguments: self.arguments.clone(), + command: self.command.clone(), + requirement: self.requirement.clone(), + redirect: self.redirect.clone(), + forks: self.forks.clone(), + modifier: self.modifier.clone(), + } + } +} + +#[derive(Debug)] +pub struct ParsedCommandNode { + pub node: Rc>>, + pub range: StringRange, +} + +impl Clone for ParsedCommandNode { + fn clone(&self) -> Self { + Self { + node: self.node.clone(), + range: self.range.clone(), + } + } +} + +impl CommandNode { /// Gets the literal, or panics. You should use match if you're not certain about the type. pub fn literal(&self) -> &Literal { match self.value { @@ -126,7 +156,7 @@ impl CommandNode { }; context_builder.with_argument(&argument.name, parsed.clone()); - context_builder.with_node(Rc::new(self.clone()), parsed.range); + context_builder.with_node(Rc::new(RefCell::new(self.clone())), parsed.range); Ok(()) } @@ -135,8 +165,10 @@ impl CommandNode { let end = self.parse(reader); if let Some(end) = end { - context_builder - .with_node(Rc::new(self.clone()), StringRange::between(start, end)); + context_builder.with_node( + Rc::new(RefCell::new(self.clone())), + StringRange::between(start, end), + ); return Ok(()); } @@ -177,7 +209,7 @@ impl CommandNode { } } -impl Debug for CommandNode { +impl Debug for CommandNode { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { f.debug_struct("CommandNode") .field("value", &self.value) @@ -191,7 +223,7 @@ impl Debug for CommandNode { } } -impl Default for CommandNode { +impl Default for CommandNode { fn default() -> Self { Self { value: ArgumentBuilderType::Literal(Literal::default()), @@ -209,7 +241,7 @@ impl Default for CommandNode { } } -impl Hash for CommandNode { +impl Hash for CommandNode { fn hash(&self, state: &mut H) { // hash the children for (k, v) in &self.children { @@ -221,7 +253,7 @@ impl Hash for CommandNode { } } -impl PartialEq for CommandNode { +impl PartialEq for CommandNode { fn eq(&self, other: &Self) -> bool { if self.children != other.children { return false; @@ -242,4 +274,4 @@ impl PartialEq for CommandNode { true } } -impl Eq for CommandNode {} +impl Eq for CommandNode {} -- cgit v1.2.3 From 1d28c7cfb5260b7c7905fb5561ffcc7ceead1b77 Mon Sep 17 00:00:00 2001 From: mat Date: Sun, 17 Apr 2022 21:38:57 -0500 Subject: forking stuff --- azalea-brigadier/src/builder/argument_builder.rs | 4 +++- azalea-brigadier/src/context.rs | 19 +++++++++++++++++-- azalea-brigadier/src/dispatcher.rs | 13 ++++++++----- azalea-brigadier/src/modifier.rs | 6 +----- azalea-brigadier/src/parse_results.rs | 2 +- 5 files changed, 30 insertions(+), 14 deletions(-) (limited to 'azalea-brigadier/src/modifier.rs') diff --git a/azalea-brigadier/src/builder/argument_builder.rs b/azalea-brigadier/src/builder/argument_builder.rs index 39edfbd3..038b68a2 100644 --- a/azalea-brigadier/src/builder/argument_builder.rs +++ b/azalea-brigadier/src/builder/argument_builder.rs @@ -111,7 +111,9 @@ impl ArgumentBuilder { redirect: self.target, modifier: self.modifier, forks: self.forks, - ..Default::default() + arguments: Default::default(), + children: Default::default(), + literals: Default::default(), }; for (_, argument) in &self.arguments.children { diff --git a/azalea-brigadier/src/context.rs b/azalea-brigadier/src/context.rs index b798397b..4c36a32c 100644 --- a/azalea-brigadier/src/context.rs +++ b/azalea-brigadier/src/context.rs @@ -53,8 +53,6 @@ impl CommandContextBuilder { command: None, dispatcher, nodes: vec![], - // rootNode, - // start, child: None, modifier: None, forks: false, @@ -157,6 +155,23 @@ impl Clone for CommandContext { } } +impl Debug for CommandContext { + fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { + f.debug_struct("CommandContext") + // .field("source", &self.source) + .field("input", &self.input) + // .field("arguments", &self.arguments) + // .field("command", &self.command) + // .field("root_node", &self.root_node) + // .field("nodes", &self.nodes) + .field("range", &self.range) + .field("child", &self.child) + // .field("modifier", &self.modifier) + .field("forks", &self.forks) + .finish() + } +} + impl CommandContext { pub fn copy_for(&self, source: Rc) -> Self { if Rc::ptr_eq(&source, &self.source) { diff --git a/azalea-brigadier/src/dispatcher.rs b/azalea-brigadier/src/dispatcher.rs index 6031452e..3abb2238 100644 --- a/azalea-brigadier/src/dispatcher.rs +++ b/azalea-brigadier/src/dispatcher.rs @@ -190,6 +190,7 @@ impl CommandDispatcher { for context in contexts.iter() { let child = &context.child; if let Some(child) = child { + println!("aaaaaaa {:?}", child); forked |= child.forks; if child.has_nodes() { found_command = true; @@ -235,6 +236,7 @@ impl CommandDispatcher { ); } + println!("forked: {}, successful forks: {}", forked, successful_forks); Ok(if forked { successful_forks } else { result }) } } @@ -248,7 +250,6 @@ impl Clone for CommandDispatcher { } } -/* #[cfg(test)] mod tests { use super::*; @@ -258,6 +259,7 @@ mod tests { parsers::integer, }; + #[derive(Debug, PartialEq)] struct CommandSource {} fn input_with_offset(input: &str, offset: usize) -> StringReader { @@ -775,13 +777,13 @@ mod tests { let source1 = Rc::new(CommandSource {}); let source2 = Rc::new(CommandSource {}); - let modifier = move |source: &CommandContext>| -> Result>, CommandSyntaxException> { + let modifier = move |source: &CommandContext| -> Result>, CommandSyntaxException> { Ok(vec![source1.clone(), source2.clone()]) }; let concrete_node = subject.register(literal("actual").executes(|_| 42)); let redirect_node = - subject.register(literal("redirected").fork(subject.root.clone(), modifier)); + subject.register(literal("redirected").fork(subject.root.clone(), Rc::new(modifier))); let input = "redirected actual"; let parse = subject.parse(input.into(), Rc::new(CommandSource {})); @@ -799,7 +801,8 @@ mod tests { assert_eq!(parse.context.root, subject.root); assert_eq!(parent.nodes[0].range, parent.range); assert_eq!(parent.nodes[0].node, concrete_node); - // assert_eq!(parent.source, Rc::new(CommandSource {})); + assert_eq!(parent.source, Rc::new(CommandSource {})); + + assert_eq!(CommandDispatcher::execute_parsed(parse).unwrap(), 2); } } -*/ diff --git a/azalea-brigadier/src/modifier.rs b/azalea-brigadier/src/modifier.rs index c1a9aaf0..68a3304e 100644 --- a/azalea-brigadier/src/modifier.rs +++ b/azalea-brigadier/src/modifier.rs @@ -1,12 +1,8 @@ -use std::{any::Any, rc::Rc}; +use std::rc::Rc; use crate::{ context::CommandContext, exceptions::command_syntax_exception::CommandSyntaxException, }; -// pub trait RedirectModifier { -// fn apply(&self, context: &CommandContext) -> Result, CommandSyntaxException>; -// } - pub type RedirectModifier = dyn Fn(&CommandContext) -> Result>, CommandSyntaxException>; diff --git a/azalea-brigadier/src/parse_results.rs b/azalea-brigadier/src/parse_results.rs index e5db0400..c9f26a04 100644 --- a/azalea-brigadier/src/parse_results.rs +++ b/azalea-brigadier/src/parse_results.rs @@ -2,7 +2,7 @@ use crate::{ context::CommandContextBuilder, exceptions::command_syntax_exception::CommandSyntaxException, string_reader::StringReader, tree::CommandNode, }; -use std::{any::Any, collections::HashMap, fmt::Debug, rc::Rc}; +use std::{collections::HashMap, fmt::Debug, rc::Rc}; pub struct ParseResults { pub context: CommandContextBuilder, -- cgit v1.2.3 From b3864af9c4af83552e37fd71a46262967572f9e6 Mon Sep 17 00:00:00 2001 From: mat Date: Mon, 18 Apr 2022 18:13:15 +0000 Subject: split stuff into more modules --- .../src/builder/required_argument_builder.rs | 5 +- azalea-brigadier/src/context.rs | 202 ------ azalea-brigadier/src/dispatcher.rs | 713 --------------------- azalea-brigadier/src/exceptions/mod.rs | 7 +- azalea-brigadier/src/lib.rs | 5 +- azalea-brigadier/src/modifier.rs | 4 +- azalea-brigadier/src/parse_results.rs | 2 +- azalea-brigadier/src/parsers.rs | 4 +- azalea-brigadier/src/string_range.rs | 45 -- azalea-brigadier/src/string_reader.rs | 4 +- 10 files changed, 12 insertions(+), 979 deletions(-) delete mode 100644 azalea-brigadier/src/context.rs delete mode 100644 azalea-brigadier/src/dispatcher.rs delete mode 100644 azalea-brigadier/src/string_range.rs (limited to 'azalea-brigadier/src/modifier.rs') diff --git a/azalea-brigadier/src/builder/required_argument_builder.rs b/azalea-brigadier/src/builder/required_argument_builder.rs index cae0cddb..a50f7ea9 100644 --- a/azalea-brigadier/src/builder/required_argument_builder.rs +++ b/azalea-brigadier/src/builder/required_argument_builder.rs @@ -1,8 +1,5 @@ use super::argument_builder::{ArgumentBuilder, ArgumentBuilderType}; -use crate::{ - exceptions::command_syntax_exception::CommandSyntaxException, parsers::Parser, - string_reader::StringReader, -}; +use crate::{exceptions::CommandSyntaxException, parsers::Parser, string_reader::StringReader}; use std::{any::Any, fmt::Debug, rc::Rc}; /// An argument node type. The `T` type parameter is the type of the argument, diff --git a/azalea-brigadier/src/context.rs b/azalea-brigadier/src/context.rs deleted file mode 100644 index d71b3925..00000000 --- a/azalea-brigadier/src/context.rs +++ /dev/null @@ -1,202 +0,0 @@ -use std::{any::Any, cell::RefCell, collections::HashMap, fmt::Debug, rc::Rc}; - -use crate::{ - dispatcher::CommandDispatcher, - modifier::RedirectModifier, - string_range::StringRange, - tree::{CommandNode, ParsedCommandNode}, -}; - -pub struct CommandContextBuilder { - pub arguments: HashMap, - pub root: Rc>>, - pub nodes: Vec>, - pub dispatcher: Rc>, - pub source: Rc, - pub command: Option) -> i32>>, - pub child: Option>>, - pub range: StringRange, - pub modifier: Option>>, - pub forks: bool, -} - -impl Clone for CommandContextBuilder { - fn clone(&self) -> Self { - Self { - arguments: self.arguments.clone(), - root: self.root.clone(), - nodes: self.nodes.clone(), - dispatcher: self.dispatcher.clone(), - source: self.source.clone(), - command: self.command.clone(), - child: self.child.clone(), - range: self.range.clone(), - modifier: self.modifier.clone(), - forks: self.forks, - } - } -} - -impl CommandContextBuilder { - // CommandDispatcher dispatcher, final S source, final CommandNode rootNode, final int start - pub fn new( - dispatcher: Rc>, - source: Rc, - root_node: Rc>>, - start: usize, - ) -> Self { - Self { - arguments: HashMap::new(), - root: root_node, - source, - range: StringRange::at(start), - command: None, - dispatcher, - nodes: vec![], - child: None, - modifier: None, - forks: false, - } - } - - pub fn with_command( - &mut self, - command: &Option) -> i32>>, - ) -> &Self { - self.command = command.clone(); - self - } - pub fn with_child(&mut self, child: Rc>) -> &Self { - self.child = Some(child); - self - } - pub fn with_argument(&mut self, name: &str, argument: ParsedArgument) -> &Self { - self.arguments.insert(name.to_string(), argument); - self - } - pub fn with_node(&mut self, node: Rc>>, range: StringRange) -> &Self { - self.nodes.push(ParsedCommandNode { - node: node.clone(), - range: range.clone(), - }); - self.range = StringRange::encompassing(&self.range, &range); - self.modifier = node.borrow().modifier.clone(); - self.forks = node.borrow().forks; - self - } - - pub fn build(&self, input: &str) -> CommandContext { - CommandContext { - arguments: self.arguments.clone(), - root_node: self.root.clone(), - nodes: self.nodes.clone(), - source: self.source.clone(), - command: self.command.clone(), - child: self.child.clone().map(|c| Rc::new(c.build(input))), - range: self.range.clone(), - forks: self.forks, - modifier: self.modifier.clone(), - input: input.to_string(), - } - } -} - -impl Debug for CommandContextBuilder { - fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { - f.debug_struct("CommandContextBuilder") - // .field("arguments", &self.arguments) - .field("root", &self.root) - // .field("nodes", &self.nodes) - // .field("dispatcher", &self.dispatcher) - // .field("source", &self.source) - // .field("command", &self.command) - .field("child", &self.child) - .field("range", &self.range) - // .field("modifier", &self.modifier) - .field("forks", &self.forks) - .finish() - } -} - -#[derive(Clone)] -pub struct ParsedArgument { - pub range: StringRange, - pub result: Rc, -} - -/// A built `CommandContextBuilder`. -pub struct CommandContext { - pub source: Rc, - pub input: String, - pub arguments: HashMap, - pub command: Option) -> i32>>, - pub root_node: Rc>>, - pub nodes: Vec>, - pub range: StringRange, - pub child: Option>>, - pub modifier: Option>>, - pub forks: bool, -} - -impl Clone for CommandContext { - fn clone(&self) -> Self { - Self { - source: self.source.clone(), - input: self.input.clone(), - arguments: self.arguments.clone(), - command: self.command.clone(), - root_node: self.root_node.clone(), - nodes: self.nodes.clone(), - range: self.range.clone(), - child: self.child.clone(), - modifier: self.modifier.clone(), - forks: self.forks, - } - } -} - -impl Debug for CommandContext { - fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { - f.debug_struct("CommandContext") - // .field("source", &self.source) - .field("input", &self.input) - // .field("arguments", &self.arguments) - // .field("command", &self.command) - // .field("root_node", &self.root_node) - // .field("nodes", &self.nodes) - .field("range", &self.range) - .field("child", &self.child) - // .field("modifier", &self.modifier) - .field("forks", &self.forks) - .finish() - } -} - -impl CommandContext { - pub fn copy_for(&self, source: Rc) -> Self { - if Rc::ptr_eq(&source, &self.source) { - return self.clone(); - } - CommandContext { - source, - input: self.input.clone(), - arguments: self.arguments.clone(), - command: self.command.clone(), - root_node: self.root_node.clone(), - nodes: self.nodes.clone(), - range: self.range.clone(), - child: self.child.clone(), - modifier: self.modifier.clone(), - forks: self.forks, - } - } - - pub fn has_nodes(&self) -> bool { - !self.nodes.is_empty() - } - - pub fn argument(&self, name: &str) -> Option> { - let argument = self.arguments.get(name); - argument.map(|a| a.result.clone()) - } -} diff --git a/azalea-brigadier/src/dispatcher.rs b/azalea-brigadier/src/dispatcher.rs deleted file mode 100644 index ce89b81d..00000000 --- a/azalea-brigadier/src/dispatcher.rs +++ /dev/null @@ -1,713 +0,0 @@ -use crate::{ - builder::argument_builder::ArgumentBuilder, - context::{CommandContext, CommandContextBuilder}, - exceptions::{ - builtin_exceptions::BuiltInExceptions, command_syntax_exception::CommandSyntaxException, - }, - parse_results::ParseResults, - string_reader::StringReader, - tree::CommandNode, -}; -use std::{cell::RefCell, cmp::Ordering, collections::HashMap, marker::PhantomData, mem, rc::Rc}; - -#[derive(Default)] -pub struct CommandDispatcher { - root: Rc>>, - _marker: PhantomData, -} - -impl CommandDispatcher { - pub fn new() -> Self { - Self { - root: Rc::new(RefCell::new(CommandNode::default())), - _marker: PhantomData, - } - } - - pub fn register(&mut self, node: ArgumentBuilder) -> Rc>> { - let build = Rc::new(RefCell::new(node.build())); - self.root.borrow_mut().add_child(&build); - build - } - - pub fn parse(&self, command: StringReader, source: Rc) -> ParseResults { - let context = CommandContextBuilder::new( - Rc::new(self.clone()), - source, - self.root.clone(), - command.cursor(), - ); - self.parse_nodes(&self.root, &command, context).unwrap() - } - - fn parse_nodes( - &self, - node: &Rc>>, - original_reader: &StringReader, - context_so_far: CommandContextBuilder, - ) -> Result, CommandSyntaxException> { - let source = context_so_far.source.clone(); - let mut errors = HashMap::>, CommandSyntaxException>::new(); - let mut potentials: Vec> = vec![]; - let cursor = original_reader.cursor(); - - for child in node - .borrow() - .get_relevant_nodes(&mut original_reader.clone()) - { - if !child.borrow().can_use(source.clone()) { - continue; - } - let mut context = context_so_far.clone(); - let mut reader = original_reader.clone(); - - let parse_with_context_result = - child.borrow().parse_with_context(&mut reader, &mut context); - if let Err(ex) = parse_with_context_result { - errors.insert( - Rc::new((*child.borrow()).clone()), - BuiltInExceptions::DispatcherParseException { - message: ex.message(), - } - .create_with_context(&reader), - ); - reader.cursor = cursor; - continue; - } - if reader.can_read() && reader.peek() != ' ' { - errors.insert( - Rc::new((*child.borrow()).clone()), - BuiltInExceptions::DispatcherExpectedArgumentSeparator - .create_with_context(&reader), - ); - reader.cursor = cursor; - continue; - } - - context.with_command(&child.borrow().command); - if reader.can_read_length(if child.borrow().redirect.is_none() { - 2 - } else { - 1 - }) { - reader.skip(); - if let Some(redirect) = &child.borrow().redirect { - let child_context = CommandContextBuilder::new( - Rc::new(self.clone()), - source, - redirect.clone(), - reader.cursor, - ); - let parse = self - .parse_nodes(redirect, &reader, child_context) - .expect("Parsing nodes failed"); - context.with_child(Rc::new(parse.context)); - return Ok(ParseResults { - context, - reader: parse.reader, - exceptions: parse.exceptions, - }); - } else { - let parse = self - .parse_nodes(&child, &reader, context) - .expect("Parsing nodes failed"); - potentials.push(parse); - } - } else { - potentials.push(ParseResults { - context, - reader, - exceptions: HashMap::new(), - }); - } - } - - if !potentials.is_empty() { - if potentials.len() > 1 { - potentials.sort_by(|a, b| { - if !a.reader.can_read() && b.reader.can_read() { - return Ordering::Less; - }; - if a.reader.can_read() && !b.reader.can_read() { - return Ordering::Greater; - }; - if a.exceptions.is_empty() && !b.exceptions.is_empty() { - return Ordering::Less; - }; - if !a.exceptions.is_empty() && b.exceptions.is_empty() { - return Ordering::Greater; - }; - Ordering::Equal - }) - } - let best_potential = potentials.into_iter().next().unwrap(); - return Ok(best_potential); - } - - Ok(ParseResults { - context: context_so_far, - reader: original_reader.clone(), - exceptions: errors, - }) - } - - pub fn execute( - &self, - input: StringReader, - source: Rc, - ) -> Result { - let parse = self.parse(input, source); - Self::execute_parsed(parse) - } - - pub fn add_paths( - &self, - node: Rc>>, - result: &mut Vec>>>>, - parents: Vec>>>, - ) { - let mut current = parents; - current.push(node.clone()); - result.push(current.clone()); - - for child in node.borrow().children.values() { - self.add_paths(child.clone(), result, current.clone()); - } - } - - pub fn get_path(&self, target: CommandNode) -> Vec { - let rc_target = Rc::new(RefCell::new(target)); - let mut nodes: Vec>>>> = Vec::new(); - self.add_paths(self.root.clone(), &mut nodes, vec![]); - - for list in nodes { - if *list.last().expect("Nothing in list").borrow() == *rc_target.borrow() { - let mut result: Vec = Vec::with_capacity(list.len()); - for node in list { - if node != self.root { - result.push(node.borrow().name().to_string()); - } - } - return result; - } - } - vec![] - } - - pub fn find_node(&self, path: &[&str]) -> Option>>> { - let mut node = self.root.clone(); - for name in path { - if let Some(child) = node.clone().borrow().child(name) { - node = child - } else { - return None; - } - } - Some(node) - } - - /// Executes a given pre-parsed command. - pub fn execute_parsed(parse: ParseResults) -> Result { - if parse.reader.can_read() { - if parse.exceptions.len() == 1 { - return Err(parse.exceptions.values().next().unwrap().clone()); - } - if parse.context.range.is_empty() { - return Err( - BuiltInExceptions::DispatcherUnknownCommand.create_with_context(&parse.reader) - ); - } - return Err( - BuiltInExceptions::DispatcherUnknownArgument.create_with_context(&parse.reader) - ); - } - let mut result = 0i32; - let mut successful_forks = 0; - let mut forked = false; - let mut found_command = false; - let command = parse.reader.string(); - let original = parse.context.build(command); - let mut contexts = vec![original]; - let mut next: Vec> = vec![]; - - while !contexts.is_empty() { - for context in contexts.iter() { - let child = &context.child; - if let Some(child) = child { - println!("aaaaaaa {:?}", child); - forked |= child.forks; - if child.has_nodes() { - found_command = true; - let modifier = &context.modifier; - if let Some(modifier) = modifier { - let results = modifier(context); - if let Ok(results) = results { - if !results.is_empty() { - next.extend(results.iter().map(|s| child.copy_for(s.clone()))); - } - } else { - // TODO - // self.consumer.on_command_complete(context, false, 0); - if !forked { - return Err(results.err().unwrap()); - } - } - } else { - next.push(child.copy_for(context.source.clone())); - } - } - } else if let Some(context_command) = &context.command { - found_command = true; - - let value = context_command(context); - result += value; - // consumer.on_command_complete(context, true, value); - successful_forks += 1; - - // TODO: allow context_command to error and handle those errors - } - } - - // move next into contexts and clear next - mem::swap(&mut contexts, &mut next); - next.clear(); - } - - if !found_command { - // consumer.on_command_complete(original, false, 0); - return Err( - BuiltInExceptions::DispatcherUnknownCommand.create_with_context(&parse.reader) - ); - } - - // TODO: this is not how vanilla does it but it works - Ok(if successful_forks >= 2 { - successful_forks - } else { - result - }) - // Ok(if forked { successful_forks } else { result }) - } -} - -impl Clone for CommandDispatcher { - fn clone(&self) -> Self { - Self { - root: self.root.clone(), - _marker: PhantomData, - } - } -} - -#[cfg(test)] -mod tests { - use super::*; - use crate::{ - builder::{literal_argument_builder::literal, required_argument_builder::argument}, - parsers::integer, - }; - - #[derive(Debug, PartialEq)] - struct CommandSource {} - - fn input_with_offset(input: &str, offset: usize) -> StringReader { - let mut result: StringReader = input.into(); - result.cursor = offset; - result - } - - #[test] - fn create_and_execute_command() { - let mut subject = CommandDispatcher::new(); - subject.register(literal("foo").executes(|_| 42)); - - assert_eq!( - subject - .execute("foo".into(), Rc::new(CommandSource {})) - .unwrap(), - 42 - ); - } - - #[test] - fn create_and_execute_offset_command() { - let mut subject = CommandDispatcher::new(); - subject.register(literal("foo").executes(|_| 42)); - - assert_eq!( - subject - .execute(input_with_offset("/foo", 1), Rc::new(CommandSource {})) - .unwrap(), - 42 - ); - } - - #[test] - fn create_and_merge_commands() { - let mut subject = CommandDispatcher::new(); - subject.register(literal("base").then(literal("foo").executes(|_| 42))); - subject.register(literal("base").then(literal("bar").executes(|_| 42))); - - assert_eq!( - subject - .execute("base foo".into(), Rc::new(CommandSource {})) - .unwrap(), - 42 - ); - assert_eq!( - subject - .execute("base bar".into(), Rc::new(CommandSource {})) - .unwrap(), - 42 - ); - } - - #[test] - fn execute_unknown_command() { - let mut subject = CommandDispatcher::new(); - subject.register(literal("bar")); - subject.register(literal("baz")); - - let execute_result = subject.execute("foo".into(), Rc::new(CommandSource {})); - - let err = execute_result.err().unwrap(); - match err.type_ { - BuiltInExceptions::DispatcherUnknownCommand => {} - _ => panic!("Unexpected error"), - } - assert_eq!(err.cursor().unwrap(), 0); - } - - #[test] - fn execute_impermissible_command() { - let mut subject = CommandDispatcher::new(); - subject.register(literal("foo").requires(|_| false)); - - let execute_result = subject.execute("foo".into(), Rc::new(CommandSource {})); - - let err = execute_result.err().unwrap(); - match err.type_ { - BuiltInExceptions::DispatcherUnknownCommand => {} - _ => panic!("Unexpected error"), - } - assert_eq!(err.cursor().unwrap(), 0); - } - - #[test] - fn execute_empty_command() { - let mut subject = CommandDispatcher::new(); - subject.register(literal("")); - - let execute_result = subject.execute("".into(), Rc::new(CommandSource {})); - - let err = execute_result.err().unwrap(); - match err.type_ { - BuiltInExceptions::DispatcherUnknownCommand => {} - _ => panic!("Unexpected error"), - } - assert_eq!(err.cursor().unwrap(), 0); - } - - #[test] - fn execute_unknown_subcommand() { - let mut subject = CommandDispatcher::new(); - subject.register(literal("foo").executes(|_| 42)); - - let execute_result = subject.execute("foo bar".into(), Rc::new(CommandSource {})); - - let err = execute_result.err().unwrap(); - match err.type_ { - BuiltInExceptions::DispatcherUnknownArgument => {} - _ => panic!("Unexpected error"), - } - assert_eq!(err.cursor().unwrap(), 4); - } - - #[test] - fn execute_incorrect_literal() { - let mut subject = CommandDispatcher::new(); - subject.register(literal("foo").executes(|_| 42).then(literal("bar"))); - - let execute_result = subject.execute("foo baz".into(), Rc::new(CommandSource {})); - - let err = execute_result.err().unwrap(); - match err.type_ { - BuiltInExceptions::DispatcherUnknownArgument => {} - _ => panic!("Unexpected error"), - } - assert_eq!(err.cursor().unwrap(), 4); - } - - #[test] - fn execute_ambiguous_incorrect_argument() { - let mut subject = CommandDispatcher::new(); - subject.register( - literal("foo") - .executes(|_| 42) - .then(literal("bar")) - .then(literal("baz")), - ); - - let execute_result = subject.execute("foo unknown".into(), Rc::new(CommandSource {})); - - let err = execute_result.err().unwrap(); - match err.type_ { - BuiltInExceptions::DispatcherUnknownArgument => {} - _ => panic!("Unexpected error"), - } - assert_eq!(err.cursor().unwrap(), 4); - } - - #[test] - fn execute_subcommand() { - let mut subject = CommandDispatcher::new(); - - subject.register( - literal("foo") - .then(literal("a")) - .then(literal("=").executes(|_| 100)) - .then(literal("c")) - .executes(|_| 42), - ); - - assert_eq!( - subject - .execute("foo =".into(), Rc::new(CommandSource {})) - .unwrap(), - 100 - ); - } - - #[test] - fn parse_incomplete_literal() { - let mut subject = CommandDispatcher::new(); - subject.register(literal("foo").then(literal("bar").executes(|_| 42))); - - let parse = subject.parse("foo ".into(), Rc::new(CommandSource {})); - assert_eq!(parse.reader.remaining(), " "); - assert_eq!(parse.context.nodes.len(), 1); - } - - #[test] - fn parse_incomplete_argument() { - let mut subject = CommandDispatcher::new(); - subject.register(literal("foo").then(argument("bar", integer()).executes(|_| 42))); - - let parse = subject.parse("foo ".into(), Rc::new(CommandSource {})); - assert_eq!(parse.reader.remaining(), " "); - assert_eq!(parse.context.nodes.len(), 1); - } - - #[test] - fn execute_ambiguious_parent_subcommand() { - let mut subject = CommandDispatcher::new(); - - subject.register( - literal("test") - .then(argument("incorrect", integer()).executes(|_| 42)) - .then( - argument("right", integer()).then(argument("sub", integer()).executes(|_| 100)), - ), - ); - - assert_eq!( - subject - .execute("test 1 2".into(), Rc::new(CommandSource {})) - .unwrap(), - 100 - ); - } - - #[test] - fn execute_ambiguious_parent_subcommand_via_redirect() { - let mut subject = CommandDispatcher::new(); - - let real = subject.register( - literal("test") - .then(argument("incorrect", integer()).executes(|_| 42)) - .then( - argument("right", integer()).then(argument("sub", integer()).executes(|_| 100)), - ), - ); - - subject.register(literal("redirect").redirect(real)); - - assert_eq!( - subject - .execute("redirect 1 2".into(), Rc::new(CommandSource {})) - .unwrap(), - 100 - ); - } - - #[test] - fn execute_redirected_multiple_times() { - let mut subject = CommandDispatcher::new(); - - let concrete_node = subject.register(literal("actual").executes(|_| 42)); - let root = subject.root.clone(); - let redirect_node = subject.register(literal("redirected").redirect(root.clone())); - - let input = "redirected redirected actual"; - - let parse = subject.parse(input.into(), Rc::new(CommandSource {})); - assert_eq!(parse.context.range.get(input), "redirected"); - assert_eq!(parse.context.nodes.len(), 1); - assert_eq!(parse.context.root, root); - assert_eq!(parse.context.nodes[0].range, parse.context.range); - assert_eq!(parse.context.nodes[0].node, redirect_node); - - let child1 = parse.context.child.clone(); - assert!(child1.is_some()); - assert_eq!(child1.clone().unwrap().range.get(input), "redirected"); - assert_eq!(child1.clone().unwrap().nodes.len(), 1); - assert_eq!(child1.clone().unwrap().root, root); - assert_eq!( - child1.clone().unwrap().nodes[0].range, - child1.clone().unwrap().range - ); - assert_eq!(child1.clone().unwrap().nodes[0].node, redirect_node); - - let child2 = child1.unwrap().child.clone(); - assert!(child2.is_some()); - assert_eq!(child2.clone().unwrap().range.get(input), "actual"); - assert_eq!(child2.clone().unwrap().nodes.len(), 1); - assert_eq!(child2.clone().unwrap().root, root); - assert_eq!( - child2.clone().unwrap().nodes[0].range, - child2.clone().unwrap().range - ); - assert_eq!(child2.clone().unwrap().nodes[0].node, concrete_node); - - assert_eq!(CommandDispatcher::execute_parsed(parse).unwrap(), 42); - } - - #[test] - fn execute_redirected() { - let mut subject = CommandDispatcher::new(); - - let source1 = Rc::new(CommandSource {}); - let source2 = Rc::new(CommandSource {}); - - let modifier = move |_: &CommandContext| -> Result>, CommandSyntaxException> { - Ok(vec![source1.clone(), source2.clone()]) - }; - - let concrete_node = subject.register(literal("actual").executes(|_| 42)); - let redirect_node = - subject.register(literal("redirected").fork(subject.root.clone(), Rc::new(modifier))); - - let input = "redirected actual"; - let parse = subject.parse(input.into(), Rc::new(CommandSource {})); - assert_eq!(parse.context.range.get(input), "redirected"); - assert_eq!(parse.context.nodes.len(), 1); - assert_eq!(parse.context.root, subject.root); - assert_eq!(parse.context.nodes[0].range, parse.context.range); - assert_eq!(parse.context.nodes[0].node, redirect_node); - - let parent = parse.context.child.clone(); - assert!(parent.is_some()); - let parent = parent.unwrap(); - assert_eq!(parent.range.get(input), "actual"); - assert_eq!(parent.nodes.len(), 1); - assert_eq!(parse.context.root, subject.root); - assert_eq!(parent.nodes[0].range, parent.range); - assert_eq!(parent.nodes[0].node, concrete_node); - assert_eq!(parent.source, Rc::new(CommandSource {})); - - assert_eq!(CommandDispatcher::execute_parsed(parse).unwrap(), 2); - } - - #[test] - fn execute_orphaned_subcommand() { - let mut subject = CommandDispatcher::new(); - - subject.register( - literal("foo") - .then(argument("bar", integer())) - .executes(|_| 42), - ); - - let result = subject.execute("foo 5".into(), Rc::new(CommandSource {})); - assert!(result.is_err()); - let result = result.unwrap_err(); - assert_eq!( - *result.get_type(), - BuiltInExceptions::DispatcherUnknownCommand - ); - assert_eq!(result.cursor(), Some(5)); - } - - #[test] - fn execute_invalid_other() { - let mut subject = CommandDispatcher::new(); - - subject.register(literal("w").executes(|_| panic!("This should not run"))); - subject.register(literal("world").executes(|_| 42)); - - assert_eq!( - subject - .execute("world".into(), Rc::new(CommandSource {})) - .unwrap(), - 42 - ); - } - - #[test] - fn parse_no_space_separator() { - let mut subject = CommandDispatcher::new(); - - subject.register( - literal("foo") - .then(argument("bar", integer())) - .executes(|_| 42), - ); - - let result = subject.execute("foo$".into(), Rc::new(CommandSource {})); - assert!(result.is_err()); - let result = result.unwrap_err(); - assert_eq!( - *result.get_type(), - BuiltInExceptions::DispatcherUnknownCommand - ); - assert_eq!(result.cursor(), Some(0)); - } - - #[test] - fn execute_invalid_subcommand() { - let mut subject = CommandDispatcher::new(); - - subject.register( - literal("foo") - .then(argument("bar", integer())) - .executes(|_| 42), - ); - - let result = subject.execute("foo bar".into(), Rc::new(CommandSource {})); - assert!(result.is_err()); - let result = result.unwrap_err(); - // this fails for some reason, i blame mojang - // assert_eq!(*result.get_type(), BuiltInExceptions::ReaderExpectedInt); - assert_eq!(result.cursor(), Some(4)); - } - - #[test] - fn get_path() { - let mut subject = CommandDispatcher::<()>::new(); - - let bar = literal("bar").build(); - subject.register(literal("foo").then_built(bar.clone())); - - assert_eq!( - subject.get_path(bar), - vec!["foo".to_string(), "bar".to_string()] - ); - } - - #[test] - fn find_node_doesnt_exist() { - let subject = CommandDispatcher::<()>::new(); - - assert_eq!(subject.find_node(&vec!["foo", "bar"]), None) - } -} diff --git a/azalea-brigadier/src/exceptions/mod.rs b/azalea-brigadier/src/exceptions/mod.rs index 0bca556e..6b9c8d62 100644 --- a/azalea-brigadier/src/exceptions/mod.rs +++ b/azalea-brigadier/src/exceptions/mod.rs @@ -1,2 +1,5 @@ -pub mod builtin_exceptions; -pub mod command_syntax_exception; +mod builtin_exceptions; +mod command_syntax_exception; + +pub use builtin_exceptions::BuiltInExceptions; +pub use command_syntax_exception::CommandSyntaxException; diff --git a/azalea-brigadier/src/lib.rs b/azalea-brigadier/src/lib.rs index e359e274..cffaac12 100644 --- a/azalea-brigadier/src/lib.rs +++ b/azalea-brigadier/src/lib.rs @@ -1,12 +1,11 @@ pub mod builder; +pub mod command_dispatcher; pub mod context; -pub mod dispatcher; pub mod exceptions; pub mod message; pub mod modifier; pub mod parse_results; pub mod parsers; -pub mod string_range; pub mod string_reader; pub mod tree; @@ -17,8 +16,8 @@ mod tests { use crate::{ builder::{literal_argument_builder::literal, required_argument_builder::argument}, + command_dispatcher::CommandDispatcher, context::CommandContext, - dispatcher::CommandDispatcher, parsers::{get_integer, integer}, }; diff --git a/azalea-brigadier/src/modifier.rs b/azalea-brigadier/src/modifier.rs index 68a3304e..d40d59f9 100644 --- a/azalea-brigadier/src/modifier.rs +++ b/azalea-brigadier/src/modifier.rs @@ -1,8 +1,6 @@ use std::rc::Rc; -use crate::{ - context::CommandContext, exceptions::command_syntax_exception::CommandSyntaxException, -}; +use crate::{context::CommandContext, exceptions::CommandSyntaxException}; pub type RedirectModifier = dyn Fn(&CommandContext) -> Result>, CommandSyntaxException>; diff --git a/azalea-brigadier/src/parse_results.rs b/azalea-brigadier/src/parse_results.rs index c9f26a04..3698ae82 100644 --- a/azalea-brigadier/src/parse_results.rs +++ b/azalea-brigadier/src/parse_results.rs @@ -1,5 +1,5 @@ use crate::{ - context::CommandContextBuilder, exceptions::command_syntax_exception::CommandSyntaxException, + context::CommandContextBuilder, exceptions::CommandSyntaxException, string_reader::StringReader, tree::CommandNode, }; use std::{collections::HashMap, fmt::Debug, rc::Rc}; diff --git a/azalea-brigadier/src/parsers.rs b/azalea-brigadier/src/parsers.rs index 1984b52f..18ee9119 100644 --- a/azalea-brigadier/src/parsers.rs +++ b/azalea-brigadier/src/parsers.rs @@ -2,9 +2,7 @@ use std::{any::Any, rc::Rc}; use crate::{ context::CommandContext, - exceptions::{ - builtin_exceptions::BuiltInExceptions, command_syntax_exception::CommandSyntaxException, - }, + exceptions::{BuiltInExceptions, CommandSyntaxException}, string_reader::StringReader, }; diff --git a/azalea-brigadier/src/string_range.rs b/azalea-brigadier/src/string_range.rs deleted file mode 100644 index 8ca88624..00000000 --- a/azalea-brigadier/src/string_range.rs +++ /dev/null @@ -1,45 +0,0 @@ -use std::cmp; - -#[derive(Debug, Clone, PartialEq, Eq, Hash, Default)] -pub struct StringRange { - start: usize, - end: usize, -} - -impl StringRange { - pub fn new(start: usize, end: usize) -> Self { - Self { start, end } - } - - pub fn at(pos: usize) -> Self { - Self::new(pos, pos) - } - - pub fn between(start: usize, end: usize) -> Self { - Self::new(start, end) - } - - pub fn encompassing(a: &Self, b: &Self) -> Self { - Self::new(cmp::min(a.start, b.start), cmp::max(a.end, b.end)) - } - - pub fn start(&self) -> usize { - self.start - } - - pub fn end(&self) -> usize { - self.end - } - - pub fn get<'a>(&self, reader: &'a str) -> &'a str { - &reader[self.start..self.end] - } - - pub fn is_empty(&self) -> bool { - self.start == self.end - } - - pub fn length(&self) -> usize { - self.end - self.start - } -} diff --git a/azalea-brigadier/src/string_reader.rs b/azalea-brigadier/src/string_reader.rs index f220267a..dcb35fcb 100644 --- a/azalea-brigadier/src/string_reader.rs +++ b/azalea-brigadier/src/string_reader.rs @@ -1,6 +1,4 @@ -use crate::exceptions::{ - builtin_exceptions::BuiltInExceptions, command_syntax_exception::CommandSyntaxException, -}; +use crate::exceptions::{BuiltInExceptions, CommandSyntaxException}; use std::str::FromStr; #[derive(Clone)] -- cgit v1.2.3 From 248f752748a0033db7f8242ee0ecd73ea8ce8ec9 Mon Sep 17 00:00:00 2001 From: mat Date: Fri, 22 Apr 2022 04:33:58 +0000 Subject: simplify error handling --- .gitignore | 0 .gitpod.yml | 0 .vscode/settings.json | 0 Cargo.lock | 0 Cargo.toml | 0 README.md | 0 azalea-auth/Cargo.toml | 0 azalea-auth/src/game_profile.rs | 0 azalea-auth/src/lib.rs | 0 azalea-brigadier/Cargo.toml | 0 azalea-brigadier/README.md | 0 azalea-brigadier/src/arguments/argument_type.rs | 0 .../src/arguments/integer_argument_type.rs | 0 azalea-brigadier/src/arguments/mod.rs | 0 azalea-brigadier/src/builder/argument_builder.rs | 0 .../src/builder/literal_argument_builder.rs | 0 azalea-brigadier/src/builder/mod.rs | 0 .../src/builder/required_argument_builder.rs | 0 azalea-brigadier/src/command_dispatcher.rs | 0 azalea-brigadier/src/context/command_context.rs | 0 .../src/context/command_context_builder.rs | 0 azalea-brigadier/src/context/mod.rs | 0 azalea-brigadier/src/context/parsed_argument.rs | 0 .../src/context/parsed_command_node.rs | 0 azalea-brigadier/src/context/string_range.rs | 0 .../src/exceptions/builtin_exceptions.rs | 0 .../src/exceptions/command_syntax_exception.rs | 0 azalea-brigadier/src/exceptions/mod.rs | 0 azalea-brigadier/src/lib.rs | 0 azalea-brigadier/src/message.rs | 0 azalea-brigadier/src/modifier.rs | 0 azalea-brigadier/src/parse_results.rs | 0 azalea-brigadier/src/string_reader.rs | 0 azalea-brigadier/src/tree/mod.rs | 0 .../tests/arguments/bool_argument_type_test.rs | 0 .../tests/arguments/double_argument_type_test.rs | 0 .../tests/arguments/float_argument_type_test.rs | 0 .../tests/arguments/integer_argument_type_test.rs | 0 .../tests/arguments/long_argument_type_test.rs | 0 .../tests/arguments/string_argument_type_test.rs | 0 .../tests/builder/argument_builder_test.rs | 0 .../tests/builder/literal_argument_builder_test.rs | 0 .../builder/required_argument_builder_test.rs | 0 azalea-brigadier/tests/command_dispatcher_test.rs | 0 .../tests/command_dispatcher_usages_test.rs | 0 azalea-brigadier/tests/command_suggestions_test.rs | 0 .../tests/context/command_context_test.rs | 0 .../tests/context/parsed_argument_test.rs | 0 .../dynamic_command_syntax_exception_type_test.rs | 0 .../simple_command_syntax_exception_type_test.rs | 0 azalea-brigadier/tests/string_reader_test.rs | 0 .../tests/suggestion/suggestion_test.rs | 0 .../tests/suggestion/suggestions_builder_test.rs | 0 .../tests/suggestion/suggestions_test.rs | 0 .../tests/tree/abstract_command_node_test.rs | 0 .../tests/tree/argument_command_node_test.rs | 0 .../tests/tree/literal_command_node_test.rs | 0 .../tests/tree/root_command_node_test.rs | 0 azalea-chat/Cargo.toml | 0 azalea-chat/README.md | 0 azalea-chat/src/base_component.rs | 0 azalea-chat/src/component.rs | 0 azalea-chat/src/events.rs | 0 azalea-chat/src/lib.rs | 0 azalea-chat/src/style.rs | 0 azalea-chat/src/text_component.rs | 0 azalea-chat/src/translatable_component.rs | 0 azalea-chat/tests/integration_test.rs | 0 azalea-client/Cargo.toml | 0 azalea-client/README.md | 0 azalea-client/src/connect.rs | 0 azalea-client/src/crypt.rs | 0 azalea-client/src/lib.rs | 0 azalea-client/src/ping.rs | 0 azalea-core/Cargo.toml | 0 azalea-core/src/difficulty.rs | 0 azalea-core/src/game_type.rs | 0 azalea-core/src/lib.rs | 0 azalea-core/src/resource_location.rs | 0 azalea-core/src/serializable_uuid.rs | 0 azalea-nbt/Cargo.toml | 0 azalea-nbt/README.md | 0 azalea-nbt/benches/my_benchmark.rs | 0 azalea-nbt/src/decode.rs | 34 ++++++++++----------- azalea-nbt/src/encode.rs | 0 azalea-nbt/src/error.rs | 11 +++++++ azalea-nbt/src/lib.rs | 0 azalea-nbt/src/tag.rs | 0 azalea-nbt/tests/bigtest.nbt | Bin azalea-nbt/tests/complex_player.dat | Bin azalea-nbt/tests/hello_world.nbt | Bin azalea-nbt/tests/inttest.nbt | Bin azalea-nbt/tests/level.dat | Bin azalea-nbt/tests/simple_player.dat | Bin azalea-nbt/tests/stringtest.nbt | Bin azalea-nbt/tests/tests.rs | 0 azalea-protocol/Cargo.toml | 0 azalea-protocol/README.md | 0 azalea-protocol/packet-macros/Cargo.toml | 0 azalea-protocol/packet-macros/src/lib.rs | 0 azalea-protocol/src/connect.rs | 0 azalea-protocol/src/lib.rs | 0 azalea-protocol/src/mc_buf/mod.rs | 0 azalea-protocol/src/mc_buf/read.rs | 0 azalea-protocol/src/mc_buf/write.rs | 0 .../game/clientbound_change_difficulty_packet.rs | 0 .../game/clientbound_custom_payload_packet.rs | 0 .../game/clientbound_declare_commands_packet.rs | 0 .../src/packets/game/clientbound_login_packet.rs | 0 .../game/clientbound_player_abilities_packet.rs | 0 .../game/clientbound_set_carried_item_packet.rs | 0 .../packets/game/clientbound_update_tags_packet.rs | 0 .../clientbound_update_view_distance_packet.rs | 0 azalea-protocol/src/packets/game/mod.rs | 0 .../packets/handshake/client_intention_packet.rs | 0 azalea-protocol/src/packets/handshake/mod.rs | 0 .../login/clientbound_custom_query_packet.rs | 0 .../login/clientbound_game_profile_packet.rs | 0 .../src/packets/login/clientbound_hello_packet.rs | 0 .../login/clientbound_login_compression_packet.rs | 0 azalea-protocol/src/packets/login/mod.rs | 0 .../src/packets/login/serverbound_hello_packet.rs | 0 azalea-protocol/src/packets/mod.rs | 0 .../status/clientbound_status_response_packet.rs | 0 azalea-protocol/src/packets/status/mod.rs | 0 .../status/serverbound_status_request_packet.rs | 0 azalea-protocol/src/read.rs | 0 azalea-protocol/src/resolver.rs | 0 azalea-protocol/src/write.rs | 0 bot/Cargo.toml | 0 bot/src/main.rs | 0 131 files changed, 28 insertions(+), 17 deletions(-) mode change 100644 => 100755 .gitignore mode change 100644 => 100755 .gitpod.yml mode change 100644 => 100755 .vscode/settings.json mode change 100644 => 100755 Cargo.lock mode change 100644 => 100755 Cargo.toml mode change 100644 => 100755 README.md mode change 100644 => 100755 azalea-auth/Cargo.toml mode change 100644 => 100755 azalea-auth/src/game_profile.rs mode change 100644 => 100755 azalea-auth/src/lib.rs mode change 100644 => 100755 azalea-brigadier/Cargo.toml mode change 100644 => 100755 azalea-brigadier/README.md mode change 100644 => 100755 azalea-brigadier/src/arguments/argument_type.rs mode change 100644 => 100755 azalea-brigadier/src/arguments/integer_argument_type.rs mode change 100644 => 100755 azalea-brigadier/src/arguments/mod.rs mode change 100644 => 100755 azalea-brigadier/src/builder/argument_builder.rs mode change 100644 => 100755 azalea-brigadier/src/builder/literal_argument_builder.rs mode change 100644 => 100755 azalea-brigadier/src/builder/mod.rs mode change 100644 => 100755 azalea-brigadier/src/builder/required_argument_builder.rs mode change 100644 => 100755 azalea-brigadier/src/command_dispatcher.rs mode change 100644 => 100755 azalea-brigadier/src/context/command_context.rs mode change 100644 => 100755 azalea-brigadier/src/context/command_context_builder.rs mode change 100644 => 100755 azalea-brigadier/src/context/mod.rs mode change 100644 => 100755 azalea-brigadier/src/context/parsed_argument.rs mode change 100644 => 100755 azalea-brigadier/src/context/parsed_command_node.rs mode change 100644 => 100755 azalea-brigadier/src/context/string_range.rs mode change 100644 => 100755 azalea-brigadier/src/exceptions/builtin_exceptions.rs mode change 100644 => 100755 azalea-brigadier/src/exceptions/command_syntax_exception.rs mode change 100644 => 100755 azalea-brigadier/src/exceptions/mod.rs mode change 100644 => 100755 azalea-brigadier/src/lib.rs mode change 100644 => 100755 azalea-brigadier/src/message.rs mode change 100644 => 100755 azalea-brigadier/src/modifier.rs mode change 100644 => 100755 azalea-brigadier/src/parse_results.rs mode change 100644 => 100755 azalea-brigadier/src/string_reader.rs mode change 100644 => 100755 azalea-brigadier/src/tree/mod.rs mode change 100644 => 100755 azalea-brigadier/tests/arguments/bool_argument_type_test.rs mode change 100644 => 100755 azalea-brigadier/tests/arguments/double_argument_type_test.rs mode change 100644 => 100755 azalea-brigadier/tests/arguments/float_argument_type_test.rs mode change 100644 => 100755 azalea-brigadier/tests/arguments/integer_argument_type_test.rs mode change 100644 => 100755 azalea-brigadier/tests/arguments/long_argument_type_test.rs mode change 100644 => 100755 azalea-brigadier/tests/arguments/string_argument_type_test.rs mode change 100644 => 100755 azalea-brigadier/tests/builder/argument_builder_test.rs mode change 100644 => 100755 azalea-brigadier/tests/builder/literal_argument_builder_test.rs mode change 100644 => 100755 azalea-brigadier/tests/builder/required_argument_builder_test.rs mode change 100644 => 100755 azalea-brigadier/tests/command_dispatcher_test.rs mode change 100644 => 100755 azalea-brigadier/tests/command_dispatcher_usages_test.rs mode change 100644 => 100755 azalea-brigadier/tests/command_suggestions_test.rs mode change 100644 => 100755 azalea-brigadier/tests/context/command_context_test.rs mode change 100644 => 100755 azalea-brigadier/tests/context/parsed_argument_test.rs mode change 100644 => 100755 azalea-brigadier/tests/exceptions/dynamic_command_syntax_exception_type_test.rs mode change 100644 => 100755 azalea-brigadier/tests/exceptions/simple_command_syntax_exception_type_test.rs mode change 100644 => 100755 azalea-brigadier/tests/string_reader_test.rs mode change 100644 => 100755 azalea-brigadier/tests/suggestion/suggestion_test.rs mode change 100644 => 100755 azalea-brigadier/tests/suggestion/suggestions_builder_test.rs mode change 100644 => 100755 azalea-brigadier/tests/suggestion/suggestions_test.rs mode change 100644 => 100755 azalea-brigadier/tests/tree/abstract_command_node_test.rs mode change 100644 => 100755 azalea-brigadier/tests/tree/argument_command_node_test.rs mode change 100644 => 100755 azalea-brigadier/tests/tree/literal_command_node_test.rs mode change 100644 => 100755 azalea-brigadier/tests/tree/root_command_node_test.rs mode change 100644 => 100755 azalea-chat/Cargo.toml mode change 100644 => 100755 azalea-chat/README.md mode change 100644 => 100755 azalea-chat/src/base_component.rs mode change 100644 => 100755 azalea-chat/src/component.rs mode change 100644 => 100755 azalea-chat/src/events.rs mode change 100644 => 100755 azalea-chat/src/lib.rs mode change 100644 => 100755 azalea-chat/src/style.rs mode change 100644 => 100755 azalea-chat/src/text_component.rs mode change 100644 => 100755 azalea-chat/src/translatable_component.rs mode change 100644 => 100755 azalea-chat/tests/integration_test.rs mode change 100644 => 100755 azalea-client/Cargo.toml mode change 100644 => 100755 azalea-client/README.md mode change 100644 => 100755 azalea-client/src/connect.rs mode change 100644 => 100755 azalea-client/src/crypt.rs mode change 100644 => 100755 azalea-client/src/lib.rs mode change 100644 => 100755 azalea-client/src/ping.rs mode change 100644 => 100755 azalea-core/Cargo.toml mode change 100644 => 100755 azalea-core/src/difficulty.rs mode change 100644 => 100755 azalea-core/src/game_type.rs mode change 100644 => 100755 azalea-core/src/lib.rs mode change 100644 => 100755 azalea-core/src/resource_location.rs mode change 100644 => 100755 azalea-core/src/serializable_uuid.rs mode change 100644 => 100755 azalea-nbt/Cargo.toml mode change 100644 => 100755 azalea-nbt/README.md mode change 100644 => 100755 azalea-nbt/benches/my_benchmark.rs mode change 100644 => 100755 azalea-nbt/src/decode.rs mode change 100644 => 100755 azalea-nbt/src/encode.rs mode change 100644 => 100755 azalea-nbt/src/error.rs mode change 100644 => 100755 azalea-nbt/src/lib.rs mode change 100644 => 100755 azalea-nbt/src/tag.rs mode change 100644 => 100755 azalea-nbt/tests/bigtest.nbt mode change 100644 => 100755 azalea-nbt/tests/complex_player.dat mode change 100644 => 100755 azalea-nbt/tests/hello_world.nbt mode change 100644 => 100755 azalea-nbt/tests/inttest.nbt mode change 100644 => 100755 azalea-nbt/tests/level.dat mode change 100644 => 100755 azalea-nbt/tests/simple_player.dat mode change 100644 => 100755 azalea-nbt/tests/stringtest.nbt mode change 100644 => 100755 azalea-nbt/tests/tests.rs mode change 100644 => 100755 azalea-protocol/Cargo.toml mode change 100644 => 100755 azalea-protocol/README.md mode change 100644 => 100755 azalea-protocol/packet-macros/Cargo.toml mode change 100644 => 100755 azalea-protocol/packet-macros/src/lib.rs mode change 100644 => 100755 azalea-protocol/src/connect.rs mode change 100644 => 100755 azalea-protocol/src/lib.rs mode change 100644 => 100755 azalea-protocol/src/mc_buf/mod.rs mode change 100644 => 100755 azalea-protocol/src/mc_buf/read.rs mode change 100644 => 100755 azalea-protocol/src/mc_buf/write.rs mode change 100644 => 100755 azalea-protocol/src/packets/game/clientbound_change_difficulty_packet.rs mode change 100644 => 100755 azalea-protocol/src/packets/game/clientbound_custom_payload_packet.rs mode change 100644 => 100755 azalea-protocol/src/packets/game/clientbound_declare_commands_packet.rs mode change 100644 => 100755 azalea-protocol/src/packets/game/clientbound_login_packet.rs mode change 100644 => 100755 azalea-protocol/src/packets/game/clientbound_player_abilities_packet.rs mode change 100644 => 100755 azalea-protocol/src/packets/game/clientbound_set_carried_item_packet.rs mode change 100644 => 100755 azalea-protocol/src/packets/game/clientbound_update_tags_packet.rs mode change 100644 => 100755 azalea-protocol/src/packets/game/clientbound_update_view_distance_packet.rs mode change 100644 => 100755 azalea-protocol/src/packets/game/mod.rs mode change 100644 => 100755 azalea-protocol/src/packets/handshake/client_intention_packet.rs mode change 100644 => 100755 azalea-protocol/src/packets/handshake/mod.rs mode change 100644 => 100755 azalea-protocol/src/packets/login/clientbound_custom_query_packet.rs mode change 100644 => 100755 azalea-protocol/src/packets/login/clientbound_game_profile_packet.rs mode change 100644 => 100755 azalea-protocol/src/packets/login/clientbound_hello_packet.rs mode change 100644 => 100755 azalea-protocol/src/packets/login/clientbound_login_compression_packet.rs mode change 100644 => 100755 azalea-protocol/src/packets/login/mod.rs mode change 100644 => 100755 azalea-protocol/src/packets/login/serverbound_hello_packet.rs mode change 100644 => 100755 azalea-protocol/src/packets/mod.rs mode change 100644 => 100755 azalea-protocol/src/packets/status/clientbound_status_response_packet.rs mode change 100644 => 100755 azalea-protocol/src/packets/status/mod.rs mode change 100644 => 100755 azalea-protocol/src/packets/status/serverbound_status_request_packet.rs mode change 100644 => 100755 azalea-protocol/src/read.rs mode change 100644 => 100755 azalea-protocol/src/resolver.rs mode change 100644 => 100755 azalea-protocol/src/write.rs mode change 100644 => 100755 bot/Cargo.toml mode change 100644 => 100755 bot/src/main.rs (limited to 'azalea-brigadier/src/modifier.rs') diff --git a/.gitignore b/.gitignore old mode 100644 new mode 100755 diff --git a/.gitpod.yml b/.gitpod.yml old mode 100644 new mode 100755 diff --git a/.vscode/settings.json b/.vscode/settings.json old mode 100644 new mode 100755 diff --git a/Cargo.lock b/Cargo.lock old mode 100644 new mode 100755 diff --git a/Cargo.toml b/Cargo.toml old mode 100644 new mode 100755 diff --git a/README.md b/README.md old mode 100644 new mode 100755 diff --git a/azalea-auth/Cargo.toml b/azalea-auth/Cargo.toml old mode 100644 new mode 100755 diff --git a/azalea-auth/src/game_profile.rs b/azalea-auth/src/game_profile.rs old mode 100644 new mode 100755 diff --git a/azalea-auth/src/lib.rs b/azalea-auth/src/lib.rs old mode 100644 new mode 100755 diff --git a/azalea-brigadier/Cargo.toml b/azalea-brigadier/Cargo.toml old mode 100644 new mode 100755 diff --git a/azalea-brigadier/README.md b/azalea-brigadier/README.md old mode 100644 new mode 100755 diff --git a/azalea-brigadier/src/arguments/argument_type.rs b/azalea-brigadier/src/arguments/argument_type.rs old mode 100644 new mode 100755 diff --git a/azalea-brigadier/src/arguments/integer_argument_type.rs b/azalea-brigadier/src/arguments/integer_argument_type.rs old mode 100644 new mode 100755 diff --git a/azalea-brigadier/src/arguments/mod.rs b/azalea-brigadier/src/arguments/mod.rs old mode 100644 new mode 100755 diff --git a/azalea-brigadier/src/builder/argument_builder.rs b/azalea-brigadier/src/builder/argument_builder.rs old mode 100644 new mode 100755 diff --git a/azalea-brigadier/src/builder/literal_argument_builder.rs b/azalea-brigadier/src/builder/literal_argument_builder.rs old mode 100644 new mode 100755 diff --git a/azalea-brigadier/src/builder/mod.rs b/azalea-brigadier/src/builder/mod.rs old mode 100644 new mode 100755 diff --git a/azalea-brigadier/src/builder/required_argument_builder.rs b/azalea-brigadier/src/builder/required_argument_builder.rs old mode 100644 new mode 100755 diff --git a/azalea-brigadier/src/command_dispatcher.rs b/azalea-brigadier/src/command_dispatcher.rs old mode 100644 new mode 100755 diff --git a/azalea-brigadier/src/context/command_context.rs b/azalea-brigadier/src/context/command_context.rs old mode 100644 new mode 100755 diff --git a/azalea-brigadier/src/context/command_context_builder.rs b/azalea-brigadier/src/context/command_context_builder.rs old mode 100644 new mode 100755 diff --git a/azalea-brigadier/src/context/mod.rs b/azalea-brigadier/src/context/mod.rs old mode 100644 new mode 100755 diff --git a/azalea-brigadier/src/context/parsed_argument.rs b/azalea-brigadier/src/context/parsed_argument.rs old mode 100644 new mode 100755 diff --git a/azalea-brigadier/src/context/parsed_command_node.rs b/azalea-brigadier/src/context/parsed_command_node.rs old mode 100644 new mode 100755 diff --git a/azalea-brigadier/src/context/string_range.rs b/azalea-brigadier/src/context/string_range.rs old mode 100644 new mode 100755 diff --git a/azalea-brigadier/src/exceptions/builtin_exceptions.rs b/azalea-brigadier/src/exceptions/builtin_exceptions.rs old mode 100644 new mode 100755 diff --git a/azalea-brigadier/src/exceptions/command_syntax_exception.rs b/azalea-brigadier/src/exceptions/command_syntax_exception.rs old mode 100644 new mode 100755 diff --git a/azalea-brigadier/src/exceptions/mod.rs b/azalea-brigadier/src/exceptions/mod.rs old mode 100644 new mode 100755 diff --git a/azalea-brigadier/src/lib.rs b/azalea-brigadier/src/lib.rs old mode 100644 new mode 100755 diff --git a/azalea-brigadier/src/message.rs b/azalea-brigadier/src/message.rs old mode 100644 new mode 100755 diff --git a/azalea-brigadier/src/modifier.rs b/azalea-brigadier/src/modifier.rs old mode 100644 new mode 100755 diff --git a/azalea-brigadier/src/parse_results.rs b/azalea-brigadier/src/parse_results.rs old mode 100644 new mode 100755 diff --git a/azalea-brigadier/src/string_reader.rs b/azalea-brigadier/src/string_reader.rs old mode 100644 new mode 100755 diff --git a/azalea-brigadier/src/tree/mod.rs b/azalea-brigadier/src/tree/mod.rs old mode 100644 new mode 100755 diff --git a/azalea-brigadier/tests/arguments/bool_argument_type_test.rs b/azalea-brigadier/tests/arguments/bool_argument_type_test.rs old mode 100644 new mode 100755 diff --git a/azalea-brigadier/tests/arguments/double_argument_type_test.rs b/azalea-brigadier/tests/arguments/double_argument_type_test.rs old mode 100644 new mode 100755 diff --git a/azalea-brigadier/tests/arguments/float_argument_type_test.rs b/azalea-brigadier/tests/arguments/float_argument_type_test.rs old mode 100644 new mode 100755 diff --git a/azalea-brigadier/tests/arguments/integer_argument_type_test.rs b/azalea-brigadier/tests/arguments/integer_argument_type_test.rs old mode 100644 new mode 100755 diff --git a/azalea-brigadier/tests/arguments/long_argument_type_test.rs b/azalea-brigadier/tests/arguments/long_argument_type_test.rs old mode 100644 new mode 100755 diff --git a/azalea-brigadier/tests/arguments/string_argument_type_test.rs b/azalea-brigadier/tests/arguments/string_argument_type_test.rs old mode 100644 new mode 100755 diff --git a/azalea-brigadier/tests/builder/argument_builder_test.rs b/azalea-brigadier/tests/builder/argument_builder_test.rs old mode 100644 new mode 100755 diff --git a/azalea-brigadier/tests/builder/literal_argument_builder_test.rs b/azalea-brigadier/tests/builder/literal_argument_builder_test.rs old mode 100644 new mode 100755 diff --git a/azalea-brigadier/tests/builder/required_argument_builder_test.rs b/azalea-brigadier/tests/builder/required_argument_builder_test.rs old mode 100644 new mode 100755 diff --git a/azalea-brigadier/tests/command_dispatcher_test.rs b/azalea-brigadier/tests/command_dispatcher_test.rs old mode 100644 new mode 100755 diff --git a/azalea-brigadier/tests/command_dispatcher_usages_test.rs b/azalea-brigadier/tests/command_dispatcher_usages_test.rs old mode 100644 new mode 100755 diff --git a/azalea-brigadier/tests/command_suggestions_test.rs b/azalea-brigadier/tests/command_suggestions_test.rs old mode 100644 new mode 100755 diff --git a/azalea-brigadier/tests/context/command_context_test.rs b/azalea-brigadier/tests/context/command_context_test.rs old mode 100644 new mode 100755 diff --git a/azalea-brigadier/tests/context/parsed_argument_test.rs b/azalea-brigadier/tests/context/parsed_argument_test.rs old mode 100644 new mode 100755 diff --git a/azalea-brigadier/tests/exceptions/dynamic_command_syntax_exception_type_test.rs b/azalea-brigadier/tests/exceptions/dynamic_command_syntax_exception_type_test.rs old mode 100644 new mode 100755 diff --git a/azalea-brigadier/tests/exceptions/simple_command_syntax_exception_type_test.rs b/azalea-brigadier/tests/exceptions/simple_command_syntax_exception_type_test.rs old mode 100644 new mode 100755 diff --git a/azalea-brigadier/tests/string_reader_test.rs b/azalea-brigadier/tests/string_reader_test.rs old mode 100644 new mode 100755 diff --git a/azalea-brigadier/tests/suggestion/suggestion_test.rs b/azalea-brigadier/tests/suggestion/suggestion_test.rs old mode 100644 new mode 100755 diff --git a/azalea-brigadier/tests/suggestion/suggestions_builder_test.rs b/azalea-brigadier/tests/suggestion/suggestions_builder_test.rs old mode 100644 new mode 100755 diff --git a/azalea-brigadier/tests/suggestion/suggestions_test.rs b/azalea-brigadier/tests/suggestion/suggestions_test.rs old mode 100644 new mode 100755 diff --git a/azalea-brigadier/tests/tree/abstract_command_node_test.rs b/azalea-brigadier/tests/tree/abstract_command_node_test.rs old mode 100644 new mode 100755 diff --git a/azalea-brigadier/tests/tree/argument_command_node_test.rs b/azalea-brigadier/tests/tree/argument_command_node_test.rs old mode 100644 new mode 100755 diff --git a/azalea-brigadier/tests/tree/literal_command_node_test.rs b/azalea-brigadier/tests/tree/literal_command_node_test.rs old mode 100644 new mode 100755 diff --git a/azalea-brigadier/tests/tree/root_command_node_test.rs b/azalea-brigadier/tests/tree/root_command_node_test.rs old mode 100644 new mode 100755 diff --git a/azalea-chat/Cargo.toml b/azalea-chat/Cargo.toml old mode 100644 new mode 100755 diff --git a/azalea-chat/README.md b/azalea-chat/README.md old mode 100644 new mode 100755 diff --git a/azalea-chat/src/base_component.rs b/azalea-chat/src/base_component.rs old mode 100644 new mode 100755 diff --git a/azalea-chat/src/component.rs b/azalea-chat/src/component.rs old mode 100644 new mode 100755 diff --git a/azalea-chat/src/events.rs b/azalea-chat/src/events.rs old mode 100644 new mode 100755 diff --git a/azalea-chat/src/lib.rs b/azalea-chat/src/lib.rs old mode 100644 new mode 100755 diff --git a/azalea-chat/src/style.rs b/azalea-chat/src/style.rs old mode 100644 new mode 100755 diff --git a/azalea-chat/src/text_component.rs b/azalea-chat/src/text_component.rs old mode 100644 new mode 100755 diff --git a/azalea-chat/src/translatable_component.rs b/azalea-chat/src/translatable_component.rs old mode 100644 new mode 100755 diff --git a/azalea-chat/tests/integration_test.rs b/azalea-chat/tests/integration_test.rs old mode 100644 new mode 100755 diff --git a/azalea-client/Cargo.toml b/azalea-client/Cargo.toml old mode 100644 new mode 100755 diff --git a/azalea-client/README.md b/azalea-client/README.md old mode 100644 new mode 100755 diff --git a/azalea-client/src/connect.rs b/azalea-client/src/connect.rs old mode 100644 new mode 100755 diff --git a/azalea-client/src/crypt.rs b/azalea-client/src/crypt.rs old mode 100644 new mode 100755 diff --git a/azalea-client/src/lib.rs b/azalea-client/src/lib.rs old mode 100644 new mode 100755 diff --git a/azalea-client/src/ping.rs b/azalea-client/src/ping.rs old mode 100644 new mode 100755 diff --git a/azalea-core/Cargo.toml b/azalea-core/Cargo.toml old mode 100644 new mode 100755 diff --git a/azalea-core/src/difficulty.rs b/azalea-core/src/difficulty.rs old mode 100644 new mode 100755 diff --git a/azalea-core/src/game_type.rs b/azalea-core/src/game_type.rs old mode 100644 new mode 100755 diff --git a/azalea-core/src/lib.rs b/azalea-core/src/lib.rs old mode 100644 new mode 100755 diff --git a/azalea-core/src/resource_location.rs b/azalea-core/src/resource_location.rs old mode 100644 new mode 100755 diff --git a/azalea-core/src/serializable_uuid.rs b/azalea-core/src/serializable_uuid.rs old mode 100644 new mode 100755 diff --git a/azalea-nbt/Cargo.toml b/azalea-nbt/Cargo.toml old mode 100644 new mode 100755 diff --git a/azalea-nbt/README.md b/azalea-nbt/README.md old mode 100644 new mode 100755 diff --git a/azalea-nbt/benches/my_benchmark.rs b/azalea-nbt/benches/my_benchmark.rs old mode 100644 new mode 100755 diff --git a/azalea-nbt/src/decode.rs b/azalea-nbt/src/decode.rs old mode 100644 new mode 100755 index 41689a46..e4968811 --- a/azalea-nbt/src/decode.rs +++ b/azalea-nbt/src/decode.rs @@ -11,13 +11,13 @@ async fn read_string(stream: &mut R) -> Result where R: AsyncRead + std::marker::Unpin, { - let length = stream.read_u16().await.map_err(|_| Error::InvalidTag)?; + let length = stream.read_u16().await?; let mut buf = Vec::with_capacity(length as usize); for _ in 0..length { - buf.push(stream.read_u8().await.map_err(|_| Error::InvalidTag)?); + buf.push(stream.read_u8().await?); } - String::from_utf8(buf).map_err(|_| Error::InvalidTag) + Ok(String::from_utf8(buf)?) } impl Tag { @@ -31,26 +31,26 @@ impl Tag { // a TAG_Compound, and is not named despite being in a TAG_Compound 0 => Tag::End, // A single signed byte - 1 => Tag::Byte(stream.read_i8().await.map_err(|_| Error::InvalidTag)?), + 1 => Tag::Byte(stream.read_i8().await?), // A single signed, big endian 16 bit integer - 2 => Tag::Short(stream.read_i16().await.map_err(|_| Error::InvalidTag)?), + 2 => Tag::Short(stream.read_i16().await?), // A single signed, big endian 32 bit integer - 3 => Tag::Int(stream.read_i32().await.map_err(|_| Error::InvalidTag)?), + 3 => Tag::Int(stream.read_i32().await?), // A single signed, big endian 64 bit integer - 4 => Tag::Long(stream.read_i64().await.map_err(|_| Error::InvalidTag)?), + 4 => Tag::Long(stream.read_i64().await?), // A single, big endian IEEE-754 single-precision floating point // number (NaN possible) - 5 => Tag::Float(stream.read_f32().await.map_err(|_| Error::InvalidTag)?), + 5 => Tag::Float(stream.read_f32().await?), // A single, big endian IEEE-754 double-precision floating point // number (NaN possible) - 6 => Tag::Double(stream.read_f64().await.map_err(|_| Error::InvalidTag)?), + 6 => Tag::Double(stream.read_f64().await?), // A length-prefixed array of signed bytes. The prefix is a signed // integer (thus 4 bytes) 7 => { - let length = stream.read_i32().await.map_err(|_| Error::InvalidTag)?; + let length = stream.read_i32().await?; let mut bytes = Vec::with_capacity(length as usize); for _ in 0..length { - bytes.push(stream.read_i8().await.map_err(|_| Error::InvalidTag)?); + bytes.push(stream.read_i8().await?); } Tag::ByteArray(bytes) } @@ -67,8 +67,8 @@ impl Tag { // another reference implementation by Mojang uses 1 instead; // parsers should accept any type if the length is <= 0). 9 => { - let type_id = stream.read_u8().await.map_err(|_| Error::InvalidTag)?; - let length = stream.read_i32().await.map_err(|_| Error::InvalidTag)?; + let type_id = stream.read_u8().await?; + let length = stream.read_i32().await?; let mut list = Vec::with_capacity(length as usize); for _ in 0..length { list.push(Tag::read_known(stream, type_id).await?); @@ -94,20 +94,20 @@ impl Tag { // signed integer (thus 4 bytes) and indicates the number of 4 byte // integers. 11 => { - let length = stream.read_i32().await.map_err(|_| Error::InvalidTag)?; + let length = stream.read_i32().await?; let mut ints = Vec::with_capacity(length as usize); for _ in 0..length { - ints.push(stream.read_i32().await.map_err(|_| Error::InvalidTag)?); + ints.push(stream.read_i32().await?); } Tag::IntArray(ints) } // A length-prefixed array of signed longs. The prefix is a signed // integer (thus 4 bytes) and indicates the number of 8 byte longs. 12 => { - let length = stream.read_i32().await.map_err(|_| Error::InvalidTag)?; + let length = stream.read_i32().await?; let mut longs = Vec::with_capacity(length as usize); for _ in 0..length { - longs.push(stream.read_i64().await.map_err(|_| Error::InvalidTag)?); + longs.push(stream.read_i64().await?); } Tag::LongArray(longs) } diff --git a/azalea-nbt/src/encode.rs b/azalea-nbt/src/encode.rs old mode 100644 new mode 100755 diff --git a/azalea-nbt/src/error.rs b/azalea-nbt/src/error.rs old mode 100644 new mode 100755 index 05ff15e0..278d2770 --- a/azalea-nbt/src/error.rs +++ b/azalea-nbt/src/error.rs @@ -14,3 +14,14 @@ impl std::fmt::Display for Error { } } } + +impl From for Error { + fn from(err: std::io::Error) -> Self { + Error::WriteError + } +} +impl From for Error { + fn from(err: std::string::FromUtf8Error) -> Self { + Error::WriteError + } +} \ No newline at end of file diff --git a/azalea-nbt/src/lib.rs b/azalea-nbt/src/lib.rs old mode 100644 new mode 100755 diff --git a/azalea-nbt/src/tag.rs b/azalea-nbt/src/tag.rs old mode 100644 new mode 100755 diff --git a/azalea-nbt/tests/bigtest.nbt b/azalea-nbt/tests/bigtest.nbt old mode 100644 new mode 100755 diff --git a/azalea-nbt/tests/complex_player.dat b/azalea-nbt/tests/complex_player.dat old mode 100644 new mode 100755 diff --git a/azalea-nbt/tests/hello_world.nbt b/azalea-nbt/tests/hello_world.nbt old mode 100644 new mode 100755 diff --git a/azalea-nbt/tests/inttest.nbt b/azalea-nbt/tests/inttest.nbt old mode 100644 new mode 100755 diff --git a/azalea-nbt/tests/level.dat b/azalea-nbt/tests/level.dat old mode 100644 new mode 100755 diff --git a/azalea-nbt/tests/simple_player.dat b/azalea-nbt/tests/simple_player.dat old mode 100644 new mode 100755 diff --git a/azalea-nbt/tests/stringtest.nbt b/azalea-nbt/tests/stringtest.nbt old mode 100644 new mode 100755 diff --git a/azalea-nbt/tests/tests.rs b/azalea-nbt/tests/tests.rs old mode 100644 new mode 100755 diff --git a/azalea-protocol/Cargo.toml b/azalea-protocol/Cargo.toml old mode 100644 new mode 100755 diff --git a/azalea-protocol/README.md b/azalea-protocol/README.md old mode 100644 new mode 100755 diff --git a/azalea-protocol/packet-macros/Cargo.toml b/azalea-protocol/packet-macros/Cargo.toml old mode 100644 new mode 100755 diff --git a/azalea-protocol/packet-macros/src/lib.rs b/azalea-protocol/packet-macros/src/lib.rs old mode 100644 new mode 100755 diff --git a/azalea-protocol/src/connect.rs b/azalea-protocol/src/connect.rs old mode 100644 new mode 100755 diff --git a/azalea-protocol/src/lib.rs b/azalea-protocol/src/lib.rs old mode 100644 new mode 100755 diff --git a/azalea-protocol/src/mc_buf/mod.rs b/azalea-protocol/src/mc_buf/mod.rs old mode 100644 new mode 100755 diff --git a/azalea-protocol/src/mc_buf/read.rs b/azalea-protocol/src/mc_buf/read.rs old mode 100644 new mode 100755 diff --git a/azalea-protocol/src/mc_buf/write.rs b/azalea-protocol/src/mc_buf/write.rs old mode 100644 new mode 100755 diff --git a/azalea-protocol/src/packets/game/clientbound_change_difficulty_packet.rs b/azalea-protocol/src/packets/game/clientbound_change_difficulty_packet.rs old mode 100644 new mode 100755 diff --git a/azalea-protocol/src/packets/game/clientbound_custom_payload_packet.rs b/azalea-protocol/src/packets/game/clientbound_custom_payload_packet.rs old mode 100644 new mode 100755 diff --git a/azalea-protocol/src/packets/game/clientbound_declare_commands_packet.rs b/azalea-protocol/src/packets/game/clientbound_declare_commands_packet.rs old mode 100644 new mode 100755 diff --git a/azalea-protocol/src/packets/game/clientbound_login_packet.rs b/azalea-protocol/src/packets/game/clientbound_login_packet.rs old mode 100644 new mode 100755 diff --git a/azalea-protocol/src/packets/game/clientbound_player_abilities_packet.rs b/azalea-protocol/src/packets/game/clientbound_player_abilities_packet.rs old mode 100644 new mode 100755 diff --git a/azalea-protocol/src/packets/game/clientbound_set_carried_item_packet.rs b/azalea-protocol/src/packets/game/clientbound_set_carried_item_packet.rs old mode 100644 new mode 100755 diff --git a/azalea-protocol/src/packets/game/clientbound_update_tags_packet.rs b/azalea-protocol/src/packets/game/clientbound_update_tags_packet.rs old mode 100644 new mode 100755 diff --git a/azalea-protocol/src/packets/game/clientbound_update_view_distance_packet.rs b/azalea-protocol/src/packets/game/clientbound_update_view_distance_packet.rs old mode 100644 new mode 100755 diff --git a/azalea-protocol/src/packets/game/mod.rs b/azalea-protocol/src/packets/game/mod.rs old mode 100644 new mode 100755 diff --git a/azalea-protocol/src/packets/handshake/client_intention_packet.rs b/azalea-protocol/src/packets/handshake/client_intention_packet.rs old mode 100644 new mode 100755 diff --git a/azalea-protocol/src/packets/handshake/mod.rs b/azalea-protocol/src/packets/handshake/mod.rs old mode 100644 new mode 100755 diff --git a/azalea-protocol/src/packets/login/clientbound_custom_query_packet.rs b/azalea-protocol/src/packets/login/clientbound_custom_query_packet.rs old mode 100644 new mode 100755 diff --git a/azalea-protocol/src/packets/login/clientbound_game_profile_packet.rs b/azalea-protocol/src/packets/login/clientbound_game_profile_packet.rs old mode 100644 new mode 100755 diff --git a/azalea-protocol/src/packets/login/clientbound_hello_packet.rs b/azalea-protocol/src/packets/login/clientbound_hello_packet.rs old mode 100644 new mode 100755 diff --git a/azalea-protocol/src/packets/login/clientbound_login_compression_packet.rs b/azalea-protocol/src/packets/login/clientbound_login_compression_packet.rs old mode 100644 new mode 100755 diff --git a/azalea-protocol/src/packets/login/mod.rs b/azalea-protocol/src/packets/login/mod.rs old mode 100644 new mode 100755 diff --git a/azalea-protocol/src/packets/login/serverbound_hello_packet.rs b/azalea-protocol/src/packets/login/serverbound_hello_packet.rs old mode 100644 new mode 100755 diff --git a/azalea-protocol/src/packets/mod.rs b/azalea-protocol/src/packets/mod.rs old mode 100644 new mode 100755 diff --git a/azalea-protocol/src/packets/status/clientbound_status_response_packet.rs b/azalea-protocol/src/packets/status/clientbound_status_response_packet.rs old mode 100644 new mode 100755 diff --git a/azalea-protocol/src/packets/status/mod.rs b/azalea-protocol/src/packets/status/mod.rs old mode 100644 new mode 100755 diff --git a/azalea-protocol/src/packets/status/serverbound_status_request_packet.rs b/azalea-protocol/src/packets/status/serverbound_status_request_packet.rs old mode 100644 new mode 100755 diff --git a/azalea-protocol/src/read.rs b/azalea-protocol/src/read.rs old mode 100644 new mode 100755 diff --git a/azalea-protocol/src/resolver.rs b/azalea-protocol/src/resolver.rs old mode 100644 new mode 100755 diff --git a/azalea-protocol/src/write.rs b/azalea-protocol/src/write.rs old mode 100644 new mode 100755 diff --git a/bot/Cargo.toml b/bot/Cargo.toml old mode 100644 new mode 100755 diff --git a/bot/src/main.rs b/bot/src/main.rs old mode 100644 new mode 100755 -- cgit v1.2.3