Source is no longer required to get an argument result
This commit is contained in:
parent
ce5eb700b8
commit
a7674e984d
7 changed files with 25 additions and 26 deletions
|
@ -39,7 +39,7 @@ public class CommandContext<S> {
|
||||||
throw new IllegalArgumentException("No such argument '" + name + "' exists on this command");
|
throw new IllegalArgumentException("No such argument '" + name + "' exists on this command");
|
||||||
}
|
}
|
||||||
|
|
||||||
final Object result = argument.getResult(source);
|
final Object result = argument.getResult();
|
||||||
if (Primitives.wrap(clazz).isAssignableFrom(result.getClass())) {
|
if (Primitives.wrap(clazz).isAssignableFrom(result.getClass())) {
|
||||||
return (V) result;
|
return (V) result;
|
||||||
} else {
|
} else {
|
||||||
|
|
|
@ -13,7 +13,7 @@ public class ParsedArgument<S, T> {
|
||||||
return raw;
|
return raw;
|
||||||
}
|
}
|
||||||
|
|
||||||
public T getResult(S source) {
|
public T getResult() {
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -33,21 +33,21 @@ public class BoolArgumentTypeTest {
|
||||||
@Test
|
@Test
|
||||||
public void parse_true() throws Exception {
|
public void parse_true() throws Exception {
|
||||||
ParsedArgument<Object, Boolean> parse = type.parse("true", context);
|
ParsedArgument<Object, Boolean> parse = type.parse("true", context);
|
||||||
assertThat(parse.getResult(source), is(true));
|
assertThat(parse.getResult(), is(true));
|
||||||
assertThat(parse.getRaw(), equalTo("true"));
|
assertThat(parse.getRaw(), equalTo("true"));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void parse_false() throws Exception {
|
public void parse_false() throws Exception {
|
||||||
ParsedArgument<Object, Boolean> parse = type.parse("false", context);
|
ParsedArgument<Object, Boolean> parse = type.parse("false", context);
|
||||||
assertThat(parse.getResult(source), is(false));
|
assertThat(parse.getResult(), is(false));
|
||||||
assertThat(parse.getRaw(), equalTo("false"));
|
assertThat(parse.getRaw(), equalTo("false"));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void parse_trailing() throws Exception {
|
public void parse_trailing() throws Exception {
|
||||||
ParsedArgument<Object, Boolean> parse = type.parse("false hello world", context);
|
ParsedArgument<Object, Boolean> parse = type.parse("false hello world", context);
|
||||||
assertThat(parse.getResult(source), is(false));
|
assertThat(parse.getResult(), is(false));
|
||||||
assertThat(parse.getRaw(), equalTo("false"));
|
assertThat(parse.getRaw(), equalTo("false"));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -37,7 +37,7 @@ public class CommandArgumentTypeTest {
|
||||||
when(dispatcher.parse("hello world", source)).thenReturn(command);
|
when(dispatcher.parse("hello world", source)).thenReturn(command);
|
||||||
final ParsedArgument<Object, ParseResults<Object>> argument = command().parse("hello world", new CommandContextBuilder<>(dispatcher, source));
|
final ParsedArgument<Object, ParseResults<Object>> argument = command().parse("hello world", new CommandContextBuilder<>(dispatcher, source));
|
||||||
assertThat(argument.getRaw(), equalTo("hello world"));
|
assertThat(argument.getRaw(), equalTo("hello world"));
|
||||||
assertThat(argument.getResult(source), is(command));
|
assertThat(argument.getResult(), is(command));
|
||||||
}
|
}
|
||||||
|
|
||||||
@SuppressWarnings("unchecked")
|
@SuppressWarnings("unchecked")
|
||||||
|
|
|
@ -43,7 +43,7 @@ public class IntegerArgumentTypeTest {
|
||||||
ParsedArgument<Object, Integer> result = type.parse("50", new CommandContextBuilder<>(dispatcher, source));
|
ParsedArgument<Object, Integer> result = type.parse("50", new CommandContextBuilder<>(dispatcher, source));
|
||||||
|
|
||||||
assertThat(result.getRaw(), is("50"));
|
assertThat(result.getRaw(), is("50"));
|
||||||
assertThat(result.getResult(source), is(50));
|
assertThat(result.getResult(), is(50));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
@ -51,7 +51,7 @@ public class IntegerArgumentTypeTest {
|
||||||
ParsedArgument<Object, Integer> result = integer(0, 100, "L").parse("50L", new CommandContextBuilder<>(dispatcher, source));
|
ParsedArgument<Object, Integer> result = integer(0, 100, "L").parse("50L", new CommandContextBuilder<>(dispatcher, source));
|
||||||
|
|
||||||
assertThat(result.getRaw(), is("50L"));
|
assertThat(result.getRaw(), is("50L"));
|
||||||
assertThat(result.getResult(source), is(50));
|
assertThat(result.getResult(), is(50));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
@ -147,7 +147,7 @@ public class IntegerArgumentTypeTest {
|
||||||
ParsedArgument<Object, Integer> result = type.parse("-100", new CommandContextBuilder<>(dispatcher, source));
|
ParsedArgument<Object, Integer> result = type.parse("-100", new CommandContextBuilder<>(dispatcher, source));
|
||||||
|
|
||||||
assertThat(result.getRaw(), is("-100"));
|
assertThat(result.getRaw(), is("-100"));
|
||||||
assertThat(result.getResult(source), is(-100));
|
assertThat(result.getResult(), is(-100));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
@ -166,7 +166,7 @@ public class IntegerArgumentTypeTest {
|
||||||
ParsedArgument<Object, Integer> result = type.parse("100", new CommandContextBuilder<>(dispatcher, source));
|
ParsedArgument<Object, Integer> result = type.parse("100", new CommandContextBuilder<>(dispatcher, source));
|
||||||
|
|
||||||
assertThat(result.getRaw(), is("100"));
|
assertThat(result.getRaw(), is("100"));
|
||||||
assertThat(result.getResult(source), is(100));
|
assertThat(result.getResult(), is(100));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
|
|
@ -44,7 +44,7 @@ public class StringArgumentTypeTest {
|
||||||
ParsedArgument<Object, String> result = type.parse("hello world", new CommandContextBuilder<>(dispatcher, source));
|
ParsedArgument<Object, String> result = type.parse("hello world", new CommandContextBuilder<>(dispatcher, source));
|
||||||
|
|
||||||
assertThat(result.getRaw(), is("hello"));
|
assertThat(result.getRaw(), is("hello"));
|
||||||
assertThat(result.getResult(source), is("hello"));
|
assertThat(result.getResult(), is("hello"));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
@ -53,7 +53,7 @@ public class StringArgumentTypeTest {
|
||||||
ParsedArgument<Object, String> result = type.parse("", new CommandContextBuilder<>(dispatcher, source));
|
ParsedArgument<Object, String> result = type.parse("", new CommandContextBuilder<>(dispatcher, source));
|
||||||
|
|
||||||
assertThat(result.getRaw(), is(""));
|
assertThat(result.getRaw(), is(""));
|
||||||
assertThat(result.getResult(source), is(""));
|
assertThat(result.getResult(), is(""));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
@ -62,7 +62,7 @@ public class StringArgumentTypeTest {
|
||||||
ParsedArgument<Object, String> result = type.parse("hello", new CommandContextBuilder<>(dispatcher, source));
|
ParsedArgument<Object, String> result = type.parse("hello", new CommandContextBuilder<>(dispatcher, source));
|
||||||
|
|
||||||
assertThat(result.getRaw(), is("hello"));
|
assertThat(result.getRaw(), is("hello"));
|
||||||
assertThat(result.getResult(source), is("hello"));
|
assertThat(result.getResult(), is("hello"));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
@ -71,7 +71,7 @@ public class StringArgumentTypeTest {
|
||||||
ParsedArgument<Object, String> result = type.parse("hello world", new CommandContextBuilder<>(dispatcher, source));
|
ParsedArgument<Object, String> result = type.parse("hello world", new CommandContextBuilder<>(dispatcher, source));
|
||||||
|
|
||||||
assertThat(result.getRaw(), is("hello"));
|
assertThat(result.getRaw(), is("hello"));
|
||||||
assertThat(result.getResult(source), is("hello"));
|
assertThat(result.getResult(), is("hello"));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
@ -80,7 +80,7 @@ public class StringArgumentTypeTest {
|
||||||
ParsedArgument<Object, String> result = type.parse("hello world", new CommandContextBuilder<>(dispatcher, source));
|
ParsedArgument<Object, String> result = type.parse("hello world", new CommandContextBuilder<>(dispatcher, source));
|
||||||
|
|
||||||
assertThat(result.getRaw(), is("hello world"));
|
assertThat(result.getRaw(), is("hello world"));
|
||||||
assertThat(result.getResult(source), is("hello world"));
|
assertThat(result.getResult(), is("hello world"));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
@ -89,7 +89,7 @@ public class StringArgumentTypeTest {
|
||||||
ParsedArgument<Object, String> result = type.parse("hello", new CommandContextBuilder<>(dispatcher, source));
|
ParsedArgument<Object, String> result = type.parse("hello", new CommandContextBuilder<>(dispatcher, source));
|
||||||
|
|
||||||
assertThat(result.getRaw(), is("hello"));
|
assertThat(result.getRaw(), is("hello"));
|
||||||
assertThat(result.getResult(source), is("hello"));
|
assertThat(result.getResult(), is("hello"));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
@ -98,7 +98,7 @@ public class StringArgumentTypeTest {
|
||||||
ParsedArgument<Object, String> result = type.parse("\"hello \\\" world\"", new CommandContextBuilder<>(dispatcher, source));
|
ParsedArgument<Object, String> result = type.parse("\"hello \\\" world\"", new CommandContextBuilder<>(dispatcher, source));
|
||||||
|
|
||||||
assertThat(result.getRaw(), is("\"hello"));
|
assertThat(result.getRaw(), is("\"hello"));
|
||||||
assertThat(result.getResult(source), is("\"hello"));
|
assertThat(result.getResult(), is("\"hello"));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
@ -107,7 +107,7 @@ public class StringArgumentTypeTest {
|
||||||
ParsedArgument<Object, String> result = type.parse("\"hello \\\" world\"", new CommandContextBuilder<>(dispatcher, source));
|
ParsedArgument<Object, String> result = type.parse("\"hello \\\" world\"", new CommandContextBuilder<>(dispatcher, source));
|
||||||
|
|
||||||
assertThat(result.getRaw(), is("\"hello \\\" world\""));
|
assertThat(result.getRaw(), is("\"hello \\\" world\""));
|
||||||
assertThat(result.getResult(source), is("hello \" world"));
|
assertThat(result.getResult(), is("hello \" world"));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
@ -116,7 +116,7 @@ public class StringArgumentTypeTest {
|
||||||
ParsedArgument<Object, String> result = type.parse("\"hello \\\" world\" with remaining", new CommandContextBuilder<>(dispatcher, source));
|
ParsedArgument<Object, String> result = type.parse("\"hello \\\" world\" with remaining", new CommandContextBuilder<>(dispatcher, source));
|
||||||
|
|
||||||
assertThat(result.getRaw(), is("\"hello \\\" world\""));
|
assertThat(result.getRaw(), is("\"hello \\\" world\""));
|
||||||
assertThat(result.getResult(source), is("hello \" world"));
|
assertThat(result.getResult(), is("hello \" world"));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
@ -125,7 +125,7 @@ public class StringArgumentTypeTest {
|
||||||
ParsedArgument<Object, String> result = type.parse("hello world", new CommandContextBuilder<>(dispatcher, source));
|
ParsedArgument<Object, String> result = type.parse("hello world", new CommandContextBuilder<>(dispatcher, source));
|
||||||
|
|
||||||
assertThat(result.getRaw(), is("hello"));
|
assertThat(result.getRaw(), is("hello"));
|
||||||
assertThat(result.getResult(source), is("hello"));
|
assertThat(result.getResult(), is("hello"));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
@ -146,7 +146,7 @@ public class StringArgumentTypeTest {
|
||||||
ParsedArgument<Object, String> result = type.parse("\"hello\" world", new CommandContextBuilder<>(dispatcher, source));
|
ParsedArgument<Object, String> result = type.parse("\"hello\" world", new CommandContextBuilder<>(dispatcher, source));
|
||||||
|
|
||||||
assertThat(result.getRaw(), is("\"hello\""));
|
assertThat(result.getRaw(), is("\"hello\""));
|
||||||
assertThat(result.getResult(source), is("hello"));
|
assertThat(result.getResult(), is("hello"));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
@ -167,7 +167,7 @@ public class StringArgumentTypeTest {
|
||||||
ParsedArgument<Object, String> result = type.parse("hello \"world\"", new CommandContextBuilder<>(dispatcher, source));
|
ParsedArgument<Object, String> result = type.parse("hello \"world\"", new CommandContextBuilder<>(dispatcher, source));
|
||||||
|
|
||||||
assertThat(result.getRaw(), is("hello"));
|
assertThat(result.getRaw(), is("hello"));
|
||||||
assertThat(result.getResult(source), is("hello"));
|
assertThat(result.getResult(), is("hello"));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
@ -200,7 +200,7 @@ public class StringArgumentTypeTest {
|
||||||
ParsedArgument<Object, String> result = type.parse("", new CommandContextBuilder<>(dispatcher, source));
|
ParsedArgument<Object, String> result = type.parse("", new CommandContextBuilder<>(dispatcher, source));
|
||||||
|
|
||||||
assertThat(result.getRaw(), is(""));
|
assertThat(result.getRaw(), is(""));
|
||||||
assertThat(result.getResult(source), is(""));
|
assertThat(result.getResult(), is(""));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
|
|
@ -7,7 +7,6 @@ import com.mojang.brigadier.Command;
|
||||||
import com.mojang.brigadier.CommandDispatcher;
|
import com.mojang.brigadier.CommandDispatcher;
|
||||||
import com.mojang.brigadier.arguments.ArgumentType;
|
import com.mojang.brigadier.arguments.ArgumentType;
|
||||||
import com.mojang.brigadier.arguments.IntegerArgumentType;
|
import com.mojang.brigadier.arguments.IntegerArgumentType;
|
||||||
import com.mojang.brigadier.arguments.StringArgumentType;
|
|
||||||
import com.mojang.brigadier.builder.RequiredArgumentBuilder;
|
import com.mojang.brigadier.builder.RequiredArgumentBuilder;
|
||||||
import com.mojang.brigadier.context.CommandContextBuilder;
|
import com.mojang.brigadier.context.CommandContextBuilder;
|
||||||
import com.mojang.brigadier.exceptions.CommandException;
|
import com.mojang.brigadier.exceptions.CommandException;
|
||||||
|
@ -47,7 +46,7 @@ public class ArgumentCommandNodeTest extends AbstractCommandNodeTest {
|
||||||
assertThat(node.parse("123 456", contextBuilder), is(" 456"));
|
assertThat(node.parse("123 456", contextBuilder), is(" 456"));
|
||||||
|
|
||||||
assertThat(contextBuilder.getArguments().containsKey("foo"), is(true));
|
assertThat(contextBuilder.getArguments().containsKey("foo"), is(true));
|
||||||
assertThat(contextBuilder.getArguments().get("foo").getResult(source), is(123));
|
assertThat(contextBuilder.getArguments().get("foo").getResult(), is(123));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
@ -55,7 +54,7 @@ public class ArgumentCommandNodeTest extends AbstractCommandNodeTest {
|
||||||
assertThat(node.parse("123", contextBuilder), is(""));
|
assertThat(node.parse("123", contextBuilder), is(""));
|
||||||
|
|
||||||
assertThat(contextBuilder.getArguments().containsKey("foo"), is(true));
|
assertThat(contextBuilder.getArguments().containsKey("foo"), is(true));
|
||||||
assertThat(contextBuilder.getArguments().get("foo").getResult(source), is(123));
|
assertThat(contextBuilder.getArguments().get("foo").getResult(), is(123));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
|
Loading…
Reference in a new issue