    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                var4.fallDistance = 0.0F;
    034                String var5 = StatCollector.translateToLocal("gameMode." + var3.getName());
    035
    036                if (var4 != par1ICommandSender)
    037                {
    038                    notifyAdmins(par1ICommandSender, 1, "commands.gamemode.success.other", new Object[] {var4.getEntityName(), var5});
    039                }
    040                else
    041                {
    042                    notifyAdmins(par1ICommandSender, 1, "commands.gamemode.success.self", new Object[] {var5});
    043                }
    044            }
    045            else
    046            {
    047                throw new WrongUsageException("commands.gamemode.usage", new Object[0]);
    048            }
    049        }
    050
    051        /**
    052         * Gets the Game Mode specified in the command.
    053         */
    054        protected EnumGameType getGameModeFromCommand(ICommandSender par1ICommandSender, String par2Str)
    055        {
    056            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;
    057        }
    058
    059        /**
    060         * Adds the strings available in this command to the given list of tab completion options.
    061         */
    062        public List addTabCompletionOptions(ICommandSender par1ICommandSender, String[] par2ArrayOfStr)
    063        {
    064            return par2ArrayOfStr.length == 1 ? getListOfStringsMatchingLastWord(par2ArrayOfStr, new String[] {"survival", "creative", "adventure"}): (par2ArrayOfStr.length == 2 ? getListOfStringsMatchingLastWord(par2ArrayOfStr, this.getListOfPlayerUsernames()) : null);
    065        }
    066
    067        /**
    068         * Returns String array containing all player usernames in the server.
    069         */
    070        protected String[] getListOfPlayerUsernames()
    071        {
    072            return MinecraftServer.getServer().getAllUsernames();
    073        }
    074
    075        /**
    076         * Return whether the specified command parameter index is a username parameter.
    077         */
    078        public boolean isUsernameIndex(int par1)
    079        {
    080            return par1 == 1;
    081        }
    082    }