@Command(
      aliases = {"time"},
      usage = "<add|set> <0-24000|day|night|dawn|dusk> [world]",
      desc = "Set the time of the server",
      min = 2,
      max = 3)
  @CommandPermissions("vanilla.command.time")
  public void time(CommandContext args, CommandSource source) throws CommandException {
    long time = 0;
    boolean relative = false;
    if (args.getString(0).equalsIgnoreCase("set")) {
      if (args.isInteger(1)) {
        time = args.getInteger(1);
      } else {
        try {
          time = Time.get(args.getString(1)).getTime();
        } catch (Exception e) {
          throw new CommandException("'" + args.getString(1) + "' is not a valid time.");
        }
      }
    } else if (args.getString(0).equalsIgnoreCase("add")) {
      relative = true;
      if (args.isInteger(1)) {
        time = args.getInteger(1);
      } else {
        throw new CommandException("Argument to 'add' must be an integer.");
      }
    }

    World world;
    if (args.length() == 3) {
      world = plugin.getEngine().getWorld(args.getString(2));
      if (world == null) {
        throw new CommandException("'" + args.getString(2) + "' is not a valid world.");
      }
    } else if (source instanceof Player) {
      Player player = (Player) source;
      world = player.getWorld();
    } else {
      throw new CommandException("You must specify a world.");
    }

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

    sky.setTime(relative ? (sky.getTime() + time) : time);
    if (Spout.getEngine() instanceof Client) {
      source.sendMessage(
          plugin.getPrefix(),
          ChatStyle.BRIGHT_GREEN,
          "You set ",
          ChatStyle.WHITE,
          world.getName(),
          ChatStyle.BRIGHT_GREEN,
          " to time: ",
          ChatStyle.WHITE,
          sky.getTime());
    } else {
      ((Server) Spout.getEngine())
          .broadcastMessage(
              plugin.getPrefix(),
              ChatStyle.WHITE,
              world.getName(),
              ChatStyle.BRIGHT_GREEN,
              " set to: ",
              ChatStyle.WHITE,
              sky.getTime());
    }
  }