Search in sources :

Example 96 with IChatBaseComponent

use of net.minecraft.server.v1_7_R4.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 97 with IChatBaseComponent

use of net.minecraft.server.v1_7_R4.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)

Example 98 with IChatBaseComponent

use of net.minecraft.server.v1_7_R4.IChatBaseComponent in project PowerBoard by Xitee1.

the class version_1_10 method sendTab.

@SuppressWarnings("deprecation")
public static void sendTab(Player player, String head, String foot) {
    IChatBaseComponent header = new ChatMessage(head);
    IChatBaseComponent footer = new ChatMessage(foot);
    PacketPlayOutPlayerListHeaderFooter tablist = new PacketPlayOutPlayerListHeaderFooter();
    try {
        Field headerField = tablist.getClass().getDeclaredField("a");
        headerField.setAccessible(true);
        headerField.set(tablist, header);
        headerField.setAccessible(!headerField.isAccessible());
        Field footerField = tablist.getClass().getDeclaredField("b");
        footerField.setAccessible(true);
        footerField.set(tablist, footer);
        footerField.setAccessible(!footerField.isAccessible());
    } catch (Exception e) {
        e.printStackTrace();
    }
    CraftPlayer cp = (CraftPlayer) player;
    cp.getHandle().playerConnection.sendPacket(tablist);
}
Also used : Field(java.lang.reflect.Field) PacketPlayOutPlayerListHeaderFooter(net.minecraft.server.v1_10_R1.PacketPlayOutPlayerListHeaderFooter) ChatMessage(net.minecraft.server.v1_10_R1.ChatMessage) IChatBaseComponent(net.minecraft.server.v1_10_R1.IChatBaseComponent) CraftPlayer(org.bukkit.craftbukkit.v1_10_R1.entity.CraftPlayer)

Example 99 with IChatBaseComponent

use of net.minecraft.server.v1_7_R4.IChatBaseComponent in project PowerBoard by Xitee1.

the class version_1_12 method sendTab.

@SuppressWarnings("deprecation")
public static void sendTab(Player p, String header, String footer) {
    IChatBaseComponent tabheader = ChatSerializer.a("{\"text\": \"" + header + "\"}");
    IChatBaseComponent tabfooter = ChatSerializer.a("{\"text\": \"" + footer + "\"}");
    PacketPlayOutPlayerListHeaderFooter tablist = new PacketPlayOutPlayerListHeaderFooter();
    try {
        Field headerField = tablist.getClass().getDeclaredField("a");
        headerField.setAccessible(true);
        headerField.set(tablist, tabheader);
        headerField.setAccessible(!headerField.isAccessible());
        Field footerField = tablist.getClass().getDeclaredField("b");
        footerField.setAccessible(true);
        footerField.set(tablist, tabfooter);
        footerField.setAccessible(!footerField.isAccessible());
    } catch (Exception var11) {
        var11.printStackTrace();
    } finally {
        ((CraftPlayer) p).getHandle().playerConnection.sendPacket(tablist);
    }
}
Also used : Field(java.lang.reflect.Field) PacketPlayOutPlayerListHeaderFooter(net.minecraft.server.v1_12_R1.PacketPlayOutPlayerListHeaderFooter) IChatBaseComponent(net.minecraft.server.v1_12_R1.IChatBaseComponent) CraftPlayer(org.bukkit.craftbukkit.v1_12_R1.entity.CraftPlayer)

Example 100 with IChatBaseComponent

use of net.minecraft.server.v1_7_R4.IChatBaseComponent in project TheAPI by TheDevTec.

the class v1_11_R1 method toIChatBaseComponents.

@Override
public Object toIChatBaseComponents(List<Component> components) {
    List<IChatBaseComponent> chat = new ArrayList<>();
    chat.add(new ChatComponentText(""));
    for (Component c : components) {
        if (c.getText() == null || c.getText().isEmpty()) {
            c = c.getExtra();
            continue;
        }
        ChatComponentText current = new ChatComponentText(c.getText());
        chat.add(current);
        ChatModifier modif = current.getChatModifier();
        if (c.getColor() != null && !c.getColor().isEmpty()) {
            modif = modif.setColor(EnumChatFormat.a(c.getColor().charAt(0)));
        }
        if (c.getClickEvent() != null)
            modif = modif.setChatClickable(new ChatClickable(EnumClickAction.valueOf(c.getClickEvent().getAction().name()), c.getClickEvent().getValue()));
        if (c.getHoverEvent() != null)
            modif = modif.setChatHoverable(new ChatHoverable(EnumHoverAction.valueOf(c.getHoverEvent().getAction().name()), (IChatBaseComponent) toIChatBaseComponent(c.getHoverEvent().getValue())));
        modif = modif.setBold(c.isBold());
        modif = modif.setItalic(c.isItalic());
        modif = modif.setRandom(c.isObfuscated());
        modif = modif.setUnderline(c.isUnderlined());
        modif = modif.setStrikethrough(c.isStrikethrough());
        current.setChatModifier(modif);
    }
    return chat.toArray(new IChatBaseComponent[0]);
}
Also used : ChatClickable(net.minecraft.server.v1_11_R1.ChatClickable) ArrayList(java.util.ArrayList) ChatModifier(net.minecraft.server.v1_11_R1.ChatModifier) IChatBaseComponent(net.minecraft.server.v1_11_R1.IChatBaseComponent) IChatBaseComponent(net.minecraft.server.v1_11_R1.IChatBaseComponent) Component(me.devtec.shared.components.Component) ChatComponentText(net.minecraft.server.v1_11_R1.ChatComponentText) ChatHoverable(net.minecraft.server.v1_11_R1.ChatHoverable)

Aggregations

ArrayList (java.util.ArrayList)74 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 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 List (java.util.List)14 IChatBaseComponent (net.minecraft.server.v1_12_R1.IChatBaseComponent)13 IChatBaseComponent (net.minecraft.server.v1_8_R3.IChatBaseComponent)13 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