Search in sources :

Example 96 with IChatBaseComponent

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

the class V1_10R1PlayerList method send.

@Override
public void send(Player player, String[] playerListCells, String header, String footer, SkinTexture[] cellTextures, int ping, Set<Integer> forceUpdateSlots) {
    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];
            if (this.firstPacket || forceUpdateSlots.contains(i)) {
                SkinTexture texture = cellTextures[i];
                if (texture != null) {
                    gameProfile.getProperties().removeAll("textures");
                    gameProfile.getProperties().put("textures", texture.getProperty());
                }
            }
            Object playerInfoData = PLAYER_INFO_DATA_HELPER.createPlayerInfoData(addPlayerPacket, gameProfile, ping, component);
            if (this.firstPacket || forceUpdateSlots.contains(i)) {
                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) SkinTexture(net.dzikoysk.funnyguilds.nms.api.playerlist.SkinTexture)

Example 97 with IChatBaseComponent

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

the class V1_16R3PlayerList method send.

@Override
public void send(Player player, String[] playerListCells, String header, String footer, SkinTexture[] cellTextures, int ping, Set<Integer> forceUpdateSlots) {
    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.fromStringOrNull(text, false);
            if (this.firstPacket || forceUpdateSlots.contains(i)) {
                SkinTexture texture = cellTextures[i];
                if (texture != null) {
                    gameProfile.getProperties().removeAll("textures");
                    gameProfile.getProperties().put("textures", texture.getProperty());
                }
            }
            Object playerInfoData = PLAYER_INFO_DATA_HELPER.createPlayerInfoData(addPlayerPacket, gameProfile, ping, component);
            if (this.firstPacket || forceUpdateSlots.contains(i)) {
                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.fromStringOrNull(header, true);
            }
            if (footerNotEmpty) {
                footerComponent = CraftChatMessage.fromStringOrNull(footer, true);
            }
            PacketPlayOutPlayerListHeaderFooter headerFooterPacket = new PacketPlayOutPlayerListHeaderFooter();
            headerFooterPacket.header = headerComponent;
            headerFooterPacket.footer = 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_16_R3.Packet) IChatBaseComponent(net.minecraft.server.v1_16_R3.IChatBaseComponent) CraftPlayer(org.bukkit.craftbukkit.v1_16_R3.entity.CraftPlayer) PacketPlayOutPlayerListHeaderFooter(net.minecraft.server.v1_16_R3.PacketPlayOutPlayerListHeaderFooter) GameProfile(com.mojang.authlib.GameProfile) PacketPlayOutPlayerInfo(net.minecraft.server.v1_16_R3.PacketPlayOutPlayerInfo) SkinTexture(net.dzikoysk.funnyguilds.nms.api.playerlist.SkinTexture)

Example 98 with IChatBaseComponent

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

the class V1_15R1PlayerList method send.

@Override
public void send(Player player, String[] playerListCells, String header, String footer, SkinTexture[] cellTextures, int ping, Set<Integer> forceUpdateSlots) {
    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.fromStringOrNull(text, false);
            if (this.firstPacket || forceUpdateSlots.contains(i)) {
                SkinTexture texture = cellTextures[i];
                if (texture != null) {
                    gameProfile.getProperties().removeAll("textures");
                    gameProfile.getProperties().put("textures", texture.getProperty());
                }
            }
            Object playerInfoData = PLAYER_INFO_DATA_HELPER.createPlayerInfoData(addPlayerPacket, gameProfile, ping, component);
            if (this.firstPacket || forceUpdateSlots.contains(i)) {
                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.fromStringOrNull(header, true);
            }
            if (footerNotEmpty) {
                footerComponent = CraftChatMessage.fromStringOrNull(footer, true);
            }
            PacketPlayOutPlayerListHeaderFooter headerFooterPacket = new PacketPlayOutPlayerListHeaderFooter();
            headerFooterPacket.header = headerComponent;
            headerFooterPacket.footer = 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_15_R1.Packet) IChatBaseComponent(net.minecraft.server.v1_15_R1.IChatBaseComponent) CraftPlayer(org.bukkit.craftbukkit.v1_15_R1.entity.CraftPlayer) PacketPlayOutPlayerListHeaderFooter(net.minecraft.server.v1_15_R1.PacketPlayOutPlayerListHeaderFooter) GameProfile(com.mojang.authlib.GameProfile) PacketPlayOutPlayerInfo(net.minecraft.server.v1_15_R1.PacketPlayOutPlayerInfo) SkinTexture(net.dzikoysk.funnyguilds.nms.api.playerlist.SkinTexture)

