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