Proposition $3.20$ of Algebraic Geometry and Aritmetic Curves- Qing Liu Can anyone explain me how the author can say that $Z$ is an affine scheme?

I thinked in a first moment that this was the key point, but it doesn't work.
EDIT:

 A: The proof isn't actually finished yet. It proceeds by using the already established correspondence between sheafs of ideals and closed immersions Prop 2.24.
By taking global sections of the exact sequence of sheaves
$$ 0 \to ker f^\# \to \mathcal{O}_X \to f^*\mathcal{O}_Z  \to 0 $$
we get an exact sequence of A-modules
$$ 0 \to J \to A \to \mathcal{O}_Z(Z)$$
where $ J = ker f^\#(X) $. Let $ g : Spec \,A/J \to Spec \, A $.
We want to show that $ Z $ is isomorphic to $ Spec \,A/J $.
Using the proposition it suffices to show that $ ker f^\# = ker g ^\# $.
We can do this by checking the equallity on all principal open subsets.
So let $ g  \in A $ and $ h = f^\#(g)$. Then $ f^{-1}(D(g)) = Z_h $. Tensoring the exact sequence of A-modules above with $A_g$ we get
$$ 0 \to J \otimes A_g \to A_g \to \mathcal{O}_Z(Z)_h$$
Here $A_g = \mathcal{O}_X(D(g)) $ and $ \mathcal{O}_Z(Z)_h = \mathcal{O}(Z_h) $. The later is clearly true Z is affine. But it truns out that i suffices for Z to have condition (3.2). Therefore we have the exact sequence
$$ 0 \to J \otimes A_g \to \mathcal{O}_X(D(g)) \to f^*\mathcal{O}_Z(D(g)) $$
This shows $ ker f ^\# (D(g)) =  J \otimes A_g $. By tensoring $ 0 \to J \to A \to A/J \to 0$ with $A_g$ it is easily seen that $ ker g^\# (D(g)) =  J \otimes A_g $ too.
It's also possible to prove that Z is affine first, without using the sheaf of ideals/closed immersion correspondence. Hartshorne gives some hints on how to do that(see Hartshorne Algebraic Geometry Chapter 2 Ex. 3.11.b).
