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