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