Search in sources :

Example 6 with ClientboundRemoveEntitiesPacket

use of net.minecraft.network.protocol.game.ClientboundRemoveEntitiesPacket in project MagicPlugin by elBukkit.

the class CompatibilityUtils method spawnFireworkEffect.

@Override
public Entity spawnFireworkEffect(Material fireworkMaterial, Server server, Location location, FireworkEffect effect, int power, Vector direction, Integer expectedLifespan, Integer ticksFlown, boolean silent) {
    Entity entity = null;
    try {
        if (fireworkMaterial == null) {
            return null;
        }
        ServerLevel level = ((CraftWorld) location.getWorld()).getHandle();
        ItemStack itemStack = new ItemStack(fireworkMaterial);
        FireworkMeta meta = (FireworkMeta) itemStack.getItemMeta();
        meta.addEffect(effect);
        meta.setPower(power);
        itemStack.setItemMeta(meta);
        Object item = platform.getItemUtils().getHandle(platform.getItemUtils().makeReal(itemStack));
        final FireworkRocketEntity fireworkHandle = new FireworkRocketEntity(level, location.getX(), location.getY(), location.getZ(), (net.minecraft.world.item.ItemStack) item);
        fireworkHandle.setSilent(silent);
        if (direction != null) {
            fireworkHandle.setDeltaMovement(new Vec3(direction.getX(), direction.getY(), direction.getZ()));
        }
        if (ticksFlown != null) {
            ReflectionUtils.setPrivateNeedsFixing(platform.getLogger(), fireworkHandle, FireworkRocketEntity.class, "life", "e", ticksFlown);
        }
        if (expectedLifespan != null) {
            fireworkHandle.lifetime = expectedLifespan;
        }
        if (direction == null) {
            ClientboundAddEntityPacket fireworkPacket = new ClientboundAddEntityPacket(fireworkHandle, CompatibilityConstants.FIREWORK_TYPE);
            int fireworkId = fireworkHandle.getId();
            SynchedEntityData watcher = fireworkHandle.getEntityData();
            ClientboundSetEntityDataPacket metadataPacket = new ClientboundSetEntityDataPacket(fireworkId, watcher, true);
            ClientboundEntityEventPacket statusPacket = new ClientboundEntityEventPacket(fireworkHandle, (byte) 17);
            ClientboundRemoveEntitiesPacket destroyPacket = new ClientboundRemoveEntitiesPacket(fireworkId);
            Collection<? extends Player> players = server.getOnlinePlayers();
            sendPacket(server, location, players, fireworkPacket);
            sendPacket(server, location, players, metadataPacket);
            sendPacket(server, location, players, statusPacket);
            sendPacket(server, location, players, destroyPacket);
            return null;
        }
        level.addFreshEntity(fireworkHandle, CreatureSpawnEvent.SpawnReason.CUSTOM);
        entity = fireworkHandle.getBukkitEntity();
    } catch (Exception ex) {
        ex.printStackTrace();
    }
    return entity;
}
Also used : FireworkRocketEntity(net.minecraft.world.entity.projectile.FireworkRocketEntity) Entity(org.bukkit.entity.Entity) HangingEntity(net.minecraft.world.entity.decoration.HangingEntity) CraftLivingEntity(org.bukkit.craftbukkit.v1_18_R2.entity.CraftLivingEntity) BlockEntity(net.minecraft.world.level.block.entity.BlockEntity) FallingBlockEntity(net.minecraft.world.entity.item.FallingBlockEntity) LivingEntity(org.bukkit.entity.LivingEntity) ItemEntity(net.minecraft.world.entity.item.ItemEntity) SignBlockEntity(net.minecraft.world.level.block.entity.SignBlockEntity) HumanEntity(org.bukkit.entity.HumanEntity) CraftEntity(org.bukkit.craftbukkit.v1_18_R2.entity.CraftEntity) ServerLevel(net.minecraft.server.level.ServerLevel) ClientboundRemoveEntitiesPacket(net.minecraft.network.protocol.game.ClientboundRemoveEntitiesPacket) SynchedEntityData(net.minecraft.network.syncher.SynchedEntityData) ClientboundAddEntityPacket(net.minecraft.network.protocol.game.ClientboundAddEntityPacket) FireworkMeta(org.bukkit.inventory.meta.FireworkMeta) FireworkRocketEntity(net.minecraft.world.entity.projectile.FireworkRocketEntity) Vec3(net.minecraft.world.phys.Vec3) ClientboundEntityEventPacket(net.minecraft.network.protocol.game.ClientboundEntityEventPacket) ItemStack(org.bukkit.inventory.ItemStack) CraftWorld(org.bukkit.craftbukkit.v1_18_R2.CraftWorld) ClientboundSetEntityDataPacket(net.minecraft.network.protocol.game.ClientboundSetEntityDataPacket)

