Search in sources :

Example 46 with IChatBaseComponent

use of net.minecraft.server.v1_16_R2.IChatBaseComponent in project FunnyGuilds by FunnyGuilds.

the class V1_11R1PlayerList method send.

@Override
public void send(Player player, String[] playerListCells, String header, String footer, int ping) {
    final List<Packet<?>> packets = Lists.newArrayList();
    final List<Object> addPlayerList = Lists.newArrayList();
    final List<Object> updatePlayerList = Lists.newArrayList();
    try {
        PacketPlayOutPlayerInfo addPlayerPacket = new PacketPlayOutPlayerInfo(EnumPlayerInfoAction.ADD_PLAYER);
        PacketPlayOutPlayerInfo updatePlayerPacket = new PacketPlayOutPlayerInfo(EnumPlayerInfoAction.UPDATE_DISPLAY_NAME);
        for (int i = 0; i < this.cellCount; i++) {
            if (this.profileCache[i] == null) {
                this.profileCache[i] = new GameProfile(UUID.fromString(String.format(PlayerListConstants.UUID_PATTERN, StringUtils.leftPad(String.valueOf(i), 2, '0'))), " ");
            }
            String text = playerListCells[i];
            GameProfile gameProfile = this.profileCache[i];
            IChatBaseComponent component = CraftChatMessage.fromString(text, false)[0];
            Object playerInfoData = PLAYER_INFO_DATA_HELPER.createPlayerInfoData(addPlayerPacket, gameProfile, ping, component);
            if (this.firstPacket) {
                addPlayerList.add(playerInfoData);
            }
            updatePlayerList.add(playerInfoData);
        }
        if (this.firstPacket) {
            this.firstPacket = false;
        }
        PLAYER_INFO_DATA_ACCESSOR.set(addPlayerPacket, addPlayerList);
        packets.add(addPlayerPacket);
        PLAYER_INFO_DATA_ACCESSOR.set(updatePlayerPacket, updatePlayerList);
        packets.add(updatePlayerPacket);
        boolean headerNotEmpty = !header.isEmpty();
        boolean footerNotEmpty = !footer.isEmpty();
        if (headerNotEmpty || footerNotEmpty) {
            IChatBaseComponent headerComponent = EMPTY_COMPONENT;
            IChatBaseComponent footerComponent = EMPTY_COMPONENT;
            if (headerNotEmpty) {
                headerComponent = CraftChatMessage.fromString(header, true)[0];
            }
            if (footerNotEmpty) {
                footerComponent = CraftChatMessage.fromString(footer, true)[0];
            }
            PacketPlayOutPlayerListHeaderFooter headerFooterPacket = new PacketPlayOutPlayerListHeaderFooter(headerComponent);
            FOOTER_ACCESSOR.set(headerFooterPacket, footerComponent);
            packets.add(headerFooterPacket);
        }
        for (Packet<?> packet : packets) {
            ((CraftPlayer) player).getHandle().playerConnection.sendPacket(packet);
        }
    } catch (Exception ex) {
        throw new RuntimeException(String.format("Failed to send PlayerList for player '%s'", player.getName()), ex);
    }
}
Also used : Packet(net.minecraft.server.v1_11_R1.Packet) IChatBaseComponent(net.minecraft.server.v1_11_R1.IChatBaseComponent) CraftPlayer(org.bukkit.craftbukkit.v1_11_R1.entity.CraftPlayer) PacketPlayOutPlayerListHeaderFooter(net.minecraft.server.v1_11_R1.PacketPlayOutPlayerListHeaderFooter) GameProfile(com.mojang.authlib.GameProfile) PacketPlayOutPlayerInfo(net.minecraft.server.v1_11_R1.PacketPlayOutPlayerInfo)

Example 47 with IChatBaseComponent

use of net.minecraft.server.v1_16_R2.IChatBaseComponent in project FunnyGuilds by FunnyGuilds.

the class V1_10R1PlayerList method send.

