    001    package net.minecraft.src;
    002
    003    import java.util.List;
    004    import net.minecraft.server.MinecraftServer;
    005
    006    public class CommandTime extends CommandBase
    007    {
    008        public String getCommandName()
    009        {
    010            return "time";
    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.time.usage", new Object[0]);
    021        }
    022
    023        public void processCommand(ICommandSender par1ICommandSender, String[] par2ArrayOfStr)
    024        {
    025            if (par2ArrayOfStr.length > 1)
    026            {
    027                int var3;
    028
    029                if (par2ArrayOfStr[0].equals("set"))
    030                {
    031                    if (par2ArrayOfStr[1].equals("day"))
    032                    {
    033                        var3 = 0;
    034                    }
    035                    else if (par2ArrayOfStr[1].equals("night"))
    036                    {
    037                        var3 = 12500;
    038                    }
    039                    else
    040                    {
    041                        var3 = parseIntWithMin(par1ICommandSender, par2ArrayOfStr[1], 0);
    042                    }
    043
    044                    this.setTime(par1ICommandSender, var3);
    045                    notifyAdmins(par1ICommandSender, "commands.time.set", new Object[] {Integer.valueOf(var3)});
    046                    return;
    047                }
    048
    049                if (par2ArrayOfStr[0].equals("add"))
    050                {
    051                    var3 = parseIntWithMin(par1ICommandSender, par2ArrayOfStr[1], 0);
    052                    this.addTime(par1ICommandSender, var3);
    053                    notifyAdmins(par1ICommandSender, "commands.time.added", new Object[] {Integer.valueOf(var3)});
    054                    return;
    055                }
    056            }
    057
    058            throw new WrongUsageException("commands.time.usage", new Object[0]);
    059        }
    060
    061        /**
    062         * Adds the strings available in this command to the given list of tab completion options.
    063         */
    064        public List addTabCompletionOptions(ICommandSender par1ICommandSender, String[] par2ArrayOfStr)
    065        {
    066            return par2ArrayOfStr.length == 1 ? getListOfStringsMatchingLastWord(par2ArrayOfStr, new String[] {"set", "add"}): (par2ArrayOfStr.length == 2 && par2ArrayOfStr[0].equals("set") ? getListOfStringsMatchingLastWord(par2ArrayOfStr, new String[] {"day", "night"}): null);
    067        }
    068
    069        /**
    070         * Set the time in the server object.
    071         */
    072        protected void setTime(ICommandSender par1ICommandSender, int par2)
    073        {
    074            for (int var3 = 0; var3 < MinecraftServer.getServer().worldServers.length; ++var3)
    075            {
    076                MinecraftServer.getServer().worldServers[var3].setWorldTime((long)par2);
    077            }
    078        }
    079
    080        /**
    081         * Adds (or removes) time in the server object.
    082         */
    083        protected void addTime(ICommandSender par1ICommandSender, int par2)
    084        {
    085            for (int var3 = 0; var3 < MinecraftServer.getServer().worldServers.length; ++var3)
    086            {
    087                WorldServer var4 = MinecraftServer.getServer().worldServers[var3];
    088                var4.setWorldTime(var4.getWorldTime() + (long)par2);
    089            }
    090        }
    091    }