    001    package net.minecraft.src;
    002
    003    import java.util.List;
    004    import net.minecraft.server.MinecraftServer;
    005
    006    public class CommandGameMode extends CommandBase
    007    {
    008        public String getCommandName()
    009        {
    010            return "gamemode";
    011        }
    012
    013        /**
    014         * Return the required permission level for this command.
    015         */
    016        public int getRequiredPermissionLevel()
    017        {
    018            return 2;
    019        }
    020
    021        public String getCommandUsage(ICommandSender par1ICommandSender)
    022        {
    023            return par1ICommandSender.translateString("commands.gamemode.usage", new Object[0]);
    024        }
    025
    026        public void processCommand(ICommandSender par1ICommandSender, String[] par2ArrayOfStr)
    027        {
    028            if (par2ArrayOfStr.length > 0)
    029            {
    030                EnumGameType var3 = this.getGameModeFromCommand(par1ICommandSender, par2ArrayOfStr[0]);
    031                EntityPlayerMP var4 = par2ArrayOfStr.length >= 2 ? func_82359_c(par1ICommandSender, par2ArrayOfStr[1]) : getCommandSenderAsPlayer(par1ICommandSender);
    032                var4.sendGameTypeToPlayer(var3);
    033                String var5 = StatCollector.translateToLocal("gameMode." + var3.getName());
    034
    035                if (var4 != par1ICommandSender)
    036                {
    037                    notifyAdmins(par1ICommandSender, 1, "commands.gamemode.success.other", new Object[] {var4.getEntityName(), var5});
    038                }
    039                else
    040                {
    041                    notifyAdmins(par1ICommandSender, 1, "commands.gamemode.success.self", new Object[] {var5});
    042                }
    043            }
    044            else
    045            {
    046                throw new WrongUsageException("commands.gamemode.usage", new Object[0]);
    047            }
    048        }
    049
    050        /**
    051         * Gets the Game Mode specified in the command.
    052         */
    053        protected EnumGameType getGameModeFromCommand(ICommandSender par1ICommandSender, String par2Str)
    054        {
    055            return !par2Str.equalsIgnoreCase(EnumGameType.SURVIVAL.getName()) && !par2Str.equalsIgnoreCase("s") ? (!par2Str.equalsIgnoreCase(EnumGameType.CREATIVE.getName()) && !par2Str.equalsIgnoreCase("c") ? (!par2Str.equalsIgnoreCase(EnumGameType.ADVENTURE.getName()) && !par2Str.equalsIgnoreCase("a") ? WorldSettings.getGameTypeById(parseIntBounded(par1ICommandSender, par2Str, 0, EnumGameType.values().length - 2)) : EnumGameType.ADVENTURE) : EnumGameType.CREATIVE) : EnumGameType.SURVIVAL;
    056        }
    057
    058        /**
    059         * Adds the strings available in this command to the given list of tab completion options.
    060         */
    061        public List addTabCompletionOptions(ICommandSender par1ICommandSender, String[] par2ArrayOfStr)
    062        {
    063            return par2ArrayOfStr.length == 1 ? getListOfStringsMatchingLastWord(par2ArrayOfStr, new String[] {"survival", "creative", "adventure"}): (par2ArrayOfStr.length == 2 ? getListOfStringsMatchingLastWord(par2ArrayOfStr, this.getListOfPlayerUsernames()) : null);
    064        }
    065
    066        /**
    067         * Returns String array containing all player usernames in the server.
    068         */
    069        protected String[] getListOfPlayerUsernames()
    070        {
    071            return MinecraftServer.getServer().getAllUsernames();
    072        }
    073
    074        /**
    075         * Return whether the specified command parameter index is a username parameter.
    076         */
    077        public boolean isUsernameIndex(int par1)
    078        {
    079            return par1 == 1;
    080        }
    081    }