Made getArgument return the actual value, not a container object
This commit is contained in:
parent
8e3b29d22e
commit
bafe8e6b56
3 changed files with 6 additions and 6 deletions
|
@ -38,7 +38,7 @@ public class IntegerArgumentType implements CommandArgumentType<Integer> {
|
|||
}
|
||||
|
||||
public static int getInteger(CommandContext<?> context, String name) {
|
||||
return context.getArgument(name, int.class).getResult();
|
||||
return context.getArgument(name, int.class);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -34,7 +34,7 @@ public class CommandContext<S> {
|
|||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
public <V> ParsedArgument<V> getArgument(String name, Class<V> clazz) {
|
||||
public <V> V getArgument(String name, Class<V> clazz) {
|
||||
ParsedArgument<?> argument = arguments.get(name);
|
||||
|
||||
if (argument == null) {
|
||||
|
@ -42,7 +42,7 @@ public class CommandContext<S> {
|
|||
}
|
||||
|
||||
if (Primitives.wrap(clazz).isAssignableFrom(argument.getResult().getClass())) {
|
||||
return (ParsedArgument<V>) argument;
|
||||
return ((ParsedArgument<V>) argument).getResult();
|
||||
} else {
|
||||
throw new IllegalArgumentException("Argument '" + name + "' is defined as " + argument.getResult().getClass().getSimpleName() + ", not " + clazz);
|
||||
}
|
||||
|
|
|
@ -46,7 +46,7 @@ public class CommandContextTest {
|
|||
@Test
|
||||
public void testGetArgument() throws Exception {
|
||||
CommandContext<Object> context = builder.withArgument("foo", integer().parse("123")).build();
|
||||
assertThat(context.getArgument("foo", int.class).getResult(), is(123));
|
||||
assertThat(context.getArgument("foo", int.class), is(123));
|
||||
}
|
||||
|
||||
@Test
|
||||
|
@ -88,11 +88,11 @@ public class CommandContextTest {
|
|||
|
||||
when(supplier.get()).thenReturn(first);
|
||||
CommandContext<Object> context = builder.withNode(literal("test").build(), "test").withArgument("test", new DynamicParsedArgument<>("test", supplier)).build();
|
||||
assertThat(context.getArgument("test", Object.class).getResult(), is(first));
|
||||
assertThat(context.getArgument("test", Object.class), is(first));
|
||||
|
||||
when(supplier.get()).thenReturn(second);
|
||||
CommandContext<Object> copy = context.copy();
|
||||
assertThat(context, is(equalTo(copy)));
|
||||
assertThat(copy.getArgument("test", Object.class).getResult(), is(second));
|
||||
assertThat(copy.getArgument("test", Object.class), is(second));
|
||||
}
|
||||
}
|
Loading…
Reference in a new issue