Search in sources :

Example 81 with IChatBaseComponent

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

the class DistributionHandler method convertBookToJson.

@SuppressWarnings({ "unchecked" })
@Override
public JsonObject convertBookToJson(ItemStack book) throws IllegalAccessException {
    BookMeta bookMeta = (BookMeta) book.getItemMeta();
    List<IChatBaseComponent> pages = bookMeta.hasPages() ? (List<IChatBaseComponent>) this.pagesField.get(bookMeta) : new ArrayList<>();
    JsonArray jsonPages = new JsonArray();
    for (IChatBaseComponent page : pages) {
        jsonPages.add(super.gson.fromJson(IChatBaseComponent.ChatSerializer.a(page), JsonElement.class));
    }
    JsonPrimitive jsonAuthor = new JsonPrimitive(bookMeta.hasAuthor() ? bookMeta.getAuthor() : "Server");
    JsonPrimitive jsonTitle = new JsonPrimitive(bookMeta.hasTitle() ? bookMeta.getTitle() : "Title");
    JsonObject jsonBook = new JsonObject();
    jsonBook.add("author", jsonAuthor);
    jsonBook.add("title", jsonTitle);
    jsonBook.add("pages", jsonPages);
    return jsonBook;
}
Also used : IChatBaseComponent(net.minecraft.server.v1_9_R2.IChatBaseComponent) BookMeta(org.bukkit.inventory.meta.BookMeta)

Example 82 with IChatBaseComponent

use of net.minecraft.server.v1_10_R1.IChatBaseComponent in project HitW-plugin by Blackoutburst.

the class GameUtils method sendTitle.

public static void sendTitle(Player player, String title, String subtitle, int fadeIn, int stay, int fadeOut) {
    CraftPlayer craftplayer = (CraftPlayer) player;
    PlayerConnection connection = craftplayer.getHandle().playerConnection;
    IChatBaseComponent titleJSON = ChatSerializer.a("{'text': '" + title + "'}");
    IChatBaseComponent subtitleJSON = ChatSerializer.a("{'text': '" + subtitle + "'}");
    PacketPlayOutTitle timePacket = new PacketPlayOutTitle(fadeIn, stay, fadeOut);
    PacketPlayOutTitle titlePacket = new PacketPlayOutTitle(EnumTitleAction.TITLE, titleJSON);
    PacketPlayOutTitle subtitlePacket = new PacketPlayOutTitle(EnumTitleAction.SUBTITLE, subtitleJSON);
    connection.sendPacket(timePacket);
    connection.sendPacket(titlePacket);
    connection.sendPacket(subtitlePacket);
}
Also used : PacketPlayOutTitle(net.minecraft.server.v1_8_R3.PacketPlayOutTitle) CraftPlayer(org.bukkit.craftbukkit.v1_8_R3.entity.CraftPlayer) IChatBaseComponent(net.minecraft.server.v1_8_R3.IChatBaseComponent) PlayerConnection(net.minecraft.server.v1_8_R3.PlayerConnection)

Example 83 with IChatBaseComponent

use of net.minecraft.server.v1_10_R1.IChatBaseComponent in project Ublisk by Derkades.

the class V1_12_R1 method sendActionBarMessage.

@Override
public void sendActionBarMessage(Player player, String message) {
    IChatBaseComponent dummyComponent = ChatSerializer.a("{\"text\":\"herobrine1337\"}");
    PacketPlayOutChat packet = new PacketPlayOutChat(dummyComponent, ChatMessageType.GAME_INFO);
    packet.components = new BaseComponent[] { new TextComponent(message) };
    CraftPlayer craftPlayer = (CraftPlayer) player;
    craftPlayer.getHandle().playerConnection.sendPacket(packet);
}
Also used : TextComponent(net.md_5.bungee.api.chat.TextComponent) PacketPlayOutChat(net.minecraft.server.v1_12_R1.PacketPlayOutChat) IChatBaseComponent(net.minecraft.server.v1_12_R1.IChatBaseComponent) CraftPlayer(org.bukkit.craftbukkit.v1_12_R1.entity.CraftPlayer)

Example 84 with IChatBaseComponent

use of net.minecraft.server.v1_10_R1.IChatBaseComponent in project FireAPI by FireBlade-Serv.

the class FireTitle method send.

public void send() {
    IChatBaseComponent basetitle = ChatSerializer.a("{\"text\": \"" + this.title + "\"}");
    IChatBaseComponent basesubtitle = ChatSerializer.a("{\"text\": \"" + this.subtitle + "\"}");
    PacketPlayOutTitle titlepacket = new PacketPlayOutTitle(EnumTitleAction.TITLE, basetitle);
    PacketPlayOutTitle subtitlepacket = new PacketPlayOutTitle(EnumTitleAction.SUBTITLE, basesubtitle);
    ((CraftPlayer) this.player).getHandle().playerConnection.sendPacket(titlepacket);
    ((CraftPlayer) this.player).getHandle().playerConnection.sendPacket(subtitlepacket);
    sendTime();
}
Also used : PacketPlayOutTitle(net.minecraft.server.v1_8_R3.PacketPlayOutTitle) IChatBaseComponent(net.minecraft.server.v1_8_R3.IChatBaseComponent) CraftPlayer(org.bukkit.craftbukkit.v1_8_R3.entity.CraftPlayer)

Example 85 with IChatBaseComponent

use of net.minecraft.server.v1_10_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_10_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 GameProfile (com.mojang.authlib.GameProfile)32 Component (me.devtec.shared.components.Component)30 ItemStack (org.bukkit.inventory.ItemStack)28 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)14 IChatBaseComponent (net.minecraft.server.v1_8_R3.IChatBaseComponent)14 IChatBaseComponent (net.minecraft.server.v1_10_R1.IChatBaseComponent)11 IChatBaseComponent (net.minecraft.server.v1_11_R1.IChatBaseComponent)11 IChatBaseComponent (net.minecraft.server.v1_14_R1.IChatBaseComponent)11 IChatBaseComponent (net.minecraft.server.v1_16_R3.IChatBaseComponent)11 IChatBaseComponent (net.minecraft.server.v1_13_R2.IChatBaseComponent)10 IChatBaseComponent (net.minecraft.server.v1_15_R1.IChatBaseComponent)10 SkinTexture (net.dzikoysk.funnyguilds.nms.api.playerlist.SkinTexture)9 IChatBaseComponent (net.minecraft.server.v1_16_R1.IChatBaseComponent)8