From dfc7d074bd7e8871b5f5d1b996c0cbfc6c37bef8 Mon Sep 17 00:00:00 2001 From: sk89q Date: Fri, 18 Feb 2011 00:09:07 -0800 Subject: [PATCH] Fixed incorrect help messages for nested commands. --- .../util/commands/CommandsManager.java | 8 ++++---- src/com/sk89q/util/StringUtil.java | 18 +++++++++++++----- 2 files changed, 17 insertions(+), 9 deletions(-) diff --git a/src/com/sk89q/minecraft/util/commands/CommandsManager.java b/src/com/sk89q/minecraft/util/commands/CommandsManager.java index 9c3150d40..95368feb2 100644 --- a/src/com/sk89q/minecraft/util/commands/CommandsManager.java +++ b/src/com/sk89q/minecraft/util/commands/CommandsManager.java @@ -21,10 +21,10 @@ package com.sk89q.minecraft.util.commands; import java.lang.reflect.InvocationTargetException; import java.lang.reflect.Method; -import java.util.ArrayList; import java.util.HashMap; -import java.util.List; +import java.util.HashSet; import java.util.Map; +import java.util.Set; import com.sk89q.util.StringUtil; /** @@ -174,7 +174,7 @@ public class CommandsManager { command.append("<"); - List allowedCommands = new ArrayList(); + Set allowedCommands = new HashSet(); for (Map.Entry entry : map.entrySet()) { Method childMethod = entry.getValue(); @@ -232,7 +232,7 @@ public class CommandsManager { if (parent == null) { // Root return false; } else { - player.printError(getNestedUsage(args, level - 1, method, player)); + player.printError(getNestedUsage(args, level - 1, parent, player)); return true; } } diff --git a/src/com/sk89q/util/StringUtil.java b/src/com/sk89q/util/StringUtil.java index 4ac411dfe..1ba76e79e 100644 --- a/src/com/sk89q/util/StringUtil.java +++ b/src/com/sk89q/util/StringUtil.java @@ -18,7 +18,7 @@ package com.sk89q.util; -import java.util.List; +import java.util.Collection; /** * String utilities. @@ -144,14 +144,22 @@ public class StringUtil { * @param initialIndex * @return */ - public static String joinString(List str, String delimiter, + public static String joinString(Collection str, String delimiter, int initialIndex) { if (str.size() == 0) { return ""; } - StringBuilder buffer = new StringBuilder(str.get(initialIndex).toString()); - for (int i = initialIndex + 1; i < str.size(); i++) { - buffer.append(delimiter).append(str.get(i).toString()); + StringBuilder buffer = new StringBuilder(); + int i = 0; + for (Object o : str) { + if (i >= initialIndex) { + if (i > 0) { + buffer.append(delimiter); + } + + buffer.append(o.toString()); + } + i++; } return buffer.toString(); }