use of net.minecraft.server.v1_15_R1.IChatBaseComponent in project CitizensBooks by NicoNekoDev.
the class DistributionHandler method convertJsonToBook.
@Override
public ItemStack convertJsonToBook(JsonObject jsonBook) throws IllegalAccessException {
ItemStack newBook = new ItemStack(Material.WRITTEN_BOOK);
BookMeta bookMeta = (BookMeta) newBook.getItemMeta();
JsonPrimitive jsonAuthor = jsonBook.getAsJsonPrimitive("author");
JsonPrimitive jsonTitle = jsonBook.getAsJsonPrimitive("title");
JsonArray jsonPages = jsonBook.getAsJsonArray("pages");
bookMeta.setAuthor(jsonAuthor.isString() ? jsonAuthor.getAsString() : "Server");
bookMeta.setTitle(jsonTitle.isString() ? jsonTitle.getAsString() : "Title");
List<IChatBaseComponent> pages = new ArrayList<>();
for (JsonElement jsonPage : jsonPages) {
pages.add(IChatBaseComponent.ChatSerializer.a(jsonPage.toString()));
}
this.pagesField.set(bookMeta, pages);
newBook.setItemMeta(bookMeta);
return newBook;
}
use of net.minecraft.server.v1_15_R1.IChatBaseComponent in project CitizensBooks by NicoNekoDev.
the class DistributionHandler method convertJsonToBook.
@Override
public ItemStack convertJsonToBook(JsonObject jsonBook) throws IllegalAccessException {
ItemStack newBook = new ItemStack(Material.WRITTEN_BOOK);
BookMeta bookMeta = (BookMeta) newBook.getItemMeta();
JsonPrimitive jsonAuthor = jsonBook.getAsJsonPrimitive("author");
JsonPrimitive jsonTitle = jsonBook.getAsJsonPrimitive("title");
JsonArray jsonPages = jsonBook.getAsJsonArray("pages");
bookMeta.setAuthor(jsonAuthor.isString() ? jsonAuthor.getAsString() : "Server");
bookMeta.setTitle(jsonTitle.isString() ? jsonTitle.getAsString() : "Title");
List<IChatBaseComponent> pages = new ArrayList<>();
for (JsonElement jsonPage : jsonPages) {
pages.add(IChatBaseComponent.ChatSerializer.a(jsonPage.toString()));
}
this.pagesField.set(bookMeta, pages);
newBook.setItemMeta(bookMeta);
return newBook;
}
use of net.minecraft.server.v1_15_R1.IChatBaseComponent in project CitizensBooks by NicoNekoDev.
the class DistributionHandler method convertJsonToBook.
@Override
public ItemStack convertJsonToBook(JsonObject jsonBook) throws IllegalAccessException {
ItemStack newBook = new ItemStack(Material.WRITTEN_BOOK);
BookMeta bookMeta = (BookMeta) newBook.getItemMeta();
JsonPrimitive jsonAuthor = jsonBook.getAsJsonPrimitive("author");
JsonPrimitive jsonTitle = jsonBook.getAsJsonPrimitive("title");
JsonArray jsonPages = jsonBook.getAsJsonArray("pages");
bookMeta.setAuthor(jsonAuthor.isString() ? jsonAuthor.getAsString() : "Server");
bookMeta.setTitle(jsonTitle.isString() ? jsonTitle.getAsString() : "Title");
List<IChatBaseComponent> pages = new ArrayList<>();
for (JsonElement jsonPage : jsonPages) {
pages.add(IChatBaseComponent.ChatSerializer.a(jsonPage.toString()));
}
this.pagesField.set(bookMeta, pages);
newBook.setItemMeta(bookMeta);
return newBook;
}
Aggregations