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