From f9942a608e964142ccf726c6920f95c4567fa19a Mon Sep 17 00:00:00 2001 From: asofold Date: Tue, 6 Nov 2012 10:23:39 +0100 Subject: [PATCH] Do add CommandUtil for auxiliary methods. --- .../nocheatplus/command/CommandUtil.java | 28 +++++++++++++++++++ 1 file changed, 28 insertions(+) create mode 100644 src/fr/neatmonster/nocheatplus/command/CommandUtil.java diff --git a/src/fr/neatmonster/nocheatplus/command/CommandUtil.java b/src/fr/neatmonster/nocheatplus/command/CommandUtil.java new file mode 100644 index 00000000..b9a3a72c --- /dev/null +++ b/src/fr/neatmonster/nocheatplus/command/CommandUtil.java @@ -0,0 +1,28 @@ +package fr.neatmonster.nocheatplus.command; + +import org.bukkit.Bukkit; +import org.bukkit.command.Command; +import org.bukkit.command.SimpleCommandMap; +import org.bukkit.craftbukkit.CraftServer; + +public class CommandUtil { + + public static SimpleCommandMap getCommandMap(){ + return (((CraftServer) Bukkit.getServer()).getCommandMap()); + } + + /** + * Get the command label (trim + lower case). + * @param alias + * @param strict If to return null if no command is found. + * @return + */ + public static String getCommandLabel(final String alias, final boolean strict){ + final String lcAlias = alias.trim().toLowerCase(); + final Command command = getCommandMap().getCommand(alias); + if (command == null){ + return strict ? null : lcAlias; + } + else return command.getLabel().trim().toLowerCase(); + } +}