From ad7b00b762bb0847049cde1abb0fc2d09ba48b1e Mon Sep 17 00:00:00 2001 From: Javacraft Date: Wed, 5 Dec 2018 19:44:07 -0500 Subject: [PATCH] Use ImmutableList rather than AbstractList for CraftMetaBook Although the AbstracList implementation does return a list, it is a of a form that does not play well with libraries using reflection, such as Gson. Leveraging a stream and the ImmutableList collector, this process is greatly simplified (and cleaner). --- .../craftbukkit/inventory/CraftMetaBook.java | 14 +------------- 1 file changed, 1 insertion(+), 13 deletions(-) diff --git a/src/main/java/org/bukkit/craftbukkit/inventory/CraftMetaBook.java b/src/main/java/org/bukkit/craftbukkit/inventory/CraftMetaBook.java index c8654c68fb..0831e13e51 100644 --- a/src/main/java/org/bukkit/craftbukkit/inventory/CraftMetaBook.java +++ b/src/main/java/org/bukkit/craftbukkit/inventory/CraftMetaBook.java @@ -256,19 +256,7 @@ public class CraftMetaBook extends CraftMetaItem implements BookMeta { } public List getPages() { - final List copy = ImmutableList.copyOf(pages); - return new AbstractList() { - - @Override - public String get(int index) { - return CraftChatMessage.fromComponent(copy.get(index)); - } - - @Override - public int size() { - return copy.size(); - } - }; + return pages.stream().map(CraftChatMessage::fromComponent).collect(ImmutableList.toImmutableList()); } public void setPages(List pages) {