@Command(
      aliases = "weather",
      usage = "<0|1|2> (0 = CLEAR, 1 = RAIN/SNOW, 2 = THUNDERSTORM) [world]",
      desc = "Changes the weather",
      min = 1,
      max = 2)
  @CommandPermissions("vanilla.command.weather")
  public void weather(CommandContext args, CommandSource source) throws CommandException {
    World world;
    if (source instanceof Player && args.length() == 1) {
      world = ((Player) source).getWorld();
    } else if (args.length() == 2) {
      world = plugin.getEngine().getWorld(args.getString(1));

      if (world == null) {
        throw new CommandException("Invalid world '" + args.getString(1) + "'.");
      }
    } else {
      throw new CommandException("You need to specify a world.");
    }

    Weather weather;
    try {
      if (args.isInteger(0)) {
        weather = Weather.get(args.getInteger(0));
      } else {
        weather = Weather.get(args.getString(0).replace("snow", "rain"));
      }
    } catch (Exception e) {
      throw new CommandException(
          "Weather must be a mode between 0 and 2, 'CLEAR', 'RAIN', 'SNOW', or 'THUNDERSTORM'");
    }

    VanillaSky sky = VanillaSky.getSky(world);
    if (sky == null) {
      throw new CommandException("The sky of world '" + world.getName() + "' is not availible.");
    }

    sky.setWeather(weather);
    ChatArguments message;

    switch (weather) {
      case RAIN:
        message =
            new ChatArguments(
                plugin.getPrefix(),
                ChatStyle.BRIGHT_GREEN,
                "Weather set to ",
                ChatStyle.WHITE,
                "RAIN/SNOW",
                ChatStyle.BRIGHT_GREEN,
                ".");
        break;
      default:
        message =
            new ChatArguments(
                plugin.getPrefix(),
                ChatStyle.BRIGHT_GREEN,
                "Weather set to ",
                ChatStyle.WHITE,
                weather.name(),
                ChatStyle.BRIGHT_GREEN,
                ".");
        break;
    }
    if (Spout.getEngine() instanceof Client) {
      source.sendMessage(message);
    } else {
      for (Player player : ((Server) Spout.getEngine()).getOnlinePlayers()) {
        if (player.getWorld().equals(world)) {
          player.sendMessage(message);
        }
      }
    }
  }