    001package net.minecraft.command;
    002
    003import java.util.List;
    004import java.util.Random;
    005import net.minecraft.server.MinecraftServer;
    006import net.minecraft.world.WorldServer;
    007import net.minecraft.world.storage.WorldInfo;
    008
    009public class CommandWeather extends CommandBase
    010{
    011    public String getCommandName()
    012    {
    013        return "weather";
    014    }
    015
    016    /**
    017     * Return the required permission level for this command.
    018     */
    019    public int getRequiredPermissionLevel()
    020    {
    021        return 2;
    022    }
    023
    024    public void processCommand(ICommandSender par1ICommandSender, String[] par2ArrayOfStr)
    025    {
    026        if (par2ArrayOfStr.length < 1)
    027        {
    028            throw new WrongUsageException("commands.weather.usage", new Object[0]);
    029        }
    030        else
    031        {
    032            int i = (300 + (new Random()).nextInt(600)) * 20;
    033
    034            if (par2ArrayOfStr.length >= 2)
    035            {
    036                i = parseIntBounded(par1ICommandSender, par2ArrayOfStr[1], 1, 1000000) * 20;
    037            }
    038
    039            WorldServer worldserver = MinecraftServer.getServer().worldServers[0];
    040            WorldInfo worldinfo = worldserver.getWorldInfo();
    041            worldinfo.setRainTime(i);
    042            worldinfo.setThunderTime(i);
    043
    044            if ("clear".equalsIgnoreCase(par2ArrayOfStr[0]))
    045            {
    046                worldinfo.setRaining(false);
    047                worldinfo.setThundering(false);
    048                notifyAdmins(par1ICommandSender, "commands.weather.clear", new Object[0]);
    049            }
    050            else if ("rain".equalsIgnoreCase(par2ArrayOfStr[0]))
    051            {
    052                worldinfo.setRaining(true);
    053                worldinfo.setThundering(false);
    054                notifyAdmins(par1ICommandSender, "commands.weather.rain", new Object[0]);
    055            }
    056            else if ("thunder".equalsIgnoreCase(par2ArrayOfStr[0]))
    057            {
    058                worldinfo.setRaining(true);
    059                worldinfo.setThundering(true);
    060                notifyAdmins(par1ICommandSender, "commands.weather.thunder", new Object[0]);
    061            }
    062        }
    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[] {"clear", "rain", "thunder"}): null;
    071    }
    072}