Search in sources :

Example 1 with SkinTexture

use of net.dzikoysk.funnyguilds.nms.api.playerlist.SkinTexture in project FunnyGuilds by FunnyGuilds.

the class V1_8R3PlayerList 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_8_R3.Packet) IChatBaseComponent(net.minecraft.server.v1_8_R3.IChatBaseComponent) CraftPlayer(org.bukkit.craftbukkit.v1_8_R3.entity.CraftPlayer) PacketPlayOutPlayerListHeaderFooter(net.minecraft.server.v1_8_R3.PacketPlayOutPlayerListHeaderFooter) GameProfile(com.mojang.authlib.GameProfile) PacketPlayOutPlayerInfo(net.minecraft.server.v1_8_R3.PacketPlayOutPlayerInfo) SkinTexture(net.dzikoysk.funnyguilds.nms.api.playerlist.SkinTexture)

Example 2 with SkinTexture

use of net.dzikoysk.funnyguilds.nms.api.playerlist.SkinTexture in project FunnyGuilds by FunnyGuilds.

the class V1_11R1PlayerList 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_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) SkinTexture(net.dzikoysk.funnyguilds.nms.api.playerlist.SkinTexture)

Example 3 with SkinTexture

use of net.dzikoysk.funnyguilds.nms.api.playerlist.SkinTexture in project FunnyGuilds by FunnyGuilds.

the class V1_18R1PlayerList 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<PacketPlayOutPlayerInfo.PlayerInfoData> addPlayerList = Lists.newArrayList();
    final List<PacketPlayOutPlayerInfo.PlayerInfoData> updatePlayerList = Lists.newArrayList();
    try {
        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());
                }
            }
            PacketPlayOutPlayerInfo.PlayerInfoData playerInfoData = new PacketPlayOutPlayerInfo.PlayerInfoData(gameProfile, ping, DEFAULT_GAME_MODE, component);
            if (this.firstPacket || forceUpdateSlots.contains(i)) {
                addPlayerList.add(playerInfoData);
            }
            updatePlayerList.add(playerInfoData);
        }
        if (this.firstPacket) {
            this.firstPacket = false;
        }
        PacketPlayOutPlayerInfo addPlayerPacket = new PacketPlayOutPlayerInfo(EnumPlayerInfoAction.a);
        addPlayerPacket.b().addAll(addPlayerList);
        packets.add(addPlayerPacket);
        PacketPlayOutPlayerInfo updatePlayerPacket = new PacketPlayOutPlayerInfo(EnumPlayerInfoAction.d);
        updatePlayerPacket.b().addAll(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(headerComponent, footerComponent);
            packets.add(headerFooterPacket);
        }
        for (Packet<?> packet : packets) {
            ((CraftPlayer) player).getHandle().b.a(packet);
        }
    } catch (Exception ex) {
        throw new RuntimeException(String.format("Failed to send PlayerList for player '%s'", player.getName()), ex);
    }
}
Also used : Packet(net.minecraft.network.protocol.Packet) IChatBaseComponent(net.minecraft.network.chat.IChatBaseComponent) CraftPlayer(org.bukkit.craftbukkit.v1_18_R1.entity.CraftPlayer) PacketPlayOutPlayerListHeaderFooter(net.minecraft.network.protocol.game.PacketPlayOutPlayerListHeaderFooter) GameProfile(com.mojang.authlib.GameProfile) PacketPlayOutPlayerInfo(net.minecraft.network.protocol.game.PacketPlayOutPlayerInfo) SkinTexture(net.dzikoysk.funnyguilds.nms.api.playerlist.SkinTexture)

Example 4 with SkinTexture

use of net.dzikoysk.funnyguilds.nms.api.playerlist.SkinTexture in project FunnyGuilds by FunnyGuilds.

the class V1_12R1PlayerList 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();
            HEADER_ACCESSOR.set(headerFooterPacket, 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_12_R1.Packet) IChatBaseComponent(net.minecraft.server.v1_12_R1.IChatBaseComponent) CraftPlayer(org.bukkit.craftbukkit.v1_12_R1.entity.CraftPlayer) PacketPlayOutPlayerListHeaderFooter(net.minecraft.server.v1_12_R1.PacketPlayOutPlayerListHeaderFooter) GameProfile(com.mojang.authlib.GameProfile) PacketPlayOutPlayerInfo(net.minecraft.server.v1_12_R1.PacketPlayOutPlayerInfo) SkinTexture(net.dzikoysk.funnyguilds.nms.api.playerlist.SkinTexture)

Example 5 with SkinTexture

use of net.dzikoysk.funnyguilds.nms.api.playerlist.SkinTexture in project FunnyGuilds by FunnyGuilds.

the class V1_13R2PlayerList 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_13_R2.Packet) IChatBaseComponent(net.minecraft.server.v1_13_R2.IChatBaseComponent) CraftPlayer(org.bukkit.craftbukkit.v1_13_R2.entity.CraftPlayer) PacketPlayOutPlayerListHeaderFooter(net.minecraft.server.v1_13_R2.PacketPlayOutPlayerListHeaderFooter) GameProfile(com.mojang.authlib.GameProfile) PacketPlayOutPlayerInfo(net.minecraft.server.v1_13_R2.PacketPlayOutPlayerInfo) SkinTexture(net.dzikoysk.funnyguilds.nms.api.playerlist.SkinTexture)

Aggregations

SkinTexture (net.dzikoysk.funnyguilds.nms.api.playerlist.SkinTexture)13 GameProfile (com.mojang.authlib.GameProfile)12 IChatBaseComponent (net.minecraft.network.chat.IChatBaseComponent)3 Packet (net.minecraft.network.protocol.Packet)3 PacketPlayOutPlayerInfo (net.minecraft.network.protocol.game.PacketPlayOutPlayerInfo)3 PacketPlayOutPlayerListHeaderFooter (net.minecraft.network.protocol.game.PacketPlayOutPlayerListHeaderFooter)3 TablistPage (net.dzikoysk.funnyguilds.config.tablist.TablistPage)1 IChatBaseComponent (net.minecraft.server.v1_10_R1.IChatBaseComponent)1 Packet (net.minecraft.server.v1_10_R1.Packet)1 PacketPlayOutPlayerInfo (net.minecraft.server.v1_10_R1.PacketPlayOutPlayerInfo)1 PacketPlayOutPlayerListHeaderFooter (net.minecraft.server.v1_10_R1.PacketPlayOutPlayerListHeaderFooter)1 IChatBaseComponent (net.minecraft.server.v1_11_R1.IChatBaseComponent)1 Packet (net.minecraft.server.v1_11_R1.Packet)1 PacketPlayOutPlayerInfo (net.minecraft.server.v1_11_R1.PacketPlayOutPlayerInfo)1 PacketPlayOutPlayerListHeaderFooter (net.minecraft.server.v1_11_R1.PacketPlayOutPlayerListHeaderFooter)1 IChatBaseComponent (net.minecraft.server.v1_12_R1.IChatBaseComponent)1 Packet (net.minecraft.server.v1_12_R1.Packet)1 PacketPlayOutPlayerInfo (net.minecraft.server.v1_12_R1.PacketPlayOutPlayerInfo)1 PacketPlayOutPlayerListHeaderFooter (net.minecraft.server.v1_12_R1.PacketPlayOutPlayerListHeaderFooter)1 IChatBaseComponent (net.minecraft.server.v1_13_R2.IChatBaseComponent)1