Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 22 additions & 0 deletions api/src/main/java/net/kyori/adventure/inventory/Book.java
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,28 @@ static Book book(final Component title, final Component author, final Component.
return book(title, author, List.of(pages));
}

/**
* Creates a book with title and author set to {@link Component#empty()}.
*
* @param pages the collection of pages
* @return a book
* @since 5.1.0
*/
static Book book(final Collection<Component> pages) {
return new BookImpl(new ArrayList<>(pages));
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
return new BookImpl(new ArrayList<>(pages));
return new BookImpl(List.copyOf(pages));

Copy link
Contributor Author

@Privatech38 Privatech38 Feb 21, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

But that would differ from the implementation that uses title and author?

static Book book(final Component title, final Component author, final Collection<Component> pages) {
return new BookImpl(title, author, new ArrayList<>(pages));
}

}

/**
* Creates a book with title and author set to {@link Component#empty()}.
*
* @param pages an array of pages
* @return a book
* @since 5.1.0
*/
static Book book(final Component... pages) {
return new BookImpl(List.of(pages));
}

/**
* Create a new builder that will create a {@link Book}.
*
Expand Down
4 changes: 4 additions & 0 deletions api/src/main/java/net/kyori/adventure/inventory/BookImpl.java
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,10 @@ record BookImpl(Component title, Component author, List<Component> pages) implem
this.pages = List.copyOf(requireNonNull(pages, "pages"));
}

BookImpl(final List<Component> pages) {
this(Component.empty(), Component.empty(), List.copyOf(requireNonNull(pages, "pages")));
}

@Override
public Component title() {
return this.title;
Expand Down
9 changes: 9 additions & 0 deletions api/src/test/java/net/kyori/adventure/inventory/BookTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -109,4 +109,13 @@ void testEquality() {
)
.testEquals();
}

@Test
void testPagesOnly() {
final Book b = Book.book(arrayOfPages(1));
assertEquals(listOfPages(1), b.pages());
assertEquals(Component.empty(), b.title());
assertEquals(Component.empty(), b.author());
}

}