aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authormat <github@matdoes.dev>2022-07-31 18:05:41 -0500
committermat <github@matdoes.dev>2022-07-31 18:05:41 -0500
commit69f97dbf02e5422ee796492a3633a4e8f3f09d2d (patch)
tree0727d5dd604e49135e2265690856c36ce28792e4
parent0cf8f82994db643e13ec90074bd1c2c92c6e67fb (diff)
downloadazalea-drasl-69f97dbf02e5422ee796492a3633a4e8f3f09d2d.tar.xz
clippo the sequel
-rw-r--r--azalea-block/block-macros/src/lib.rs4
-rwxr-xr-xazalea-brigadier/src/builder/argument_builder.rs8
-rwxr-xr-xazalea-brigadier/src/context/command_context.rs7
-rwxr-xr-xazalea-brigadier/src/context/command_context_builder.rs13
-rwxr-xr-xazalea-brigadier/src/exceptions/command_syntax_exception.rs12
-rwxr-xr-xazalea-brigadier/src/tree/mod.rs8
-rwxr-xr-xazalea-chat/src/style.rs2
-rwxr-xr-xazalea-chat/src/text_component.rs2
-rwxr-xr-xazalea-core/src/difficulty.rs2
-rw-r--r--azalea-core/src/position.rs2
10 files changed, 38 insertions, 22 deletions
diff --git a/azalea-block/block-macros/src/lib.rs b/azalea-block/block-macros/src/lib.rs
index 01ce556d..907fd241 100644
--- a/azalea-block/block-macros/src/lib.rs
+++ b/azalea-block/block-macros/src/lib.rs
@@ -3,6 +3,7 @@ mod utils;
use proc_macro::TokenStream;
use quote::quote;
use std::collections::HashMap;
+use std::fmt::Write;
use syn::{
self, braced,
parse::{Parse, ParseStream, Result},
@@ -273,7 +274,8 @@ pub fn make_block_states(input: TokenStream) -> TokenStream {
.unwrap_or_else(|| panic!("Property '{}' is bad", property.struct_name))
.clone();
if let Some(index) = index {
- property_name.push_str(&format!("_{}", &index.to_string()));
+ // property_name.push_str(&format!("_{}", &index.to_string()));
+ write!(property_name, "_{}", index).unwrap();
}
properties_with_name
.push(property.as_property_with_name_and_default(property_name.clone()));
diff --git a/azalea-brigadier/src/builder/argument_builder.rs b/azalea-brigadier/src/builder/argument_builder.rs
index d26b2a8a..38ccc98c 100755
--- a/azalea-brigadier/src/builder/argument_builder.rs
+++ b/azalea-brigadier/src/builder/argument_builder.rs
@@ -1,4 +1,8 @@
-use crate::{context::CommandContext, modifier::RedirectModifier, tree::CommandNode};
+use crate::{
+ context::CommandContext,
+ modifier::RedirectModifier,
+ tree::{Command, CommandNode},
+};
use super::{literal_argument_builder::Literal, required_argument_builder::Argument};
use std::{cell::RefCell, fmt::Debug, rc::Rc};
@@ -13,7 +17,7 @@ pub enum ArgumentBuilderType {
pub struct ArgumentBuilder<S> {
arguments: CommandNode<S>,
- command: Option<Rc<dyn Fn(&CommandContext<S>) -> i32>>,
+ command: Command<S>,
requirement: Rc<dyn Fn(Rc<S>) -> bool>,
target: Option<Rc<RefCell<CommandNode<S>>>>,
diff --git a/azalea-brigadier/src/context/command_context.rs b/azalea-brigadier/src/context/command_context.rs
index 1834a73d..98609a6e 100755
--- a/azalea-brigadier/src/context/command_context.rs
+++ b/azalea-brigadier/src/context/command_context.rs
@@ -1,5 +1,8 @@
use super::{parsed_command_node::ParsedCommandNode, string_range::StringRange, ParsedArgument};
-use crate::{modifier::RedirectModifier, tree::CommandNode};
+use crate::{
+ modifier::RedirectModifier,
+ tree::{Command, CommandNode},
+};
use std::{any::Any, cell::RefCell, collections::HashMap, fmt::Debug, rc::Rc};
/// A built `CommandContextBuilder`.
@@ -7,7 +10,7 @@ pub struct CommandContext<S> {
pub source: Rc<S>,
pub input: String,
pub arguments: HashMap<String, ParsedArgument>,
- pub command: Option<Rc<dyn Fn(&CommandContext<S>) -> i32>>,
+ pub command: Command<S>,
pub root_node: Rc<RefCell<CommandNode<S>>>,
pub nodes: Vec<ParsedCommandNode<S>>,
pub range: StringRange,
diff --git a/azalea-brigadier/src/context/command_context_builder.rs b/azalea-brigadier/src/context/command_context_builder.rs
index f192f6b7..7516ab9e 100755
--- a/azalea-brigadier/src/context/command_context_builder.rs
+++ b/azalea-brigadier/src/context/command_context_builder.rs
@@ -2,7 +2,11 @@ use super::{
command_context::CommandContext, parsed_command_node::ParsedCommandNode,
string_range::StringRange, ParsedArgument,
};
-use crate::{command_dispatcher::CommandDispatcher, modifier::RedirectModifier, tree::CommandNode};
+use crate::{
+ command_dispatcher::CommandDispatcher,
+ modifier::RedirectModifier,
+ tree::{Command, CommandNode},
+};
use std::{cell::RefCell, collections::HashMap, fmt::Debug, rc::Rc};
pub struct CommandContextBuilder<S> {
@@ -11,7 +15,7 @@ pub struct CommandContextBuilder<S> {
pub nodes: Vec<ParsedCommandNode<S>>,
pub dispatcher: Rc<CommandDispatcher<S>>,
pub source: Rc<S>,
- pub command: Option<Rc<dyn Fn(&CommandContext<S>) -> i32>>,
+ pub command: Command<S>,
pub child: Option<Rc<CommandContextBuilder<S>>>,
pub range: StringRange,
pub modifier: Option<Rc<RedirectModifier<S>>>,
@@ -56,10 +60,7 @@ impl<S> CommandContextBuilder<S> {
}
}
- pub fn with_command(
- &mut self,
- command: &Option<Rc<dyn Fn(&CommandContext<S>) -> i32>>,
- ) -> &Self {
+ pub fn with_command(&mut self, command: &Command<S>) -> &Self {
self.command = command.clone();
self
}
diff --git a/azalea-brigadier/src/exceptions/command_syntax_exception.rs b/azalea-brigadier/src/exceptions/command_syntax_exception.rs
index 4bfe9cda..14376a87 100755
--- a/azalea-brigadier/src/exceptions/command_syntax_exception.rs
+++ b/azalea-brigadier/src/exceptions/command_syntax_exception.rs
@@ -1,7 +1,9 @@
-use std::{cmp, fmt};
-
use super::builtin_exceptions::BuiltInExceptions;
use crate::message::Message;
+use std::{
+ cmp,
+ fmt::{self, Write},
+};
#[derive(Clone, PartialEq)]
pub struct CommandSyntaxException {
@@ -36,11 +38,13 @@ impl CommandSyntaxException {
let mut message = self.message.string();
let context = self.context();
if let Some(context) = context {
- message.push_str(&format!(
+ write!(
+ message,
" at position {}: {}",
self.cursor.unwrap_or(usize::MAX),
context
- ));
+ )
+ .unwrap();
}
message
}
diff --git a/azalea-brigadier/src/tree/mod.rs b/azalea-brigadier/src/tree/mod.rs
index b6181c73..ef2573b9 100755
--- a/azalea-brigadier/src/tree/mod.rs
+++ b/azalea-brigadier/src/tree/mod.rs
@@ -10,6 +10,8 @@ use crate::{
};
use std::{cell::RefCell, collections::HashMap, fmt::Debug, hash::Hash, ptr, rc::Rc};
+pub type Command<S> = Option<Rc<dyn Fn(&CommandContext<S>) -> i32>>;
+
/// An ArgumentBuilder that has been built.
#[non_exhaustive]
pub struct CommandNode<S> {
@@ -19,7 +21,7 @@ pub struct CommandNode<S> {
pub literals: HashMap<String, Rc<RefCell<CommandNode<S>>>>,
pub arguments: HashMap<String, Rc<RefCell<CommandNode<S>>>>,
- pub command: Option<Rc<dyn Fn(&CommandContext<S>) -> i32>>,
+ pub command: Command<S>,
pub requirement: Rc<dyn Fn(Rc<S>) -> bool>,
pub redirect: Option<Rc<RefCell<CommandNode<S>>>>,
pub forks: bool,
@@ -75,9 +77,9 @@ impl<S> CommandNode<S> {
input.cursor = cursor;
let literal = literals.get(&text);
if let Some(literal) = literal {
- return vec![literal.clone()];
+ vec![literal.clone()]
} else {
- return self.arguments.values().cloned().collect();
+ self.arguments.values().cloned().collect()
}
} else {
self.arguments.values().cloned().collect()
diff --git a/azalea-chat/src/style.rs b/azalea-chat/src/style.rs
index 4e3b24de..9fca6563 100755
--- a/azalea-chat/src/style.rs
+++ b/azalea-chat/src/style.rs
@@ -2,7 +2,7 @@ use std::{collections::HashMap, fmt};
use serde_json::Value;
-#[derive(Clone, PartialEq, Debug)]
+#[derive(Clone, PartialEq, Eq, Debug)]
pub struct TextColor {
pub value: u32,
pub name: Option<String>,
diff --git a/azalea-chat/src/text_component.rs b/azalea-chat/src/text_component.rs
index 6c43f8b7..a704f455 100755
--- a/azalea-chat/src/text_component.rs
+++ b/azalea-chat/src/text_component.rs
@@ -54,7 +54,7 @@ pub fn legacy_color_code_to_text_component(legacy_color_code: &str) -> TextCompo
final_component
}
-impl<'a> TextComponent {
+impl TextComponent {
pub fn new(text: String) -> Self {
// if it contains a LEGACY_FORMATTING_CODE_SYMBOL, format it
if text.contains(LEGACY_FORMATTING_CODE_SYMBOL) {
diff --git a/azalea-core/src/difficulty.rs b/azalea-core/src/difficulty.rs
index 718359f3..f2877f79 100755
--- a/azalea-core/src/difficulty.rs
+++ b/azalea-core/src/difficulty.rs
@@ -5,7 +5,7 @@ use std::{
use azalea_buf::{McBufReadable, McBufWritable};
-#[derive(Hash, Clone, Debug, PartialEq)]
+#[derive(Hash, Clone, Debug, PartialEq, Eq)]
pub enum Difficulty {
PEACEFUL = 0,
EASY = 1,
diff --git a/azalea-core/src/position.rs b/azalea-core/src/position.rs
index 64075aa7..adc5cafa 100644
--- a/azalea-core/src/position.rs
+++ b/azalea-core/src/position.rs
@@ -86,7 +86,7 @@ impl ChunkSectionPos {
}
}
/// The coordinates of a block inside a chunk.
-#[derive(Clone, Copy, Debug, Default, PartialEq)]
+#[derive(Clone, Copy, Debug, Default, PartialEq, Eq)]
pub struct ChunkBlockPos {
pub x: u8,
pub y: i32,