Example 99 with IChatBaseComponent

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

the class V1_9R2PlayerList method send.

@Override
public void send(Player player, String[] playerListCells, String header, String footer, SkinTexture[] cellTextures, int ping, Set<Integer> forceUpdateSlots) {
    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];
            if (this.firstPacket || forceUpdateSlots.contains(i)) {
                SkinTexture texture = cellTextures[i];
                if (texture != null) {
                    gameProfile.getProperties().removeAll("textures");
                    gameProfile.getProperties().put("textures", texture.getProperty());
                }
            }
            Object playerInfoData = PLAYER_INFO_DATA_HELPER.createPlayerInfoData(addPlayerPacket, gameProfile, ping, component);
            if (this.firstPacket || forceUpdateSlots.contains(i)) {
                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_9_R2.Packet) IChatBaseComponent(net.minecraft.server.v1_9_R2.IChatBaseComponent) CraftPlayer(org.bukkit.craftbukkit.v1_9_R2.entity.CraftPlayer) PacketPlayOutPlayerListHeaderFooter(net.minecraft.server.v1_9_R2.PacketPlayOutPlayerListHeaderFooter) GameProfile(com.mojang.authlib.GameProfile) PacketPlayOutPlayerInfo(net.minecraft.server.v1_9_R2.PacketPlayOutPlayerInfo) SkinTexture(net.dzikoysk.funnyguilds.nms.api.playerlist.SkinTexture)

Example 100 with IChatBaseComponent

use of net.minecraft.server.v1_10_R1.IChatBaseComponent in project RoseStacker by Rosewood-Development.

the class HologramImpl method update.

@Override
protected void update(Player player) {
    Boolean visible = this.watchers.get(player);
    if (visible == null)
        return;
    List<DataWatcher.Item<?>> dataItems = new ArrayList<>();
    Optional<IChatBaseComponent> nameComponent = Optional.of(CraftChatMessage.fromStringOrNull(this.text));
    dataItems.add(new DataWatcher.Item<>(DataWatcherRegistry.f.a(2), nameComponent));
    dataItems.add(new DataWatcher.Item<>(DataWatcherRegistry.i.a(3), visible));
    dataItems.add(new DataWatcher.Item<>(DataWatcherRegistry.c.a(7), 0.5F));
    dataItems.add(new DataWatcher.Item<>(DataWatcherRegistry.i.a(9), true));
    dataItems.add(new DataWatcher.Item<>(DataWatcherRegistry.j.a(10), new ParticleParamBlock(Particles.BLOCK, Blocks.AIR.getBlockData())));
    PacketPlayOutEntityMetadata packet = new PacketPlayOutEntityMetadata(this.entityId, new DataWatcherWrapper(dataItems), false);
    ((CraftPlayer) player).getHandle().playerConnection.sendPacket(packet);
}
Also used : ArrayList(java.util.ArrayList) PacketPlayOutEntityMetadata(net.minecraft.server.v1_16_R2.PacketPlayOutEntityMetadata) IChatBaseComponent(net.minecraft.server.v1_16_R2.IChatBaseComponent) DataWatcherWrapper(dev.rosewood.rosestacker.nms.v1_16_R2.entity.DataWatcherWrapper) CraftPlayer(org.bukkit.craftbukkit.v1_16_R2.entity.CraftPlayer) ParticleParamBlock(net.minecraft.server.v1_16_R2.ParticleParamBlock) DataWatcher(net.minecraft.server.v1_16_R2.DataWatcher)

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