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