Search in sources :

Example 1 with ClientboundAddPlayerPacket

use of net.minecraft.network.protocol.game.ClientboundAddPlayerPacket in project Denizen-For-Bukkit by DenizenScript.

the class ProfileEditorImpl method updatePlayer.

@Override
protected void updatePlayer(Player player, final boolean isSkinChanging) {
    final ServerPlayer entityPlayer = ((CraftPlayer) player).getHandle();
    final UUID uuid = player.getUniqueId();
    ClientboundRemoveEntitiesPacket destroyPacket = new ClientboundRemoveEntitiesPacket(entityPlayer.getId());
    for (Player p : Bukkit.getServer().getOnlinePlayers()) {
        if (!p.getUniqueId().equals(uuid)) {
            PacketHelperImpl.send(p, destroyPacket);
        }
    }
    new BukkitRunnable() {

        @Override
        public void run() {
            ClientboundPlayerInfoPacket playerInfo = new ClientboundPlayerInfoPacket(ClientboundPlayerInfoPacket.Action.ADD_PLAYER, entityPlayer);
            ClientboundAddPlayerPacket spawnPacket = new ClientboundAddPlayerPacket(entityPlayer);
            for (Player player : Bukkit.getServer().getOnlinePlayers()) {
                PacketHelperImpl.send(player, playerInfo);
                if (!player.getUniqueId().equals(uuid)) {
                    PacketHelperImpl.send(player, spawnPacket);
                } else {
                    if (isSkinChanging) {
                        ((CraftServer) Bukkit.getServer()).getHandle().respawn(entityPlayer, (ServerLevel) entityPlayer.level, true, player.getLocation(), false);
                    }
                    player.updateInventory();
                }
            }
        }
    }.runTaskLater(NMSHandler.getJavaPlugin(), 5);
}
Also used : ServerLevel(net.minecraft.server.level.ServerLevel) ClientboundRemoveEntitiesPacket(net.minecraft.network.protocol.game.ClientboundRemoveEntitiesPacket) Player(org.bukkit.entity.Player) ServerPlayer(net.minecraft.server.level.ServerPlayer) CraftPlayer(org.bukkit.craftbukkit.v1_18_R1.entity.CraftPlayer) ServerPlayer(net.minecraft.server.level.ServerPlayer) BukkitRunnable(org.bukkit.scheduler.BukkitRunnable) CraftPlayer(org.bukkit.craftbukkit.v1_18_R1.entity.CraftPlayer) ClientboundAddPlayerPacket(net.minecraft.network.protocol.game.ClientboundAddPlayerPacket) UUID(java.util.UUID) CraftServer(org.bukkit.craftbukkit.v1_18_R1.CraftServer) ClientboundPlayerInfoPacket(net.minecraft.network.protocol.game.ClientboundPlayerInfoPacket)

Example 2 with ClientboundAddPlayerPacket

use of net.minecraft.network.protocol.game.ClientboundAddPlayerPacket in project Denizen-For-Bukkit by DenizenScript.

the class ProfileEditorImpl method updatePlayer.

@Override
protected void updatePlayer(Player player, final boolean isSkinChanging) {
    final ServerPlayer entityPlayer = ((CraftPlayer) player).getHandle();
    final UUID uuid = player.getUniqueId();
    ClientboundRemoveEntitiesPacket destroyPacket = new ClientboundRemoveEntitiesPacket(entityPlayer.getId());
    for (Player p : Bukkit.getServer().getOnlinePlayers()) {
        if (!p.getUniqueId().equals(uuid)) {
            PacketHelperImpl.send(p, destroyPacket);
        }
    }
    new BukkitRunnable() {

        @Override
        public void run() {
            ClientboundPlayerInfoPacket playerInfo = new ClientboundPlayerInfoPacket(ClientboundPlayerInfoPacket.Action.ADD_PLAYER, entityPlayer);
            ClientboundAddPlayerPacket spawnPacket = new ClientboundAddPlayerPacket(entityPlayer);
            for (Player player : Bukkit.getServer().getOnlinePlayers()) {
                PacketHelperImpl.send(player, playerInfo);
                if (!player.getUniqueId().equals(uuid)) {
                    PacketHelperImpl.send(player, spawnPacket);
                } else {
                    if (isSkinChanging) {
                        ((CraftServer) Bukkit.getServer()).getHandle().moveToWorld(entityPlayer, (ServerLevel) entityPlayer.level, true, player.getLocation(), false);
                    }
                    player.updateInventory();
                }
            }
        }
    }.runTaskLater(NMSHandler.getJavaPlugin(), 5);
}
Also used : ServerLevel(net.minecraft.server.level.ServerLevel) ClientboundRemoveEntitiesPacket(net.minecraft.network.protocol.game.ClientboundRemoveEntitiesPacket) CraftPlayer(org.bukkit.craftbukkit.v1_17_R1.entity.CraftPlayer) Player(org.bukkit.entity.Player) ServerPlayer(net.minecraft.server.level.ServerPlayer) ServerPlayer(net.minecraft.server.level.ServerPlayer) BukkitRunnable(org.bukkit.scheduler.BukkitRunnable) CraftPlayer(org.bukkit.craftbukkit.v1_17_R1.entity.CraftPlayer) ClientboundAddPlayerPacket(net.minecraft.network.protocol.game.ClientboundAddPlayerPacket) UUID(java.util.UUID) CraftServer(org.bukkit.craftbukkit.v1_17_R1.CraftServer) ClientboundPlayerInfoPacket(net.minecraft.network.protocol.game.ClientboundPlayerInfoPacket)

Aggregations

UUID (java.util.UUID)2 ClientboundAddPlayerPacket (net.minecraft.network.protocol.game.ClientboundAddPlayerPacket)2 ClientboundPlayerInfoPacket (net.minecraft.network.protocol.game.ClientboundPlayerInfoPacket)2 ClientboundRemoveEntitiesPacket (net.minecraft.network.protocol.game.ClientboundRemoveEntitiesPacket)2 ServerLevel (net.minecraft.server.level.ServerLevel)2 ServerPlayer (net.minecraft.server.level.ServerPlayer)2 Player (org.bukkit.entity.Player)2 BukkitRunnable (org.bukkit.scheduler.BukkitRunnable)2 CraftServer (org.bukkit.craftbukkit.v1_17_R1.CraftServer)1 CraftPlayer (org.bukkit.craftbukkit.v1_17_R1.entity.CraftPlayer)1 CraftServer (org.bukkit.craftbukkit.v1_18_R1.CraftServer)1 CraftPlayer (org.bukkit.craftbukkit.v1_18_R1.entity.CraftPlayer)1