First attempt to color the help with requirementsAreMet color code.

This commit is contained in:
Olof Larsson 2013-04-25 13:25:49 +02:00
parent ffab977475
commit 69c78d68a1
2 changed files with 25 additions and 4 deletions

View File

@ -33,7 +33,7 @@ public class HelpCommand extends MCommand
{ {
if (subCommand.visibleTo(sender)) if (subCommand.visibleTo(sender))
{ {
lines.add(subCommand.getUseageTemplate(this.commandChain, true, true)); lines.add(subCommand.getUseageTemplate(this.commandChain, true, true, sender));
} }
} }

View File

@ -349,15 +349,31 @@ public abstract class MCommand
// HELP AND USAGE INFORMATION // HELP AND USAGE INFORMATION
// -------------------------------------------- // // -------------------------------------------- //
public String getUseageTemplate(List<MCommand> commandChain, boolean addDesc, boolean onlyFirstAlias) public String getUseageTemplate(List<MCommand> commandChain, boolean addDesc, boolean onlyFirstAlias, CommandSender sender)
{ {
StringBuilder ret = new StringBuilder(); StringBuilder ret = new StringBuilder();
ret.append(Txt.parse("<c>"));
List<MCommand> commands = new ArrayList<MCommand>(commandChain);
commands.add(this);
String commandGoodColor = Txt.parse("<c>");
String commandBadColor = Txt.parse("<bad>");
ret.append(commandGoodColor);
ret.append('/'); ret.append('/');
boolean first = true; boolean first = true;
for (MCommand mc : commandChain) for (MCommand mc : commands)
{ {
if (sender != null && !mc.requirementsAreMet(sender, false))
{
ret.append(commandBadColor);
}
else
{
ret.append(commandGoodColor);
}
if (first && onlyFirstAlias) if (first && onlyFirstAlias)
{ {
ret.append(mc.aliases.get(0)); ret.append(mc.aliases.get(0));
@ -410,6 +426,11 @@ public abstract class MCommand
return ret.toString(); return ret.toString();
} }
public String getUseageTemplate(List<MCommand> commandChain, boolean addDesc, boolean onlyFirstAlias)
{
return getUseageTemplate(commandChain, addDesc, onlyFirstAlias, null);
}
public String getUseageTemplate(List<MCommand> commandChain, boolean addDesc) public String getUseageTemplate(List<MCommand> commandChain, boolean addDesc)
{ {
return getUseageTemplate(commandChain, addDesc, false); return getUseageTemplate(commandChain, addDesc, false);