diff --git a/src/java/com/threerings/crowd/chat/client/ChatDirector.java b/src/java/com/threerings/crowd/chat/client/ChatDirector.java index 9ddb9bc43..713a73610 100644 --- a/src/java/com/threerings/crowd/chat/client/ChatDirector.java +++ b/src/java/com/threerings/crowd/chat/client/ChatDirector.java @@ -957,24 +957,29 @@ public class ChatDirector extends BasicDirector HashMap matches = Maps.newHashMap(); BodyObject user = (BodyObject)_ctx.getClient().getClientObject(); for (Map.Entry entry : _handlers.entrySet()) { - String cmd = entry.getKey(); - if (!cmd.startsWith(command)) { + if (!isCommandPrefix(command, entry.getKey(), entry.getValue(), user)) { continue; } - CommandHandler handler = entry.getValue(); - if (!handler.checkAccess(user)) { - continue; - } - if (cmd.equals(command)) {// If we hit an exact match, it wins + if (entry.getKey().equals(command)) {// If we hit an exact match, it wins matches.clear(); - matches.put(cmd, handler); + matches.put(entry.getKey(), entry.getValue()); return matches; } - matches.put(cmd, handler); + matches.put(entry.getKey(), entry.getValue()); } return matches; } + /** + * Returns true if enteredCommand equals or is a prefix of + * handlerCommand and if the handler is available for user. + */ + protected boolean isCommandPrefix (String enteredCommand, String handlerCommand, + CommandHandler handler, BodyObject user) + { + return handlerCommand.startsWith(enteredCommand) && handler.checkAccess(user); + } + /** * Adds a chatter to our list of recent chatters. */