    001package net.minecraft.command;
    002
    003import java.util.List;
    004import net.minecraft.server.MinecraftServer;
    005import net.minecraft.world.WorldServer;
    006
    007public 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 i;
    032
    033            if (par2ArrayOfStr[0].equals("set"))
    034            {
    035                if (par2ArrayOfStr[1].equals("day"))
    036                {
    037                    i = 0;
    038                }
    039                else if (par2ArrayOfStr[1].equals("night"))
    040                {
    041                    i = 12500;
    042                }
    043                else
    044                {
    045                    i = parseIntWithMin(par1ICommandSender, par2ArrayOfStr[1], 0);
    046                }
    047
    048                this.setTime(par1ICommandSender, i);
    049                notifyAdmins(par1ICommandSender, "commands.time.set", new Object[] {Integer.valueOf(i)});
    050                return;
    051            }
    052
    053            if (par2ArrayOfStr[0].equals("add"))
    054            {
    055                i = parseIntWithMin(par1ICommandSender, par2ArrayOfStr[1], 0);
    056                this.addTime(par1ICommandSender, i);
    057                notifyAdmins(par1ICommandSender, "commands.time.added", new Object[] {Integer.valueOf(i)});
    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 j = 0; j < MinecraftServer.getServer().worldServers.length; ++j)
    079        {
    080            MinecraftServer.getServer().worldServers[j].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 j = 0; j < MinecraftServer.getServer().worldServers.length; ++j)
    090        {
    091            WorldServer worldserver = MinecraftServer.getServer().worldServers[j];
    092            worldserver.setWorldTime(worldserver.getWorldTime() + (long)par2);
    093        }
    094    }
    095}