aboutsummaryrefslogtreecommitdiff
path: root/azalea-brigadier/src/context/command_context.rs
diff options
context:
space:
mode:
authormat <github@matdoes.dev>2022-04-17 14:02:13 -0500
committermat <github@matdoes.dev>2022-04-17 14:02:13 -0500
commita72a47ced76065caf739898954cd18edbc39174b (patch)
tree5526c7663f253bbd7c8318b9d98413f1f2074852 /azalea-brigadier/src/context/command_context.rs
parent4ff67d4917ce333232189e86aee09f2d82451fc6 (diff)
downloadazalea-drasl-a72a47ced76065caf739898954cd18edbc39174b.tar.xz
Rewrite brigadier
Diffstat (limited to 'azalea-brigadier/src/context/command_context.rs')
-rw-r--r--azalea-brigadier/src/context/command_context.rs93
1 files changed, 0 insertions, 93 deletions
diff --git a/azalea-brigadier/src/context/command_context.rs b/azalea-brigadier/src/context/command_context.rs
deleted file mode 100644
index 8db1487f..00000000
--- a/azalea-brigadier/src/context/command_context.rs
+++ /dev/null
@@ -1,93 +0,0 @@
-use super::{
- parsed_argument::ParsedArgument, parsed_command_node::ParsedCommandNode,
- string_range::StringRange,
-};
-use crate::{
- arguments::argument_type::ArgumentType, command::Command, redirect_modifier::RedirectModifier,
- tree::command_node::CommandNodeTrait,
-};
-use std::{any::Any, collections::HashMap};
-
-pub struct CommandContext<'a, S> {
- source: S,
- input: String,
- command: &'a dyn Command<S>,
- arguments: HashMap<String, ParsedArgument<Box<dyn Any>>>,
- root_node: &'a dyn CommandNodeTrait<S>,
- nodes: Vec<ParsedCommandNode<S>>,
- range: StringRange,
- child: Option<&'a CommandContext<'a, S>>,
- modifier: Option<&'a dyn RedirectModifier<S>>,
- forks: bool,
-}
-
-impl<S> CommandContext<'_, S>
-where
- S: PartialEq,
-{
- pub fn clone_for(&self, source: S) -> Self {
- if self.source == source {
- return *self;
- }
- Self {
- source,
- input: self.input.clone(),
- command: self.command.clone(),
- arguments: self.arguments.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,
- }
- }
-
- fn child(&self) -> &Option<CommandContext<S>> {
- &self.child
- }
-
- fn last_child(&self) -> &CommandContext<S> {
- let mut result = self;
- while result.child.is_some() {
- result = result.child.as_ref().unwrap();
- }
- result
- }
-
- fn command(&self) -> &dyn Command<S> {
- &self.command
- }
-
- fn source(&self) -> &S {
- &self.source
- }
-
- // public <V> V getArgument(final String name, final Class<V> clazz) {
- // final ParsedArgument<S, ?> argument = arguments.get(name);
-
- // if (argument == null) {
- // throw new IllegalArgumentException("No such argument '" + name + "' exists on this command");
- // }
-
- // final Object result = argument.getResult();
- // if (PRIMITIVE_TO_WRAPPER.getOrDefault(clazz, clazz).isAssignableFrom(result.getClass())) {
- // return (V) result;
- // } else {
- // throw new IllegalArgumentException("Argument '" + name + "' is defined as " + result.getClass().getSimpleName() + ", not " + clazz);
- // }
- // }
- fn get_argument<V>(&self, name: &str) -> Result<V, String> {
- let argument = self.arguments.get(name);
-
- if argument.is_none() {
- return Err(format!(
- "No such argument '{}' exists on this command",
- name
- ));
- }
-
- let result = argument.unwrap().result();
- Ok(result)
- }
-}