Fix WritableBookMeta not containing the title & author

This commit is contained in:
themode 2021-03-18 03:13:56 +01:00
parent 72ad230872
commit 6c8e3cc022

View File

@ -1,6 +1,7 @@
package net.minestom.server.item.metadata;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import org.jglrxavpok.hephaistos.nbt.NBTCompound;
import org.jglrxavpok.hephaistos.nbt.NBTList;
import org.jglrxavpok.hephaistos.nbt.NBTString;
@ -11,8 +12,28 @@ import java.util.List;
public class WritableBookMeta extends ItemMeta {
private String title;
private String author;
private List<String> pages = new ArrayList<>();
@Nullable
public String getTitle() {
return title;
}
public void setTitle(@Nullable String title) {
this.title = title;
}
@Nullable
public String getAuthor() {
return author;
}
public void setAuthor(@Nullable String author) {
this.author = author;
}
/**
* Gets an array list containing the book pages.
* <p>
@ -49,6 +70,15 @@ public class WritableBookMeta extends ItemMeta {
@Override
public void read(@NotNull NBTCompound compound) {
if (compound.containsKey("title")) {
this.title = compound.getString("title");
}
if (compound.containsKey("author")) {
this.author = compound.getString("author");
}
if (compound.containsKey("pages")) {
final NBTList<NBTString> list = compound.getList("pages");
for (NBTString page : list) {
@ -59,6 +89,15 @@ public class WritableBookMeta extends ItemMeta {
@Override
public void write(@NotNull NBTCompound compound) {
if (title != null) {
compound.setString("title", title);
}
if (author != null) {
compound.setString("author", author);
}
if (!pages.isEmpty()) {
NBTList<NBTString> list = new NBTList<>(NBTTypes.TAG_String);
for (String page : pages) {