def set_max_players_command(instance, player, arguments):
  """ Set the maximum number of players allowed to join an instance.

  Args:
    instance: The GameInstance database model to change.
    player: The player requesting the change. This player must be the
      current leader of the instance.
    arguments: A single item list containing the desired integer value
      for the max players of this instance.

  If the maximum player count is set to a value lower than the current
  number of players, no players will be removed. However, new players
  will not be able to join until the max players count goes up or
  enough players leave the instance that the number of players is less
  than the maximum.

  Returns:
    The new value of max_players for the instance.

  Raises:
    ValueError if the requesting player is not the leader of the
      instance.
    ValueError if the argument is unable to be parsed into an integer.
  """
  instance.check_leader(player)
  max_players = int(arguments[0])
  instance.max_players = max_players
  return max_players