Break out command prefix checking
git-svn-id: svn+ssh://src.earth.threerings.net/narya/trunk@5842 542714f4-19e9-0310-aa3c-eee0fc999fb1
This commit is contained in:
@@ -957,24 +957,29 @@ public class ChatDirector extends BasicDirector
|
|||||||
HashMap<String, CommandHandler> matches = Maps.newHashMap();
|
HashMap<String, CommandHandler> matches = Maps.newHashMap();
|
||||||
BodyObject user = (BodyObject)_ctx.getClient().getClientObject();
|
BodyObject user = (BodyObject)_ctx.getClient().getClientObject();
|
||||||
for (Map.Entry<String, CommandHandler> entry : _handlers.entrySet()) {
|
for (Map.Entry<String, CommandHandler> entry : _handlers.entrySet()) {
|
||||||
String cmd = entry.getKey();
|
if (!isCommandPrefix(command, entry.getKey(), entry.getValue(), user)) {
|
||||||
if (!cmd.startsWith(command)) {
|
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
CommandHandler handler = entry.getValue();
|
if (entry.getKey().equals(command)) {// If we hit an exact match, it wins
|
||||||
if (!handler.checkAccess(user)) {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
if (cmd.equals(command)) {// If we hit an exact match, it wins
|
|
||||||
matches.clear();
|
matches.clear();
|
||||||
matches.put(cmd, handler);
|
matches.put(entry.getKey(), entry.getValue());
|
||||||
return matches;
|
return matches;
|
||||||
}
|
}
|
||||||
matches.put(cmd, handler);
|
matches.put(entry.getKey(), entry.getValue());
|
||||||
}
|
}
|
||||||
return matches;
|
return matches;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns true if <code>enteredCommand</code> equals or is a prefix of
|
||||||
|
* <code>handlerCommand</code> and if the handler is available for <code>user</code>.
|
||||||
|
*/
|
||||||
|
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.
|
* Adds a chatter to our list of recent chatters.
|
||||||
*/
|
*/
|
||||||
|
|||||||
Reference in New Issue
Block a user