Tampilan buku
A BookView is the representation of the Book GUI on the client. The BookView
is not associated with an
actual ItemStack and is only for displaying Component through a book to the player. Note that a
BookView
is read-only, due to it being impossible to tell the client to open an unsigned book.
Untuk membuat BookView
, kita hanya perlu memperoleh BookView.Builder, yang telah disediakan melalui metode BookView#builder(). Dengan menggunakan pembangunnya, kita dapat menetapkan judulnya, penciptanya, dan halaman dari BookView
. Lalu untuk menggunakan tampilannya, kita harus mengirimkannya ke Viewer. Contohnya ditunjukkan di bawah ini:
import net.kyori.adventure.text.Component;
import org.spongepowered.api.effect.Viewer;
import org.spongepowered.api.text.BookView;
BookView bookView = BookView.builder()
.title(Component.text("Story Mode"))
.author(Component.text("Notch"))
.addPage(Component.text("There once was a Steve..."))
.build();
viewer.sendBookView(bookView);
This will display a book to the client with a single page that contains the text specified in the
BookView.Builder#addPage(Component) method. Of course, you don't have to call addPage(Component)
for every page
you wish to add. The BookView.Builder
class provides a BookView.Builder#addPages(Collection<Component>)
method that accepts multiple Component
s.
The BookView.Builder
class also provides the BookView.Builder#insertPage(int, Component) and the corresponding
BookView.Builder#insertPages(int, Collection<Component>) methods for inserting a page or several pages at any
given index.
You may also remove pages of a BookView
by providing either the Component
from the page or by specifying the index
of the page that you wish to remove. You simply need to use the corresponding
BookView.Builder#removePage(Component), BookView.Builder#removePage(int), or
BookView.Builder#removePages(Collection<Component>) methods.