Search in sources :

Example 16 with PacketPlayOutEntityEquipment

use of net.minecraft.server.v1_16_R3.PacketPlayOutEntityEquipment in project UltraCosmetics by iSach.

the class EntityUtil method sendBlizzard.

@Override
public void sendBlizzard(final Player player, Location loc, boolean affectPlayers, Vector v) {
    if (!fakeArmorStandsMap.containsKey(player))
        fakeArmorStandsMap.put(player, new ArrayList<>());
    if (!cooldownJumpMap.containsKey(player))
        cooldownJumpMap.put(player, new ArrayList<>());
    final List<EntityArmorStand> fakeArmorStands = fakeArmorStandsMap.get(player);
    final List<Entity> cooldownJump = cooldownJumpMap.get(player);
    final EntityArmorStand as = new EntityArmorStand(((CraftWorld) player.getWorld()).getHandle());
    as.setInvisible(true);
    as.setSmall(true);
    as.setGravity(false);
    as.setArms(true);
    as.setHeadPose(new Vector3f(r.nextInt(360), r.nextInt(360), r.nextInt(360)));
    as.setLocation(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()) {
        PacketSender.send(players, new PacketPlayOutSpawnEntityLiving(as));
        PacketSender.send(players, new PacketPlayOutEntityEquipment(as.getId(), 4, CraftItemStack.asNMSCopy(new ItemStack(org.bukkit.Material.PACKED_ICE))));
    }
    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()) {
            if (as == null) {
                continue;
            }
            PacketSender.send(pl, new PacketPlayOutEntityDestroy(as.getId()));
        }
        fakeArmorStands.remove(as);
    }, 20);
    if (affectPlayers)
        for (final Entity ent : as.getBukkitEntity().getNearbyEntities(0.5, 0.5, 0.5)) {
            if (!cooldownJump.contains(ent) && ent != player) {
                MathUtils.applyVelocity(ent, new Vector(0, 1, 0).add(v));
                cooldownJump.add(ent);
                Bukkit.getScheduler().runTaskLater(UltraCosmeticsData.get().getPlugin(), () -> cooldownJump.remove(ent), 20);
            }
        }
}
Also used : PathEntity(net.minecraft.server.v1_8_R3.PathEntity) Entity(org.bukkit.entity.Entity) PacketPlayOutSpawnEntityLiving(net.minecraft.server.v1_8_R3.PacketPlayOutSpawnEntityLiving) Player(org.bukkit.entity.Player) EntityPlayer(net.minecraft.server.v1_8_R3.EntityPlayer) PacketPlayOutEntityDestroy(net.minecraft.server.v1_8_R3.PacketPlayOutEntityDestroy) Vector3f(net.minecraft.server.v1_8_R3.Vector3f) ArrayList(java.util.ArrayList) EntityArmorStand(net.minecraft.server.v1_8_R3.EntityArmorStand) PacketPlayOutEntityEquipment(net.minecraft.server.v1_8_R3.PacketPlayOutEntityEquipment) CraftItemStack(org.bukkit.craftbukkit.v1_8_R3.inventory.CraftItemStack) ItemStack(org.bukkit.inventory.ItemStack) Vector(org.bukkit.util.Vector)

Example 17 with PacketPlayOutEntityEquipment

use of net.minecraft.server.v1_16_R3.PacketPlayOutEntityEquipment in project CokesAddon by Cokes86.

the class v1_16_R3 method injectPlayer.

public void injectPlayer(Player player) {
    CraftPlayer player1 = (CraftPlayer) player;
    if (!player.isValid())
        return;
    if (channelHandlers.containsKey(player.getUniqueId())) {
        final Pair<CraftPlayer, ChannelOutboundHandlerAdapter> pair = channelHandlers.get(player.getUniqueId());
        if (!pair.getLeft().isValid()) {
            try {
                pair.getLeft().getHandle().playerConnection.networkManager.channel.pipeline().remove(pair.getRight());
            } catch (NoSuchElementException ignored) {
            }
        } else
            return;
    }
    final ChannelOutboundHandlerAdapter handler = new ChannelOutboundHandlerAdapter() {

        @Override
        public void write(ChannelHandlerContext ctx, Object packet, ChannelPromise promise) throws Exception {
            if (packet instanceof PacketPlayOutEntityEquipment) {
                if ((int) ReflectionUtil.FieldUtil.getValue(packet, "a") == getPlayer().getEntityId()) {
                    ReflectionUtil.FieldUtil.setValue(packet, "c", ItemStack.a);
                }
            } else if (packet instanceof PacketPlayOutEntityMetadata) {
                if ((int) ReflectionUtil.FieldUtil.getValue(packet, "a") == getPlayer().getEntityId()) {
                    List<Item<?>> items = ReflectionUtil.FieldUtil.getValue(packet, "b");
                    if (items.size() != 0) {
                        Item<?> item = items.get(0);
                        if (BYTE_DATA_WATCHER_OBJECT.equals(item.a())) {
                            Item<Byte> byteItem = (Item<Byte>) item;
                            byteItem.a((byte) (byteItem.b() | 1 << 5));
                            ((CraftPlayer) getPlayer()).getHandle().setInvisible(true);
                        }
                    }
                }
            }
            super.write(ctx, packet, promise);
        }
    };
    channelHandlers.put(player.getUniqueId(), Pair.of(player1, handler));
    player1.getHandle().playerConnection.networkManager.channel.pipeline().addBefore("packet_handler", hashCode() + ":" + player.getName(), handler);
}
Also used : Item(net.minecraft.server.v1_16_R3.DataWatcher.Item) ChannelOutboundHandlerAdapter(io.netty.channel.ChannelOutboundHandlerAdapter) CraftPlayer(org.bukkit.craftbukkit.v1_16_R3.entity.CraftPlayer) ChannelHandlerContext(io.netty.channel.ChannelHandlerContext) ChannelPromise(io.netty.channel.ChannelPromise)

