Search in sources :

Example 1 with PacketPlayOutPlayerInfo

use of net.minecraft.network.protocol.game.PacketPlayOutPlayerInfo in project FunnyGuilds by FunnyGuilds.

the class V1_18R1PlayerList method send.

@Override
public void send(Player player, String[] playerListCells, String header, String footer, int ping) {
    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);
            PacketPlayOutPlayerInfo.PlayerInfoData playerInfoData = new PacketPlayOutPlayerInfo.PlayerInfoData(gameProfile, ping, DEFAULT_GAME_MODE, component);
            if (this.firstPacket) {
                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)

Example 2 with PacketPlayOutPlayerInfo

use of net.minecraft.network.protocol.game.PacketPlayOutPlayerInfo in project FunnyGuilds by FunnyGuilds.

the class V1_17R1PlayerList method send.

@Override
public void send(Player player, String[] playerListCells, String header, String footer, int ping) {
    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);
            PacketPlayOutPlayerInfo.PlayerInfoData playerInfoData = new PacketPlayOutPlayerInfo.PlayerInfoData(gameProfile, ping, DEFAULT_GAME_MODE, component);
            if (this.firstPacket) {
                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.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.network.protocol.Packet) IChatBaseComponent(net.minecraft.network.chat.IChatBaseComponent) CraftPlayer(org.bukkit.craftbukkit.v1_17_R1.entity.CraftPlayer) PacketPlayOutPlayerListHeaderFooter(net.minecraft.network.protocol.game.PacketPlayOutPlayerListHeaderFooter) GameProfile(com.mojang.authlib.GameProfile) PacketPlayOutPlayerInfo(net.minecraft.network.protocol.game.PacketPlayOutPlayerInfo)

Example 3 with PacketPlayOutPlayerInfo

use of net.minecraft.network.protocol.game.PacketPlayOutPlayerInfo in project Nexus by ProjectEdenGG.

the class FakeNPCPacketUtils method spawnFakeNPC.

// NPCs
public static void spawnFakeNPC(HasPlayer hasPlayer, FakeNPC fakeNPC) {
    EntityPlayer entityPlayer = fakeNPC.getEntityPlayer();
    PacketPlayOutPlayerInfo playerInfoPacket = new PacketPlayOutPlayerInfo(EnumPlayerInfoAction.a, entityPlayer);
    PacketPlayOutNamedEntitySpawn spawnPacket = new PacketPlayOutNamedEntitySpawn(entityPlayer);
    PacketPlayOutEntityHeadRotation headRotationPacket = new PacketPlayOutEntityHeadRotation(entityPlayer, PacketUtils.encodeAngle(fakeNPC.getLocation().getYaw()));
    // untested
    DataWatcher dataWatcher = entityPlayer.getDataWatcher();
    dataWatcher.set(new DataWatcherObject<>(16, DataWatcherRegistry.a), (byte) 127);
    sendPacket(hasPlayer, playerInfoPacket, spawnPacket, headRotationPacket);
    spawnHologram(hasPlayer, fakeNPC);
}
Also used : PacketPlayOutNamedEntitySpawn(net.minecraft.network.protocol.game.PacketPlayOutNamedEntitySpawn) PacketPlayOutEntityHeadRotation(net.minecraft.network.protocol.game.PacketPlayOutEntityHeadRotation) EntityPlayer(net.minecraft.server.level.EntityPlayer) PacketPlayOutPlayerInfo(net.minecraft.network.protocol.game.PacketPlayOutPlayerInfo) DataWatcher(net.minecraft.network.syncher.DataWatcher)

Aggregations

PacketPlayOutPlayerInfo (net.minecraft.network.protocol.game.PacketPlayOutPlayerInfo)3 GameProfile (com.mojang.authlib.GameProfile)2 IChatBaseComponent (net.minecraft.network.chat.IChatBaseComponent)2 Packet (net.minecraft.network.protocol.Packet)2 PacketPlayOutPlayerListHeaderFooter (net.minecraft.network.protocol.game.PacketPlayOutPlayerListHeaderFooter)2 PacketPlayOutEntityHeadRotation (net.minecraft.network.protocol.game.PacketPlayOutEntityHeadRotation)1 PacketPlayOutNamedEntitySpawn (net.minecraft.network.protocol.game.PacketPlayOutNamedEntitySpawn)1 DataWatcher (net.minecraft.network.syncher.DataWatcher)1 EntityPlayer (net.minecraft.server.level.EntityPlayer)1 CraftPlayer (org.bukkit.craftbukkit.v1_17_R1.entity.CraftPlayer)1 CraftPlayer (org.bukkit.craftbukkit.v1_18_R1.entity.CraftPlayer)1