Search in sources :

Example 6 with PacketPlayOutPlayerInfo

use of net.minecraft.server.v1_14_R1.PacketPlayOutPlayerInfo in project DragonsOnline by UniverseCraft.

the class PlayerNPC116R3 method addToTablist.

public void addToTablist() {
    PacketPlayOutPlayerInfo packet = new PacketPlayOutPlayerInfo();
    PacketPlayOutPlayerInfo.PlayerInfoData data = packet.new PlayerInfoData(this.handle.getProfile(), 0, EnumGamemode.NOT_SET, CraftChatMessage.fromString(tablistName)[0]);
    @SuppressWarnings("unchecked") List<PacketPlayOutPlayerInfo.PlayerInfoData> players = (List<PacketPlayOutPlayerInfo.PlayerInfoData>) getField(packet, "b");
    players.add(data);
    this.setField(packet, "a", PacketPlayOutPlayerInfo.EnumPlayerInfoAction.ADD_PLAYER);
    this.setField(packet, "b", players);
    this.sendPacket(packet);
}
Also used : List(java.util.List) ArrayList(java.util.ArrayList) PacketPlayOutPlayerInfo(net.minecraft.server.v1_16_R3.PacketPlayOutPlayerInfo)

Example 7 with PacketPlayOutPlayerInfo

use of net.minecraft.server.v1_14_R1.PacketPlayOutPlayerInfo in project DragonsOnline by UniverseCraft.

the class PlayerNPC116R3 method removeFromTablistFor.

public void removeFromTablistFor(Player player) {
    PacketPlayOutPlayerInfo packet = new PacketPlayOutPlayerInfo();
    PacketPlayOutPlayerInfo.PlayerInfoData data = packet.new PlayerInfoData(this.handle.getProfile(), 0, EnumGamemode.NOT_SET, CraftChatMessage.fromString(tablistName)[0]);
    @SuppressWarnings("unchecked") List<PacketPlayOutPlayerInfo.PlayerInfoData> players = (List<PacketPlayOutPlayerInfo.PlayerInfoData>) getField(packet, "b");
    players.add(data);
    this.setField(packet, "a", PacketPlayOutPlayerInfo.EnumPlayerInfoAction.REMOVE_PLAYER);
    this.setField(packet, "b", players);
    this.sendPacket(packet, player);
}
Also used : List(java.util.List) ArrayList(java.util.ArrayList) PacketPlayOutPlayerInfo(net.minecraft.server.v1_16_R3.PacketPlayOutPlayerInfo)

Example 8 with PacketPlayOutPlayerInfo

use of net.minecraft.server.v1_14_R1.PacketPlayOutPlayerInfo in project DragonsOnline by UniverseCraft.

the class PlayerNPC116R3 method spawnFor.

public void spawnFor(Player player) {
    if (isDestroyed)
        return;
    // resync
    location = getEntity().getLocation();
    location.setYaw(originalYaw);
    handle.setCustomNameVisible(false);
    sendPacket(new PacketPlayOutPlayerInfo(PacketPlayOutPlayerInfo.EnumPlayerInfoAction.ADD_PLAYER, handle), player);
    sync(() -> sendPacket(new PacketPlayOutNamedEntitySpawn(handle), player), 1);
    PacketPlayOutEntityTeleport tp = new PacketPlayOutEntityTeleport();
    setField(tp, "a", getEntityId());
    setField(tp, "b", location.getX());
    setField(tp, "c", location.getY());
    setField(tp, "d", location.getZ());
    setField(tp, "e", getPacketRotation(location.getYaw()));
    setField(tp, "f", getPacketRotation(location.getPitch()));
    setField(tp, "g", handle.isOnGround());
    sync(() -> sendPacket(new PacketPlayOutEntityMetadata(handle.getId(), handle.getDataWatcher(), true), player), 2);
    sync(() -> setTablistName(getTablistName()), 2);
    sync(() -> sendPacket(tp, player), 3);
    sync(() -> sendPacket(new PacketPlayOutEntityHeadRotation(handle, getPacketRotation(location.getYaw())), player), 6);
    sync(() -> removeFromTablistFor(player), 20 + (int) Math.ceil(2 * bridge.getPing(player) * 20 / 1000));
    lastSeenLocation.put(player, location.clone());
    // https://www.spigotmc.org/threads/remove-nameplate-of-an-nms-player-entity.436099/ (Phaze)
    ScoreboardTeam team = new ScoreboardTeam(((CraftScoreboard) Bukkit.getScoreboardManager().getMainScoreboard()).getHandle(), player.getName());
    team.setNameTagVisibility(ScoreboardTeamBase.EnumNameTagVisibility.NEVER);
    sendPacket(new PacketPlayOutScoreboardTeam(team, 1), player);
    sendPacket(new PacketPlayOutScoreboardTeam(team, 0), player);
    sendPacket(new PacketPlayOutScoreboardTeam(team, List.of(handle.getName()), 3), player);
}
Also used : PacketPlayOutScoreboardTeam(net.minecraft.server.v1_16_R3.PacketPlayOutScoreboardTeam) PacketPlayOutNamedEntitySpawn(net.minecraft.server.v1_16_R3.PacketPlayOutNamedEntitySpawn) PacketPlayOutEntityMetadata(net.minecraft.server.v1_16_R3.PacketPlayOutEntityMetadata) PacketPlayOutEntityHeadRotation(net.minecraft.server.v1_16_R3.PacketPlayOutEntityHeadRotation) PacketPlayOutPlayerInfo(net.minecraft.server.v1_16_R3.PacketPlayOutPlayerInfo) PacketPlayOutEntityTeleport(net.minecraft.server.v1_16_R3.PacketPlayOutEntityTeleport) PacketPlayOutScoreboardTeam(net.minecraft.server.v1_16_R3.PacketPlayOutScoreboardTeam) ScoreboardTeam(net.minecraft.server.v1_16_R3.ScoreboardTeam)