Example 7 with ClientboundRemoveEntitiesPacket

use of net.minecraft.network.protocol.game.ClientboundRemoveEntitiesPacket in project kit-api by HGLabor.

the class SpidermanKit method onPlayerRightClickKitItem.

@KitEvent
@Override
public void onPlayerRightClickKitItem(PlayerInteractEvent event, KitPlayer kitPlayer) {
    Player player = event.getPlayer();
    kitPlayer.activateKitCooldown(this);
    final Vector direction = player.getEyeLocation().getDirection();
    Snowball snowball = player.getWorld().spawn(player.getEyeLocation().add(direction.multiply(shootingVelocity)), Snowball.class);
    snowball.setVelocity(direction);
    snowball.setShooter(player);
    snowball.setMetadata(spidermanSnowballKey, new FixedMetadataValue(KitApi.getInstance().getPlugin(), ""));
    for (Player p : Bukkit.getServer().getOnlinePlayers()) {
        ClientboundRemoveEntitiesPacket packet = new ClientboundRemoveEntitiesPacket(snowball.getEntityId());
        ((CraftPlayer) p).getHandle().connection.send(packet);
    }
    FallingBlock cobWeb = player.getWorld().spawnFallingBlock(player.getEyeLocation().add(direction), spidernetBlock.createBlockData());
    cobWeb.setHurtEntities(true);
    cobWeb.setVelocity(direction);
    cobWeb.setDropItem(false);
    snowball.addPassenger(cobWeb);
}
Also used : FallingBlock(org.bukkit.entity.FallingBlock) Snowball(org.bukkit.entity.Snowball) Player(org.bukkit.entity.Player) CraftPlayer(org.bukkit.craftbukkit.v1_18_R1.entity.CraftPlayer) KitPlayer(de.hglabor.plugins.kitapi.player.KitPlayer) ClientboundRemoveEntitiesPacket(net.minecraft.network.protocol.game.ClientboundRemoveEntitiesPacket) FixedMetadataValue(org.bukkit.metadata.FixedMetadataValue) CraftPlayer(org.bukkit.craftbukkit.v1_18_R1.entity.CraftPlayer) Vector(org.bukkit.util.Vector) KitEvent(de.hglabor.plugins.kitapi.kit.events.KitEvent)

Example 8 with ClientboundRemoveEntitiesPacket

use of net.minecraft.network.protocol.game.ClientboundRemoveEntitiesPacket in project Denizen 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)

Example 9 with ClientboundRemoveEntitiesPacket

use of net.minecraft.network.protocol.game.ClientboundRemoveEntitiesPacket in project Denizen 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_R2.entity.CraftPlayer) ServerPlayer(net.minecraft.server.level.ServerPlayer) BukkitRunnable(org.bukkit.scheduler.BukkitRunnable) CraftPlayer(org.bukkit.craftbukkit.v1_18_R2.entity.CraftPlayer) ClientboundAddPlayerPacket(net.minecraft.network.protocol.game.ClientboundAddPlayerPacket) UUID(java.util.UUID) CraftServer(org.bukkit.craftbukkit.v1_18_R2.CraftServer) ClientboundPlayerInfoPacket(net.minecraft.network.protocol.game.ClientboundPlayerInfoPacket)

Example 10 with ClientboundRemoveEntitiesPacket

use of net.minecraft.network.protocol.game.ClientboundRemoveEntitiesPacket in project UltraCosmetics by iSach.

the class EntityUtil method sendBlizzard.

