    001    package net.minecraft.src;
    002
    003    import java.util.List;
    004    import net.minecraft.server.MinecraftServer;
    005
    006    public class CommandGameRule extends CommandBase
    007    {
    008        public String getCommandName()
    009        {
    010            return "gamerule";
    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.gamerule.usage", new Object[0]);
    024        }
    025
    026        public void processCommand(ICommandSender par1ICommandSender, String[] par2ArrayOfStr)
    027        {
    028            String var6;
    029
    030            if (par2ArrayOfStr.length == 2)
    031            {
    032                var6 = par2ArrayOfStr[0];
    033                String var7 = par2ArrayOfStr[1];
    034                GameRules var8 = this.getGameRules();
    035
    036                if (var8.hasRule(var6))
    037                {
    038                    var8.func_82764_b(var6, var7);
    039                    notifyAdmins(par1ICommandSender, "commands.gamerule.success", new Object[0]);
    040                }
    041                else
    042                {
    043                    notifyAdmins(par1ICommandSender, "commands.gamerule.norule", new Object[] {var6});
    044                }
    045            }
    046            else if (par2ArrayOfStr.length == 1)
    047            {
    048                var6 = par2ArrayOfStr[0];
    049                GameRules var4 = this.getGameRules();
    050
    051                if (var4.hasRule(var6))
    052                {
    053                    String var5 = var4.getGameRuleStringValue(var6);
    054                    par1ICommandSender.sendChatToPlayer(var6 + " = " + var5);
    055                }
    056                else
    057                {
    058                    notifyAdmins(par1ICommandSender, "commands.gamerule.norule", new Object[] {var6});
    059                }
    060            }
    061            else if (par2ArrayOfStr.length == 0)
    062            {
    063                GameRules var3 = this.getGameRules();
    064                par1ICommandSender.sendChatToPlayer(joinNiceString(var3.getRules()));
    065            }
    066            else
    067            {
    068                throw new WrongUsageException("commands.gamerule.usage", new Object[0]);
    069            }
    070        }
    071
    072        /**
    073         * Adds the strings available in this command to the given list of tab completion options.
    074         */
    075        public List addTabCompletionOptions(ICommandSender par1ICommandSender, String[] par2ArrayOfStr)
    076        {
    077            return par2ArrayOfStr.length == 1 ? getListOfStringsMatchingLastWord(par2ArrayOfStr, this.getGameRules().getRules()) : (par2ArrayOfStr.length == 2 ? getListOfStringsMatchingLastWord(par2ArrayOfStr, new String[] {"true", "false"}): null);
    078        }
    079
    080        /**
    081         * Return the game rule set this command should be able to manipulate.
    082         */
    083        private GameRules getGameRules()
    084        {
    085            return MinecraftServer.getServer().worldServerForDimension(0).getGameRules();
    086        }
    087    }