    001    package net.minecraft.src;
    002
    003    import java.util.Arrays;
    004    import java.util.Collections;
    005    import java.util.List;
    006    import java.util.Map;
    007    import net.minecraft.server.MinecraftServer;
    008
    009    public class CommandHelp extends CommandBase
    010    {
    011        public String getCommandName()
    012        {
    013            return "help";
    014        }
    015
    016        public int func_82362_a()
    017        {
    018            return 0;
    019        }
    020
    021        public String getCommandUsage(ICommandSender par1ICommandSender)
    022        {
    023            return par1ICommandSender.translateString("commands.help.usage", new Object[0]);
    024        }
    025
    026        public List getCommandAliases()
    027        {
    028            return Arrays.asList(new String[] {"?"});
    029        }
    030
    031        public void processCommand(ICommandSender par1ICommandSender, String[] par2ArrayOfStr)
    032        {
    033            List var3 = this.getSortedPossibleCommands(par1ICommandSender);
    034            byte var4 = 7;
    035            int var5 = var3.size() / var4;
    036            boolean var6 = false;
    037            ICommand var9;
    038            int var11;
    039
    040            try
    041            {
    042                var11 = par2ArrayOfStr.length == 0 ? 0 : parseIntBounded(par1ICommandSender, par2ArrayOfStr[0], 1, var5 + 1) - 1;
    043            }
    044            catch (NumberInvalidException var10)
    045            {
    046                Map var8 = this.getCommands();
    047                var9 = (ICommand)var8.get(par2ArrayOfStr[0]);
    048
    049                if (var9 != null)
    050                {
    051                    throw new WrongUsageException(var9.getCommandUsage(par1ICommandSender), new Object[0]);
    052                }
    053
    054                throw new CommandNotFoundException();
    055            }
    056
    057            int var7 = Math.min((var11 + 1) * var4, var3.size());
    058            par1ICommandSender.sendChatToPlayer("\u00a72" + par1ICommandSender.translateString("commands.help.header", new Object[] {Integer.valueOf(var11 + 1), Integer.valueOf(var5 + 1)}));
    059
    060            for (int var12 = var11 * var4; var12 < var7; ++var12)
    061            {
    062                var9 = (ICommand)var3.get(var12);
    063                par1ICommandSender.sendChatToPlayer(var9.getCommandUsage(par1ICommandSender));
    064            }
    065
    066            if (var11 == 0 && par1ICommandSender instanceof EntityPlayer)
    067            {
    068                par1ICommandSender.sendChatToPlayer("\u00a7a" + par1ICommandSender.translateString("commands.help.footer", new Object[0]));
    069            }
    070        }
    071
    072        /**
    073         * Returns a sorted list of all possible commands for the given ICommandSender.
    074         */
    075        protected List getSortedPossibleCommands(ICommandSender par1ICommandSender)
    076        {
    077            List var2 = MinecraftServer.getServer().getCommandManager().getPossibleCommands(par1ICommandSender);
    078            Collections.sort(var2);
    079            return var2;
    080        }
    081
    082        protected Map getCommands()
    083        {
    084            return MinecraftServer.getServer().getCommandManager().getCommands();
    085        }
    086    }