Search in sources :

Example 96 with IChatBaseComponent

use of net.minecraft.server.v1_8_R1.IChatBaseComponent in project CitizensBooks by NicoNekoDev.

the class DistributionHandler method convertJsonToBook.

@SuppressWarnings("ConstantConditions")
@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_14_R1.IChatBaseComponent) ItemStack(org.bukkit.inventory.ItemStack) BookMeta(org.bukkit.inventory.meta.BookMeta)

Example 97 with IChatBaseComponent

use of net.minecraft.server.v1_8_R1.IChatBaseComponent in project CitizensBooks by NicoNekoDev.

the class DistributionHandler method applyPlaceholders.

@SuppressWarnings({ "unchecked" })
@Override
public ItemStack applyPlaceholders(Player player, ItemStack book, NPC npc) throws IllegalAccessException {
    Validate.notNull(book, "The ItemStack is null! This is not an error with CitizensBooks," + " so please don't report it. Make sure the plugins that uses CitizensBooks as dependency are correctly configured.");
    Validate.isTrue(book.getType() == Material.WRITTEN_BOOK, "The ItemStack is not a written book! This is not an error with CitizensBooks," + " so please don't report it. Make sure the plugins that uses CitizensBooks as dependency are correctly configured.");
    BookMeta bookMeta = (BookMeta) book.getItemMeta();
    List<String> pages = bookMeta.hasPages() ? super.papiReplaceStrList.apply(player, ((List<IChatBaseComponent>) this.pagesField.get(bookMeta)).stream().map(IChatBaseComponent.ChatSerializer::a).toList(), Optional.ofNullable(npc)) : new ArrayList<>();
    String author = bookMeta.hasAuthor() ? super.papiReplaceStr.apply(player, bookMeta.getAuthor(), Optional.ofNullable(npc)) : "Server";
    String title = bookMeta.hasTitle() ? super.papiReplaceStr.apply(player, bookMeta.getTitle(), Optional.ofNullable(npc)) : "Title";
    ItemStack newBook = new ItemStack(Material.WRITTEN_BOOK);
    bookMeta.setAuthor(author);
    bookMeta.setTitle(title);
    this.pagesField.set(bookMeta, pages.stream().map(IChatBaseComponent.ChatSerializer::a).toList());
    newBook.setItemMeta(bookMeta);
    return newBook;
}
Also used : ArrayList(java.util.ArrayList) List(java.util.List) IChatBaseComponent(net.minecraft.server.v1_8_R2.IChatBaseComponent) ItemStack(org.bukkit.inventory.ItemStack) BookMeta(org.bukkit.inventory.meta.BookMeta)

Example 98 with IChatBaseComponent

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

Example 99 with IChatBaseComponent

use of net.minecraft.server.v1_8_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;
}
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 100 with IChatBaseComponent

use of net.minecraft.server.v1_8_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;
}
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)

Aggregations

ArrayList (java.util.ArrayList)76 BookMeta (org.bukkit.inventory.meta.BookMeta)41 Component (me.devtec.shared.components.Component)30 ItemStack (org.bukkit.inventory.ItemStack)28 GameProfile (com.mojang.authlib.GameProfile)23 IChatBaseComponent (net.minecraft.server.v1_12_R1.IChatBaseComponent)18 List (java.util.List)15 ServerListPingEvent (me.devtec.theapi.bukkit.events.ServerListPingEvent)15 PlayerProfile (me.devtec.theapi.bukkit.events.ServerListPingEvent.PlayerProfile)15 Player (org.bukkit.entity.Player)15 Channel (io.netty.channel.Channel)14 IChatBaseComponent (net.minecraft.server.v1_8_R3.IChatBaseComponent)14 IChatBaseComponent (net.minecraft.server.v1_10_R1.IChatBaseComponent)10 IChatBaseComponent (net.minecraft.server.v1_11_R1.IChatBaseComponent)10 IChatBaseComponent (net.minecraft.server.v1_14_R1.IChatBaseComponent)10 IChatBaseComponent (net.minecraft.server.v1_13_R2.IChatBaseComponent)9 IChatBaseComponent (net.minecraft.server.v1_15_R1.IChatBaseComponent)9 IChatBaseComponent (net.minecraft.server.v1_16_R3.IChatBaseComponent)9 IChatBaseComponent (net.minecraft.server.v1_16_R1.IChatBaseComponent)8 IChatBaseComponent (net.minecraft.server.v1_13_R1.IChatBaseComponent)7