Example 18 with PacketPlayOutEntityEquipment

use of net.minecraft.server.v1_16_R3.PacketPlayOutEntityEquipment in project DragonsOnline by UniverseCraft.

the class PlayerNPC116R3 method setEquipment.

public void setEquipment(EquipmentSlot slot, org.bukkit.inventory.ItemStack item) {
    PacketPlayOutEntityEquipment packet = new PacketPlayOutEntityEquipment();
    this.setField(packet, "a", handle.getId());
    this.setField(packet, "b", CraftEquipmentSlot.getNMS(slot));
    this.setField(packet, "c", CraftItemStack.asNMSCopy(item));
    this.sendPacket(packet);
}
Also used : PacketPlayOutEntityEquipment(net.minecraft.server.v1_16_R3.PacketPlayOutEntityEquipment)

Example 19 with PacketPlayOutEntityEquipment

use of net.minecraft.server.v1_16_R3.PacketPlayOutEntityEquipment in project MechanicsMain by WeaponMechanics.

the class FakeEntity_1_16_R3 method show.

@Override
public void show(@NotNull Player player) {
    PlayerConnection connection = ((CraftPlayer) player).getHandle().playerConnection;
    if (connections.contains(connection))
        throw new IllegalArgumentException();
    connection.sendPacket(type.isAlive() ? new PacketPlayOutSpawnEntityLiving((EntityLiving) entity) : new PacketPlayOutSpawnEntity(entity, type == EntityType.FALLING_BLOCK ? Block.getCombinedId(block) : 0));
    connection.sendPacket(new PacketPlayOutEntityMetadata(cache, entity.getDataWatcher(), true));
    connection.sendPacket(new PacketPlayOutEntityLook(cache, convertYaw(getYaw()), convertPitch(getPitch()), false));
    connection.sendPacket(new PacketPlayOutEntityVelocity(cache, new Vec3D(motion.getX(), motion.getY(), motion.getZ())));
    connection.sendPacket(new PacketPlayOutEntityHeadRotation(entity, convertYaw(getYaw())));
    PacketPlayOutEntityEquipment equipment = getEquipmentPacket();
    if (equipment != null)
        connection.sendPacket(equipment);
    // Inject the player's packet connection into this listener, so we can
    // show the player position/velocity/rotation changes
    connections.add(connection);
}
Also used : PacketPlayOutEntityLook(net.minecraft.server.v1_16_R3.PacketPlayOutEntity.PacketPlayOutEntityLook)

Aggregations

Location (org.bukkit.Location)9 Pair (com.mojang.datafixers.util.Pair)7 ArrayList (java.util.ArrayList)4 PacketContainer (com.comphenix.protocol.events.PacketContainer)3 net.minecraft.server.v1_16_R3 (net.minecraft.server.v1_16_R3)3 PacketPlayOutEntityEquipment (net.minecraft.server.v1_16_R3.PacketPlayOutEntityEquipment)3 Player (org.bukkit.entity.Player)3 EquipmentSlot (org.bukkit.inventory.EquipmentSlot)3 ItemStack (org.bukkit.inventory.ItemStack)3 EnumItemSlot (net.minecraft.server.v1_16_R3.EnumItemSlot)2 PacketPlayOutEntityLook (net.minecraft.server.v1_16_R3.PacketPlayOutEntity.PacketPlayOutEntityLook)2 Vector (org.bukkit.util.Vector)2 UltraCosmeticsData (be.isach.ultracosmetics.UltraCosmeticsData)1 ChestType (be.isach.ultracosmetics.treasurechests.ChestType)1 TreasureChestDesign (be.isach.ultracosmetics.treasurechests.TreasureChestDesign)1 MathUtils (be.isach.ultracosmetics.util.MathUtils)1 PacketSender (be.isach.ultracosmetics.util.PacketSender)1 Particles (be.isach.ultracosmetics.util.Particles)1 UtilParticles (be.isach.ultracosmetics.util.UtilParticles)1 CustomPathFinderGoalPanic (be.isach.ultracosmetics.v1_16_R3.pathfinders.CustomPathFinderGoalPanic)1