@Override
public void sendBlizzard(final Player player, Location loc, boolean affectPlayers, Vector v) {
    try {
        if (!fakeArmorStandsMap.containsKey(player))
            fakeArmorStandsMap.put(player, new ArrayList<>());
        if (!cooldownJumpMap.containsKey(player))
            cooldownJumpMap.put(player, new ArrayList<>());
        final List<ArmorStand> fakeArmorStands = fakeArmorStandsMap.get(player);
        final List<org.bukkit.entity.Entity> cooldownJump = cooldownJumpMap.get(player);
        final ArmorStand as = new ArmorStand(EntityType.ARMOR_STAND, ((CraftWorld) player.getWorld()).getHandle());
        as.setInvisible(true);
        as.setSharedFlag(5, true);
        as.setSmall(true);
        as.setNoGravity(true);
        as.setShowArms(true);
        as.setHeadPose(new Rotations((r.nextInt(360)), (r.nextInt(360)), (r.nextInt(360))));
        as.absMoveTo(loc.getX() + MathUtils.randomDouble(-1.5, 1.5), loc.getY() + MathUtils.randomDouble(0, .5) - 0.75, loc.getZ() + MathUtils.randomDouble(-1.5, 1.5), 0, 0);
        fakeArmorStands.add(as);
        for (Player players : player.getWorld().getPlayers()) {
            sendPacket(player, new ClientboundAddEntityPacket(as));
            sendPacket(players, new ClientboundSetEntityDataPacket(as.getId(), as.getEntityData(), false));
            List<Pair<EquipmentSlot, ItemStack>> list = new ArrayList<>();
            list.add(new Pair(EquipmentSlot.HEAD, CraftItemStack.asNMSCopy(new org.bukkit.inventory.ItemStack(org.bukkit.Material.PACKED_ICE))));
            sendPacket(players, new ClientboundSetEquipmentPacket(as.getId(), list));
        }
        UtilParticles.display(Particles.CLOUD, loc.clone().add(MathUtils.randomDouble(-1.5, 1.5), MathUtils.randomDouble(0, .5) - 0.75, MathUtils.randomDouble(-1.5, 1.5)), 2, 0.4f);
        Bukkit.getScheduler().runTaskLater(UltraCosmeticsData.get().getPlugin(), () -> {
            for (Player pl : player.getWorld().getPlayers()) {
                sendPacket(pl, new ClientboundRemoveEntitiesPacket(as.getId()));
            }
            fakeArmorStands.remove(as);
        }, 20);
        if (affectPlayers)
            as.getBukkitEntity().getNearbyEntities(0.5, 0.5, 0.5).stream().filter(ent -> !cooldownJump.contains(ent) && ent != player).forEachOrdered(ent -> {
                MathUtils.applyVelocity(ent, new Vector(0, 1, 0).add(v));
                cooldownJump.add(ent);
                Bukkit.getScheduler().runTaskLater(UltraCosmeticsData.get().getPlugin(), () -> cooldownJump.remove(ent), 20);
            });
    } catch (Exception exc) {
    }
}
Also used : CraftPlayer(org.bukkit.craftbukkit.v1_17_R1.entity.CraftPlayer) LivingEntity(net.minecraft.world.entity.LivingEntity) Path(net.minecraft.world.level.pathfinder.Path) CraftEnderDragon(org.bukkit.craftbukkit.v1_17_R1.entity.CraftEnderDragon) UtilParticles(be.isach.ultracosmetics.util.UtilParticles) Player(org.bukkit.entity.Player) Inventory(org.bukkit.inventory.Inventory) Block(org.bukkit.block.Block) Location(org.bukkit.Location) EnderDragon(net.minecraft.world.entity.boss.enderdragon.EnderDragon) CraftCreature(org.bukkit.craftbukkit.v1_17_R1.entity.CraftCreature) UltraCosmeticsData(be.isach.ultracosmetics.UltraCosmeticsData) Math(java.lang.Math) Creature(org.bukkit.entity.Creature) Bukkit(org.bukkit.Bukkit) ClientboundRemoveEntitiesPacket(net.minecraft.network.protocol.game.ClientboundRemoveEntitiesPacket) CraftBoat(org.bukkit.craftbukkit.v1_17_R1.entity.CraftBoat) ClientboundTeleportEntityPacket(net.minecraft.network.protocol.game.ClientboundTeleportEntityPacket) BlockPos(net.minecraft.core.BlockPos) ItemEntity(net.minecraft.world.entity.item.ItemEntity) Boat(net.minecraft.world.entity.vehicle.Boat) WrappedGoal(net.minecraft.world.entity.ai.goal.WrappedGoal) CraftWorld(org.bukkit.craftbukkit.v1_17_R1.CraftWorld) CustomPathFinderGoalPanic(be.isach.ultracosmetics.v1_17_R1.pathfinders.CustomPathFinderGoalPanic) Packet(net.minecraft.network.protocol.Packet) PathfinderMob(net.minecraft.world.entity.PathfinderMob) ChestType(be.isach.ultracosmetics.treasurechests.ChestType) ItemStack(net.minecraft.world.item.ItemStack) MoverType(net.minecraft.world.entity.MoverType) Level(net.minecraft.world.level.Level) Goal(net.minecraft.world.entity.ai.goal.Goal) CraftInventory(org.bukkit.craftbukkit.v1_17_R1.inventory.CraftInventory) CraftItemStack(org.bukkit.craftbukkit.v1_17_R1.inventory.CraftItemStack) GoalSelector(net.minecraft.world.entity.ai.goal.GoalSelector) MathUtils(be.isach.ultracosmetics.util.MathUtils) java.util(java.util) CraftWither(org.bukkit.craftbukkit.v1_17_R1.entity.CraftWither) Wither(org.bukkit.entity.Wither) EntityType(net.minecraft.world.entity.EntityType) ChestBlockEntity(net.minecraft.world.level.block.entity.ChestBlockEntity) ServerPlayer(net.minecraft.server.level.ServerPlayer) Rotations(net.minecraft.core.Rotations) ArmorStand(net.minecraft.world.entity.decoration.ArmorStand) Particles(be.isach.ultracosmetics.util.Particles) TreasureChestDesign(be.isach.ultracosmetics.treasurechests.TreasureChestDesign) CraftEntity(org.bukkit.craftbukkit.v1_17_R1.entity.CraftEntity) Field(java.lang.reflect.Field) ClientboundSetEquipmentPacket(net.minecraft.network.protocol.game.ClientboundSetEquipmentPacket) Pair(com.mojang.datafixers.util.Pair) ClientboundAddEntityPacket(net.minecraft.network.protocol.game.ClientboundAddEntityPacket) Vector(org.bukkit.util.Vector) Entity(net.minecraft.world.entity.Entity) ClientboundSetEntityDataPacket(net.minecraft.network.protocol.game.ClientboundSetEntityDataPacket) Vec3(net.minecraft.world.phys.Vec3) IEntityUtil(be.isach.ultracosmetics.version.IEntityUtil) EquipmentSlot(net.minecraft.world.entity.EquipmentSlot) Brain(net.minecraft.world.entity.ai.Brain) Mob(net.minecraft.world.entity.Mob) EnderChestBlockEntity(net.minecraft.world.level.block.entity.EnderChestBlockEntity) LivingEntity(net.minecraft.world.entity.LivingEntity) ItemEntity(net.minecraft.world.entity.item.ItemEntity) ChestBlockEntity(net.minecraft.world.level.block.entity.ChestBlockEntity) CraftEntity(org.bukkit.craftbukkit.v1_17_R1.entity.CraftEntity) Entity(net.minecraft.world.entity.Entity) EnderChestBlockEntity(net.minecraft.world.level.block.entity.EnderChestBlockEntity) ClientboundSetEquipmentPacket(net.minecraft.network.protocol.game.ClientboundSetEquipmentPacket) CraftPlayer(org.bukkit.craftbukkit.v1_17_R1.entity.CraftPlayer) Player(org.bukkit.entity.Player) ServerPlayer(net.minecraft.server.level.ServerPlayer) ClientboundRemoveEntitiesPacket(net.minecraft.network.protocol.game.ClientboundRemoveEntitiesPacket) ClientboundAddEntityPacket(net.minecraft.network.protocol.game.ClientboundAddEntityPacket) Rotations(net.minecraft.core.Rotations) ArmorStand(net.minecraft.world.entity.decoration.ArmorStand) Vector(org.bukkit.util.Vector) ClientboundSetEntityDataPacket(net.minecraft.network.protocol.game.ClientboundSetEntityDataPacket) Pair(com.mojang.datafixers.util.Pair)

