Search in sources :

Example 56 with IChatBaseComponent

use of net.minecraft.server.v1_8_R2.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;
}
Also used : ArrayList(java.util.ArrayList) IChatBaseComponent(net.minecraft.server.v1_13_R1.IChatBaseComponent) ItemStack(org.bukkit.inventory.ItemStack) BookMeta(org.bukkit.inventory.meta.BookMeta)

Example 57 with IChatBaseComponent

use of net.minecraft.server.v1_8_R2.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;
}
Also used : ArrayList(java.util.ArrayList) IChatBaseComponent(net.minecraft.server.v1_9_R1.IChatBaseComponent) ItemStack(org.bukkit.inventory.ItemStack) BookMeta(org.bukkit.inventory.meta.BookMeta)

Example 58 with IChatBaseComponent

use of net.minecraft.server.v1_8_R2.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;
}
Also used : ArrayList(java.util.ArrayList) IChatBaseComponent(net.minecraft.server.v1_9_R2.IChatBaseComponent) ItemStack(org.bukkit.inventory.ItemStack) BookMeta(org.bukkit.inventory.meta.BookMeta)

Aggregations

BookMeta (org.bukkit.inventory.meta.BookMeta)41 ArrayList (java.util.ArrayList)29 ItemStack (org.bukkit.inventory.ItemStack)28 List (java.util.List)14 GameProfile (com.mojang.authlib.GameProfile)9 IChatBaseComponent (net.minecraft.server.v1_8_R3.IChatBaseComponent)8 IChatBaseComponent (net.minecraft.server.v1_12_R1.IChatBaseComponent)5 IChatBaseComponent (net.minecraft.server.v1_14_R1.IChatBaseComponent)5 CraftPlayer (org.bukkit.craftbukkit.v1_8_R3.entity.CraftPlayer)5 IChatBaseComponent (net.minecraft.server.v1_10_R1.IChatBaseComponent)4 IChatBaseComponent (net.minecraft.server.v1_11_R1.IChatBaseComponent)4 IChatBaseComponent (net.minecraft.server.v1_13_R2.IChatBaseComponent)4 IChatBaseComponent (net.minecraft.server.v1_15_R1.IChatBaseComponent)4 IChatBaseComponent (net.minecraft.server.v1_16_R2.IChatBaseComponent)4 IChatBaseComponent (net.minecraft.server.v1_16_R3.IChatBaseComponent)4 IChatBaseComponent (net.minecraft.server.v1_9_R2.IChatBaseComponent)4 IChatBaseComponent (net.minecraft.server.v1_13_R1.IChatBaseComponent)3 IChatBaseComponent (net.minecraft.server.v1_16_R1.IChatBaseComponent)3 IChatBaseComponent (net.minecraft.server.v1_8_R2.IChatBaseComponent)3 IChatBaseComponent (net.minecraft.server.v1_9_R1.IChatBaseComponent)3