@Override
public void send(Player player, String[] playerListCells, String header, String footer, int ping) {
    final List<Packet<?>> packets = Lists.newArrayList();
    final List<Object> addPlayerList = Lists.newArrayList();
    final List<Object> updatePlayerList = Lists.newArrayList();
    try {
        PacketPlayOutPlayerInfo addPlayerPacket = new PacketPlayOutPlayerInfo(EnumPlayerInfoAction.ADD_PLAYER);
        PacketPlayOutPlayerInfo updatePlayerPacket = new PacketPlayOutPlayerInfo(EnumPlayerInfoAction.UPDATE_DISPLAY_NAME);
        for (int i = 0; i < this.cellCount; i++) {
            if (this.profileCache[i] == null) {
                this.profileCache[i] = new GameProfile(UUID.fromString(String.format(PlayerListConstants.UUID_PATTERN, StringUtils.leftPad(String.valueOf(i), 2, '0'))), " ");
            }
            String text = playerListCells[i];
            GameProfile gameProfile = this.profileCache[i];
            IChatBaseComponent component = CraftChatMessage.fromString(text, false)[0];
            Object playerInfoData = PLAYER_INFO_DATA_HELPER.createPlayerInfoData(addPlayerPacket, gameProfile, ping, component);
            if (this.firstPacket) {
                addPlayerList.add(playerInfoData);
            }
            updatePlayerList.add(playerInfoData);
        }
        if (this.firstPacket) {
            this.firstPacket = false;
        }
        PLAYER_INFO_DATA_ACCESSOR.set(addPlayerPacket, addPlayerList);
        packets.add(addPlayerPacket);
        PLAYER_INFO_DATA_ACCESSOR.set(updatePlayerPacket, updatePlayerList);
        packets.add(updatePlayerPacket);
        boolean headerNotEmpty = !header.isEmpty();
        boolean footerNotEmpty = !footer.isEmpty();
        if (headerNotEmpty || footerNotEmpty) {
            IChatBaseComponent headerComponent = EMPTY_COMPONENT;
            IChatBaseComponent footerComponent = EMPTY_COMPONENT;
            if (headerNotEmpty) {
                headerComponent = CraftChatMessage.fromString(header, true)[0];
            }
            if (footerNotEmpty) {
                footerComponent = CraftChatMessage.fromString(footer, true)[0];
            }
            PacketPlayOutPlayerListHeaderFooter headerFooterPacket = new PacketPlayOutPlayerListHeaderFooter(headerComponent);
            FOOTER_ACCESSOR.set(headerFooterPacket, footerComponent);
            packets.add(headerFooterPacket);
        }
        for (Packet<?> packet : packets) {
            ((CraftPlayer) player).getHandle().playerConnection.sendPacket(packet);
        }
    } catch (Exception ex) {
        throw new RuntimeException(String.format("Failed to send PlayerList for player '%s'", player.getName()), ex);
    }
}
Also used : Packet(net.minecraft.server.v1_10_R1.Packet) IChatBaseComponent(net.minecraft.server.v1_10_R1.IChatBaseComponent) CraftPlayer(org.bukkit.craftbukkit.v1_10_R1.entity.CraftPlayer) PacketPlayOutPlayerListHeaderFooter(net.minecraft.server.v1_10_R1.PacketPlayOutPlayerListHeaderFooter) GameProfile(com.mojang.authlib.GameProfile) PacketPlayOutPlayerInfo(net.minecraft.server.v1_10_R1.PacketPlayOutPlayerInfo)

Example 48 with IChatBaseComponent

use of net.minecraft.server.v1_16_R2.IChatBaseComponent in project UltraCosmetics by iSach.

the class AncientUtil method sendActionBarMessage.

@Override
public void sendActionBarMessage(Player player, String message) {
    CraftPlayer p = (CraftPlayer) player;
    IChatBaseComponent cbc = IChatBaseComponent.ChatSerializer.a("{\"text\": \"" + message + "\"}");
    PacketPlayOutChat ppoc = new PacketPlayOutChat(cbc, (byte) 2);
    p.getHandle().playerConnection.sendPacket(ppoc);
}
Also used : PacketPlayOutChat(net.minecraft.server.v1_8_R3.PacketPlayOutChat) CraftPlayer(org.bukkit.craftbukkit.v1_8_R3.entity.CraftPlayer) IChatBaseComponent(net.minecraft.server.v1_8_R3.IChatBaseComponent)

Example 49 with IChatBaseComponent

use of net.minecraft.server.v1_16_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_10_R1.IChatBaseComponent) ItemStack(org.bukkit.inventory.ItemStack) BookMeta(org.bukkit.inventory.meta.BookMeta)

Example 50 with IChatBaseComponent

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

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_13_R1.IChatBaseComponent)3 IChatBaseComponent (net.minecraft.server.v1_16_R1.IChatBaseComponent)3 IChatBaseComponent (net.minecraft.server.v1_9_R2.IChatBaseComponent)3 TextComponent (net.md_5.bungee.api.chat.TextComponent)2 IChatBaseComponent (net.minecraft.server.v1_8_R2.IChatBaseComponent)2