Example 9 with PacketPlayOutPlayerInfo

use of net.minecraft.server.v1_14_R1.PacketPlayOutPlayerInfo in project DragonsOnline by UniverseCraft.

the class PlayerNPC116R3 method removeFromTablist.

public void removeFromTablist() {
    PacketPlayOutPlayerInfo packet = new PacketPlayOutPlayerInfo();
    PacketPlayOutPlayerInfo.PlayerInfoData data = packet.new PlayerInfoData(this.handle.getProfile(), 0, EnumGamemode.NOT_SET, CraftChatMessage.fromString(tablistName)[0]);
    @SuppressWarnings("unchecked") List<PacketPlayOutPlayerInfo.PlayerInfoData> players = (List<PacketPlayOutPlayerInfo.PlayerInfoData>) getField(packet, "b");
    players.add(data);
    this.setField(packet, "a", PacketPlayOutPlayerInfo.EnumPlayerInfoAction.REMOVE_PLAYER);
    this.setField(packet, "b", players);
    this.sendPacket(packet);
}
Also used : List(java.util.List) ArrayList(java.util.ArrayList) PacketPlayOutPlayerInfo(net.minecraft.server.v1_16_R3.PacketPlayOutPlayerInfo)

Example 10 with PacketPlayOutPlayerInfo

use of net.minecraft.server.v1_14_R1.PacketPlayOutPlayerInfo in project FunnyGuilds by FunnyGuilds.

the class V1_14R1PlayerList 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.fromStringOrNull(text, false);
            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.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_14_R1.Packet) IChatBaseComponent(net.minecraft.server.v1_14_R1.IChatBaseComponent) CraftPlayer(org.bukkit.craftbukkit.v1_14_R1.entity.CraftPlayer) PacketPlayOutPlayerListHeaderFooter(net.minecraft.server.v1_14_R1.PacketPlayOutPlayerListHeaderFooter) GameProfile(com.mojang.authlib.GameProfile) PacketPlayOutPlayerInfo(net.minecraft.server.v1_14_R1.PacketPlayOutPlayerInfo)

Aggregations

GameProfile (com.mojang.authlib.GameProfile)13 PacketPlayOutPlayerInfo (net.minecraft.server.v1_16_R3.PacketPlayOutPlayerInfo)9 SkinnableEntity (net.citizensnpcs.npc.skin.SkinnableEntity)8 PacketPlayOutPlayerInfo (net.minecraft.server.v1_10_R1.PacketPlayOutPlayerInfo)6 PacketPlayOutPlayerInfo (net.minecraft.server.v1_11_R1.PacketPlayOutPlayerInfo)6 PacketPlayOutPlayerInfo (net.minecraft.server.v1_8_R3.PacketPlayOutPlayerInfo)6 ArrayList (java.util.ArrayList)4 List (java.util.List)4 UUID (java.util.UUID)4 EntityPlayer (net.minecraft.server.v1_10_R1.EntityPlayer)4 EntityPlayer (net.minecraft.server.v1_11_R1.EntityPlayer)4 PacketPlayOutPlayerInfo (net.minecraft.server.v1_12_R1.PacketPlayOutPlayerInfo)4 PacketPlayOutPlayerInfo (net.minecraft.server.v1_13_R2.PacketPlayOutPlayerInfo)4 PacketPlayOutPlayerInfo (net.minecraft.server.v1_14_R1.PacketPlayOutPlayerInfo)4 PacketPlayOutPlayerInfo (net.minecraft.server.v1_15_R1.PacketPlayOutPlayerInfo)4 Player (org.bukkit.entity.Player)4 BukkitRunnable (org.bukkit.scheduler.BukkitRunnable)4 EntityPlayer (net.minecraft.server.v1_12_R1.EntityPlayer)3 EntityPlayer (net.minecraft.server.v1_13_R2.EntityPlayer)3 EntityPlayer (net.minecraft.server.v1_14_R1.EntityPlayer)3