package net.minecraft.src;

import net.minecraft.server.MinecraftServer;

import java.io.File;
import java.io.FileWriter;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;

public class CommandDebug extends CommandBase
{
    /** Time the debugging started in milliseconds. */
    private long startTime;

    /** The number of ticks when debugging started. */
    private int startTicks;

    public String getCommandName()
    {
        return "debug";
    }

    /**
     * Return the required permission level for this command.
     */
    public int getRequiredPermissionLevel()
    {
        return 3;
    }

    public String getCommandUsage(ICommandSender par1ICommandSender)
    {
        return "commands.debug.usage";
    }

    public void processCommand(ICommandSender par1ICommandSender, String[] par2ArrayOfStr)
    {
        if (par2ArrayOfStr.length == 1)
        {
            if (par2ArrayOfStr[0].equals("start"))
            {
                notifyAdmins(par1ICommandSender, "commands.debug.start", new Object[0]);
                MinecraftServer.getServer().enableProfiling();
                this.startTime = MinecraftServer.getSystemTimeMillis();
                this.startTicks = MinecraftServer.getServer().getTickCounter();
                return;
            }

            if (par2ArrayOfStr[0].equals("stop"))
            {
                long var3 = MinecraftServer.getSystemTimeMillis();
                int var5 = MinecraftServer.getServer().getTickCounter();
                long var6 = var3 - this.startTime;
                int var8 = var5 - this.startTicks;
                notifyAdmins(par1ICommandSender, "commands.debug.stop", new Object[] {Float.valueOf((float)var6 / 1000.0F), Integer.valueOf(var8)});
                return;
            }
        }

        throw new WrongUsageException("commands.debug.usage", new Object[0]);
    }

    /**
     * Adds the strings available in this command to the given list of tab completion options.
     */
    public List addTabCompletionOptions(ICommandSender par1ICommandSender, String[] par2ArrayOfStr)
    {
        return par2ArrayOfStr.length == 1 ? getListOfStringsMatchingLastWord(par2ArrayOfStr, new String[] {"start", "stop"}): null;
    }
}
