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