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(); + } +}