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