From 69c78d68a1025222ba1d21dd10e9fc45a06bf887 Mon Sep 17 00:00:00 2001 From: Olof Larsson Date: Thu, 25 Apr 2013 13:25:49 +0200 Subject: [PATCH] First attempt to color the help with requirementsAreMet color code. --- .../massivecraft/mcore/cmd/HelpCommand.java | 2 +- src/com/massivecraft/mcore/cmd/MCommand.java | 27 ++++++++++++++++--- 2 files changed, 25 insertions(+), 4 deletions(-) diff --git a/src/com/massivecraft/mcore/cmd/HelpCommand.java b/src/com/massivecraft/mcore/cmd/HelpCommand.java index 550e249c..4830be5d 100644 --- a/src/com/massivecraft/mcore/cmd/HelpCommand.java +++ b/src/com/massivecraft/mcore/cmd/HelpCommand.java @@ -33,7 +33,7 @@ public class HelpCommand extends MCommand { if (subCommand.visibleTo(sender)) { - lines.add(subCommand.getUseageTemplate(this.commandChain, true, true)); + lines.add(subCommand.getUseageTemplate(this.commandChain, true, true, sender)); } } diff --git a/src/com/massivecraft/mcore/cmd/MCommand.java b/src/com/massivecraft/mcore/cmd/MCommand.java index a320e861..05b1e7f3 100644 --- a/src/com/massivecraft/mcore/cmd/MCommand.java +++ b/src/com/massivecraft/mcore/cmd/MCommand.java @@ -349,15 +349,31 @@ public abstract class MCommand // HELP AND USAGE INFORMATION // -------------------------------------------- // - public String getUseageTemplate(List commandChain, boolean addDesc, boolean onlyFirstAlias) + public String getUseageTemplate(List commandChain, boolean addDesc, boolean onlyFirstAlias, CommandSender sender) { StringBuilder ret = new StringBuilder(); - ret.append(Txt.parse("")); + + List commands = new ArrayList(commandChain); + commands.add(this); + + String commandGoodColor = Txt.parse(""); + String commandBadColor = Txt.parse(""); + + ret.append(commandGoodColor); ret.append('/'); 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) { ret.append(mc.aliases.get(0)); @@ -410,6 +426,11 @@ public abstract class MCommand return ret.toString(); } + public String getUseageTemplate(List commandChain, boolean addDesc, boolean onlyFirstAlias) + { + return getUseageTemplate(commandChain, addDesc, onlyFirstAlias, null); + } + public String getUseageTemplate(List commandChain, boolean addDesc) { return getUseageTemplate(commandChain, addDesc, false);