From e85f4a9f11139aede63cb3c945b8771e6fe5df12 Mon Sep 17 00:00:00 2001 From: Nathan Adams Date: Fri, 13 Oct 2017 09:34:45 +0200 Subject: [PATCH] Added optional boolean to get all command usage text --- .../java/com/mojang/brigadier/CommandDispatcher.java | 10 +++++----- .../mojang/brigadier/arguments/FloatArgumentType.java | 4 ++-- .../mojang/brigadier/CommandDispatcherUsagesTest.java | 4 ++-- 3 files changed, 9 insertions(+), 9 deletions(-) diff --git a/src/main/java/com/mojang/brigadier/CommandDispatcher.java b/src/main/java/com/mojang/brigadier/CommandDispatcher.java index 750f008..1f1c1c8 100644 --- a/src/main/java/com/mojang/brigadier/CommandDispatcher.java +++ b/src/main/java/com/mojang/brigadier/CommandDispatcher.java @@ -162,14 +162,14 @@ public class CommandDispatcher { return new ParseResults<>(rootContext, reader, errors); } - public String[] getAllUsage(final CommandNode node, final S source) { + public String[] getAllUsage(final CommandNode node, final S source, final boolean restricted) { final ArrayList result = Lists.newArrayList(); - getAllUsage(node, source, result, ""); + getAllUsage(node, source, result, "", restricted); return result.toArray(new String[result.size()]); } - private void getAllUsage(final CommandNode node, final S source, final ArrayList result, final String prefix) { - if (!node.canUse(source)) { + private void getAllUsage(final CommandNode node, final S source, final ArrayList result, final String prefix, final boolean restricted) { + if (restricted && !node.canUse(source)) { return; } @@ -182,7 +182,7 @@ public class CommandDispatcher { result.add(prefix.isEmpty() ? node.getUsageText() + ARGUMENT_SEPARATOR + redirect : prefix + ARGUMENT_SEPARATOR + redirect); } else if (!node.getChildren().isEmpty()) { for (final CommandNode child : node.getChildren()) { - getAllUsage(child, source, result, prefix.isEmpty() ? child.getUsageText() : prefix + ARGUMENT_SEPARATOR + child.getUsageText()); + getAllUsage(child, source, result, prefix.isEmpty() ? child.getUsageText() : prefix + ARGUMENT_SEPARATOR + child.getUsageText(), restricted); } } } diff --git a/src/main/java/com/mojang/brigadier/arguments/FloatArgumentType.java b/src/main/java/com/mojang/brigadier/arguments/FloatArgumentType.java index cd1b701..4e4723d 100644 --- a/src/main/java/com/mojang/brigadier/arguments/FloatArgumentType.java +++ b/src/main/java/com/mojang/brigadier/arguments/FloatArgumentType.java @@ -39,8 +39,8 @@ public class FloatArgumentType implements ArgumentType { return new FloatArgumentType(min, max, suffix); } - public static int getInteger(final CommandContext context, final String name) { - return context.getArgument(name, int.class); + public static float getFloat(final CommandContext context, final String name) { + return context.getArgument(name, Float.class); } @Override diff --git a/src/test/java/com/mojang/brigadier/CommandDispatcherUsagesTest.java b/src/test/java/com/mojang/brigadier/CommandDispatcherUsagesTest.java index cc22387..e0ee6b6 100644 --- a/src/test/java/com/mojang/brigadier/CommandDispatcherUsagesTest.java +++ b/src/test/java/com/mojang/brigadier/CommandDispatcherUsagesTest.java @@ -109,7 +109,7 @@ public class CommandDispatcherUsagesTest { @Test public void testAllUsage_noCommands() throws Exception { subject = new CommandDispatcher<>(); - final String[] results = subject.getAllUsage(subject.getRoot(), source); + final String[] results = subject.getAllUsage(subject.getRoot(), source, true); assertThat(results, is(emptyArray())); } @@ -122,7 +122,7 @@ public class CommandDispatcherUsagesTest { @Test public void testAllUsage_root() throws Exception { - final String[] results = subject.getAllUsage(subject.getRoot(), source); + final String[] results = subject.getAllUsage(subject.getRoot(), source, true); assertThat(results, equalTo(new String[]{ "a 1 i", "a 1 ii",