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