diff --git a/src/main/java/com/mojang/brigadier/arguments/StringArgumentType.java b/src/main/java/com/mojang/brigadier/arguments/StringArgumentType.java index 4f8095b..042bd48 100644 --- a/src/main/java/com/mojang/brigadier/arguments/StringArgumentType.java +++ b/src/main/java/com/mojang/brigadier/arguments/StringArgumentType.java @@ -9,8 +9,6 @@ import com.mojang.brigadier.exceptions.CommandException; import com.mojang.brigadier.exceptions.ParameterizedCommandExceptionType; import com.mojang.brigadier.exceptions.SimpleCommandExceptionType; -import java.util.Set; - public class StringArgumentType implements ArgumentType { public static final ParameterizedCommandExceptionType ERROR_INVALID_ESCAPE = new ParameterizedCommandExceptionType("argument.string.escape.invalid", "Unknown or invalid escape sequence: ${input}", "input"); public static final SimpleCommandExceptionType ERROR_UNEXPECTED_ESCAPE = new SimpleCommandExceptionType("argument.string.escape.unexpected", "Unexpected escape sequence, please quote the whole argument"); @@ -24,7 +22,7 @@ public class StringArgumentType implements ArgumentType { } public static StringArgumentType word() { - return new StringArgumentType(StringType.SINGLE_WORLD); + return new StringArgumentType(StringType.SINGLE_WORD); } public static StringArgumentType string() { @@ -43,7 +41,7 @@ public class StringArgumentType implements ArgumentType { public ParsedArgument parse(String command, CommandContextBuilder contextBuilder) throws CommandException { if (type == StringType.GREEDY_PHRASE) { return new FixedParsedArgument<>(command, command); - } else if (type == StringType.SINGLE_WORLD) { + } else if (type == StringType.SINGLE_WORD) { int index = command.indexOf(CommandDispatcher.ARGUMENT_SEPARATOR); if (index > 0) { final String word = command.substring(0, index); @@ -123,8 +121,13 @@ public class StringArgumentType implements ArgumentType { return result.toString(); } + @Override + public String getUsageText() { + return "string"; + } + public enum StringType { - SINGLE_WORLD, + SINGLE_WORD, QUOTABLE_PHRASE, GREEDY_PHRASE, } diff --git a/src/test/java/com/mojang/brigadier/tree/ArgumentCommandNodeTest.java b/src/test/java/com/mojang/brigadier/tree/ArgumentCommandNodeTest.java index cc05979..be6d53f 100644 --- a/src/test/java/com/mojang/brigadier/tree/ArgumentCommandNodeTest.java +++ b/src/test/java/com/mojang/brigadier/tree/ArgumentCommandNodeTest.java @@ -5,6 +5,7 @@ import com.google.common.collect.Sets; import com.google.common.testing.EqualsTester; import com.mojang.brigadier.Command; import com.mojang.brigadier.CommandDispatcher; +import com.mojang.brigadier.arguments.ArgumentType; import com.mojang.brigadier.arguments.IntegerArgumentType; import com.mojang.brigadier.arguments.StringArgumentType; import com.mojang.brigadier.builder.RequiredArgumentBuilder; @@ -23,6 +24,7 @@ import static org.hamcrest.Matchers.is; import static org.junit.Assert.assertThat; import static org.junit.Assert.fail; import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.when; public class ArgumentCommandNodeTest extends AbstractCommandNodeTest { private ArgumentCommandNode node; @@ -80,7 +82,9 @@ public class ArgumentCommandNodeTest extends AbstractCommandNodeTest { @Test public void testUsage_empty() throws Exception { - ArgumentCommandNode node = argument("foo", StringArgumentType.word()).build(); + @SuppressWarnings("unchecked") ArgumentType type = mock(ArgumentType.class); + when(type.getUsageText()).thenReturn(null); + ArgumentCommandNode node = argument("foo", type).build(); assertThat(node.getUsageText(), is("")); }