    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        public int func_82362_a()
    014        {
    015            return 2;
    016        }
    017
    018        public String getCommandUsage(ICommandSender par1ICommandSender)
    019        {
    020            return par1ICommandSender.translateString("commands.gamemode.usage", new Object[0]);
    021        }
    022
    023        public void processCommand(ICommandSender par1ICommandSender, String[] par2ArrayOfStr)
    024        {
    025            if (par2ArrayOfStr.length > 0)
    026            {
    027                EnumGameType var3 = this.getGameModeFromCommand(par1ICommandSender, par2ArrayOfStr[0]);
    028                EntityPlayerMP var4 = par2ArrayOfStr.length >= 2 ? func_82359_c(par1ICommandSender, par2ArrayOfStr[1]) : getCommandSenderAsPlayer(par1ICommandSender);
    029                var4.sendGameTypeToPlayer(var3);
    030                String var5 = StatCollector.translateToLocal("gameMode." + var3.getName());
    031
    032                if (var4 != par1ICommandSender)
    033                {
    034                    notifyAdmins(par1ICommandSender, 1, "commands.gamemode.success.other", new Object[] {var4.getEntityName(), var5});
    035                }
    036                else
    037                {
    038                    notifyAdmins(par1ICommandSender, 1, "commands.gamemode.success.self", new Object[] {var5});
    039                }
    040            }
    041            else
    042            {
    043                throw new WrongUsageException("commands.gamemode.usage", new Object[0]);
    044            }
    045        }
    046
    047        /**
    048         * Gets the Game Mode specified in the command.
    049         */
    050        protected EnumGameType getGameModeFromCommand(ICommandSender par1ICommandSender, String par2Str)
    051        {
    052            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;
    053        }
    054
    055        /**
    056         * Adds the strings available in this command to the given list of tab completion options.
    057         */
    058        public List addTabCompletionOptions(ICommandSender par1ICommandSender, String[] par2ArrayOfStr)
    059        {
    060            return par2ArrayOfStr.length == 1 ? getListOfStringsMatchingLastWord(par2ArrayOfStr, new String[] {"survival", "creative", "adventure"}): (par2ArrayOfStr.length == 2 ? getListOfStringsMatchingLastWord(par2ArrayOfStr, this.getListOfPlayerUsernames()) : null);
    061        }
    062
    063        /**
    064         * Returns String array containing all player usernames in the server.
    065         */
    066        protected String[] getListOfPlayerUsernames()
    067        {
    068            return MinecraftServer.getServer().getAllUsernames();
    069        }
    070
    071        public boolean func_82358_a(int par1)
    072        {
    073            return par1 == 1;
    074        }
    075    }