Aggregations

ClientboundRemoveEntitiesPacket (net.minecraft.network.protocol.game.ClientboundRemoveEntitiesPacket)27 ServerPlayer (net.minecraft.server.level.ServerPlayer)16 Player (org.bukkit.entity.Player)11 ServerLevel (net.minecraft.server.level.ServerLevel)10 ClientboundAddEntityPacket (net.minecraft.network.protocol.game.ClientboundAddEntityPacket)6 ClientboundSetEntityDataPacket (net.minecraft.network.protocol.game.ClientboundSetEntityDataPacket)6 ItemEntity (net.minecraft.world.entity.item.ItemEntity)6 Vec3 (net.minecraft.world.phys.Vec3)6 ClientboundPlayerInfoPacket (net.minecraft.network.protocol.game.ClientboundPlayerInfoPacket)5 CraftPlayer (org.bukkit.craftbukkit.v1_17_R1.entity.CraftPlayer)5 ChunkMap (net.minecraft.server.level.ChunkMap)4 net.minecraft.world.entity (net.minecraft.world.entity)4 ArmorStand (net.minecraft.world.entity.decoration.ArmorStand)4 CraftPlayer (org.bukkit.craftbukkit.v1_18_R1.entity.CraftPlayer)4 CraftPlayer (org.bukkit.craftbukkit.v1_18_R2.entity.CraftPlayer)4 org.bukkit.entity (org.bukkit.entity)4 KitPlayer (de.hglabor.plugins.kitapi.player.KitPlayer)3 ArrayList (java.util.ArrayList)3 UUID (java.util.UUID)3 ClientboundAddPlayerPacket (net.minecraft.network.protocol.game.ClientboundAddPlayerPacket)3