Search in sources :

Example 16 with PacketPlayOutEntityMetadata

use of net.minecraft.server.v1_15_R1.PacketPlayOutEntityMetadata 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<EntityArmorStand> fakeArmorStands = fakeArmorStandsMap.get(player);
        final List<org.bukkit.entity.Entity> cooldownJump = cooldownJumpMap.get(player);
        final EntityArmorStand as = new EntityArmorStand(EntityTypes.ARMOR_STAND, ((CraftWorld) player.getWorld()).getHandle());
        as.setInvisible(true);
        as.setFlag(5, true);
        as.setSmall(true);
        as.setNoGravity(true);
        as.setArms(true);
        as.setHeadPose(new Vector3f((float) (r.nextInt(360)), (float) (r.nextInt(360)), (float) (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 PacketPlayOutEntityMetadata(as.getId(), as.getDataWatcher(), false));
            PacketSender.send(players, new PacketPlayOutEntityEquipment(as.getId(), EnumItemSlot.HEAD, CraftItemStack.asNMSCopy(new org.bukkit.inventory.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()) PacketSender.send(pl, new PacketPlayOutEntityDestroy(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 : MathUtils(be.isach.ultracosmetics.util.MathUtils) java.util(java.util) Wither(org.bukkit.entity.Wither) UtilParticles(be.isach.ultracosmetics.util.UtilParticles) org.bukkit.craftbukkit.v1_15_R1.entity(org.bukkit.craftbukkit.v1_15_R1.entity) Player(org.bukkit.entity.Player) Inventory(org.bukkit.inventory.Inventory) Block(org.bukkit.block.Block) Location(org.bukkit.Location) UltraCosmeticsData(be.isach.ultracosmetics.UltraCosmeticsData) Math(java.lang.Math) Particles(be.isach.ultracosmetics.util.Particles) TreasureChestDesign(be.isach.ultracosmetics.treasurechests.TreasureChestDesign) CraftInventory(org.bukkit.craftbukkit.v1_15_R1.inventory.CraftInventory) CraftItemStack(org.bukkit.craftbukkit.v1_15_R1.inventory.CraftItemStack) Creature(org.bukkit.entity.Creature) Bukkit(org.bukkit.Bukkit) CraftWorld(org.bukkit.craftbukkit.v1_15_R1.CraftWorld) Field(java.lang.reflect.Field) CustomPathFinderGoalPanic(be.isach.ultracosmetics.v1_15_R1.pathfinders.CustomPathFinderGoalPanic) Vector(org.bukkit.util.Vector) net.minecraft.server.v1_15_R1(net.minecraft.server.v1_15_R1) IEntityUtil(be.isach.ultracosmetics.version.IEntityUtil) ChestType(be.isach.ultracosmetics.treasurechests.ChestType) PacketSender(be.isach.ultracosmetics.util.PacketSender) Player(org.bukkit.entity.Player) Vector(org.bukkit.util.Vector)

Example 17 with PacketPlayOutEntityMetadata

use of net.minecraft.server.v1_15_R1.PacketPlayOutEntityMetadata in project MechanicsMain by WeaponMechanics.

the class FakeEntity_1_15_R1 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) {
        for (PacketPlayOutEntityEquipment packet : equipment) {
            connection.sendPacket(packet);
        }
    }
    // 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_15_R1.PacketPlayOutEntity.PacketPlayOutEntityLook)

Example 18 with PacketPlayOutEntityMetadata

use of net.minecraft.server.v1_15_R1.PacketPlayOutEntityMetadata in project MechanicsMain by WeaponMechanics.

the class FakeEntity_1_15_R1 method show.

public void show() {
    // Construct the packets out of the loop to save resources, they will
    // be the same for each Player.
    Packet<?> spawn = type.isAlive() ? new PacketPlayOutSpawnEntityLiving((EntityLiving) entity) : new PacketPlayOutSpawnEntity(entity, type == EntityType.FALLING_BLOCK ? Block.getCombinedId(block) : 0);
    PacketPlayOutEntityMetadata meta = new PacketPlayOutEntityMetadata(cache, entity.getDataWatcher(), true);
    PacketPlayOutEntityHeadRotation head = new PacketPlayOutEntityHeadRotation(entity, convertYaw(getYaw()));
    PacketPlayOutEntityLook look = new PacketPlayOutEntityLook(cache, convertYaw(getYaw()), convertPitch(getPitch()), false);
    PacketPlayOutEntityVelocity velocity = new PacketPlayOutEntityVelocity(cache, new Vec3D(motion.getX(), motion.getY(), motion.getZ()));
    for (Player temp : DistanceUtil.getPlayersInRange(location)) {
        PlayerConnection connection = ((CraftPlayer) temp).getHandle().playerConnection;
        if (connections.contains(connection)) {
            continue;
        }
        connection.sendPacket(spawn);
        connection.sendPacket(meta);
        connection.sendPacket(head);
        connection.sendPacket(velocity);
        connection.sendPacket(look);
        PacketPlayOutEntityEquipment[] equipment = getEquipmentPacket();
        if (equipment != null) {
            for (PacketPlayOutEntityEquipment packet : equipment) {
                connection.sendPacket(packet);
            }
        }
        connections.add(connection);
    }
}
Also used : Player(org.bukkit.entity.Player) CraftPlayer(org.bukkit.craftbukkit.v1_15_R1.entity.CraftPlayer) PacketPlayOutEntityLook(net.minecraft.server.v1_15_R1.PacketPlayOutEntity.PacketPlayOutEntityLook)

Aggregations

MemoryNPCDataStore (net.citizensnpcs.api.npc.MemoryNPCDataStore)8 NPC (net.citizensnpcs.api.npc.NPC)8 NPCRegistry (net.citizensnpcs.api.npc.NPCRegistry)8 NPCHolder (net.citizensnpcs.npc.ai.NPCHolder)8 ArmorStandTrait (net.citizensnpcs.trait.ArmorStandTrait)8 FixedMetadataValue (org.bukkit.metadata.FixedMetadataValue)7 BukkitRunnable (org.bukkit.scheduler.BukkitRunnable)7 PacketPlayOutEntityMetadata (net.minecraft.server.v1_16_R3.PacketPlayOutEntityMetadata)4 ArrayList (java.util.ArrayList)3 Field (java.lang.reflect.Field)2 PacketPlayOutEntityLook (net.minecraft.server.v1_15_R1.PacketPlayOutEntity.PacketPlayOutEntityLook)2 Item (net.minecraft.server.v1_16_R2.DataWatcher.Item)2 PacketPlayOutEntityMetadata (net.minecraft.server.v1_16_R2.PacketPlayOutEntityMetadata)2 Item (net.minecraft.server.v1_16_R3.DataWatcher.Item)2 Player (org.bukkit.entity.Player)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