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).

By: Javacraft <frelling@java-craft.com>
This commit is contained in:
CraftBukkit/Spigot 2018-12-05 19:44:07 -05:00
parent 98ccac33d9
commit 21a5dbe50f

View file

@ -256,19 +256,7 @@ public class CraftMetaBook extends CraftMetaItem implements BookMeta {
}
public List<String> getPages() {
final List<IChatBaseComponent> copy = ImmutableList.copyOf(pages);
return new AbstractList<String>() {
@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<String> pages) {