Search in sources :

Example 86 with CraftEntity

use of org.bukkit.craftbukkit.v1_8_R2.entity.CraftEntity in project Denizen-For-Bukkit by DenizenScript.

the class DenizenNetworkManagerImpl method processDisguiseForPacket.

public boolean processDisguiseForPacket(Packet<?> packet, GenericFutureListener<? extends Future<? super Void>> genericfuturelistener) {
    if (DisguiseCommand.disguises.isEmpty() || antiDuplicate) {
        return false;
    }
    try {
        int ider = -1;
        if (packet instanceof ClientboundSetEntityDataPacket) {
            ider = ((ClientboundSetEntityDataPacket) packet).getId();
        }
        if (packet instanceof ClientboundUpdateAttributesPacket) {
            ider = ((ClientboundUpdateAttributesPacket) packet).getEntityId();
        }
        if (packet instanceof ClientboundAddPlayerPacket) {
            ider = ((ClientboundAddPlayerPacket) packet).getEntityId();
        } else if (packet instanceof ClientboundAddEntityPacket) {
            ider = ((ClientboundAddEntityPacket) packet).getId();
        } else if (packet instanceof ClientboundAddMobPacket) {
            ider = ((ClientboundAddMobPacket) packet).getId();
        }
        if (ider != -1) {
            Entity e = player.getLevel().getEntity(ider);
            if (e == null) {
                return false;
            }
            HashMap<UUID, DisguiseCommand.TrackedDisguise> playerMap = DisguiseCommand.disguises.get(e.getUUID());
            if (playerMap == null) {
                return false;
            }
            DisguiseCommand.TrackedDisguise disguise = playerMap.get(player.getUUID());
            if (disguise == null) {
                disguise = playerMap.get(null);
                if (disguise == null) {
                    return false;
                }
            }
            if (!disguise.isActive) {
                return false;
            }
            if (NMSHandler.debugPackets) {
                doPacketOutput("DISGUISED packet " + packet.getClass().getName() + " for entity " + ider + " to player " + player.getScoreboardName());
            }
            if (packet instanceof ClientboundSetEntityDataPacket) {
                ClientboundSetEntityDataPacket metadataPacket = (ClientboundSetEntityDataPacket) packet;
                if (e.getId() == player.getId()) {
                    if (!disguise.shouldFake) {
                        return false;
                    }
                    List<SynchedEntityData.DataItem<?>> data = metadataPacket.getUnpackedData();
                    for (SynchedEntityData.DataItem item : data) {
                        EntityDataAccessor<?> watcherObject = item.getAccessor();
                        int watcherId = watcherObject.getId();
                        if (watcherId == 0) {
                            // Entity flags
                            ClientboundSetEntityDataPacket altPacket = new ClientboundSetEntityDataPacket(copyPacket(metadataPacket));
                            data = new ArrayList<>(data);
                            ENTITY_METADATA_LIST.set(altPacket, data);
                            data.remove(item);
                            byte flags = (byte) item.getValue();
                            // Invisible flag
                            flags |= 0x20;
                            data.add(new SynchedEntityData.DataItem(watcherObject, flags));
                            ClientboundSetEntityDataPacket updatedPacket = getModifiedMetadataFor(altPacket);
                            oldManager.send(updatedPacket == null ? altPacket : updatedPacket, genericfuturelistener);
                            return true;
                        }
                    }
                } else {
                    ClientboundSetEntityDataPacket altPacket = new ClientboundSetEntityDataPacket(e.getId(), ((CraftEntity) disguise.toOthers.entity.entity).getHandle().getEntityData(), true);
                    oldManager.send(altPacket, genericfuturelistener);
                    return true;
                }
                return false;
            }
            if (packet instanceof ClientboundUpdateAttributesPacket) {
                FakeEntity fake = ider == player.getId() ? disguise.fakeToSelf : disguise.toOthers;
                if (fake == null) {
                    return false;
                }
                if (fake.entity.entity instanceof LivingEntity) {
                    return false;
                }
                // Non-living don't have attributes
                return true;
            }
            antiDuplicate = true;
            disguise.sendTo(Collections.singletonList(new PlayerTag(player.getBukkitEntity())));
            antiDuplicate = false;
            return true;
        }
    } catch (Throwable ex) {
        antiDuplicate = false;
        Debug.echoError(ex);
    }
    return false;
}
Also used : FakeEntity(com.denizenscript.denizen.utilities.entity.FakeEntity) LivingEntity(org.bukkit.entity.LivingEntity) FakeEntity(com.denizenscript.denizen.utilities.entity.FakeEntity) Entity(net.minecraft.world.entity.Entity) CraftEntity(org.bukkit.craftbukkit.v1_18_R1.entity.CraftEntity) DisguiseCommand(com.denizenscript.denizen.scripts.commands.player.DisguiseCommand) SynchedEntityData(net.minecraft.network.syncher.SynchedEntityData) PlayerTag(com.denizenscript.denizen.objects.PlayerTag) CraftEntity(org.bukkit.craftbukkit.v1_18_R1.entity.CraftEntity) LivingEntity(org.bukkit.entity.LivingEntity)

Example 87 with CraftEntity

use of org.bukkit.craftbukkit.v1_8_R2.entity.CraftEntity in project Denizen-For-Bukkit by DenizenScript.

the class DenizenNetworkManagerImpl method tryProcessTeleportPacketForAttach.

public void tryProcessTeleportPacketForAttach(ClientboundTeleportEntityPacket packet, Entity e, Vector relative) throws IllegalAccessException {
    EntityAttachmentHelper.EntityAttachedToMap attList = EntityAttachmentHelper.toEntityToData.get(e.getUUID());
    if (attList != null) {
        for (EntityAttachmentHelper.PlayerAttachMap attMap : attList.attachedToMap.values()) {
            EntityAttachmentHelper.AttachmentData att = attMap.getAttachment(player.getUUID());
            if (attMap.attached.isValid() && att != null) {
                ClientboundTeleportEntityPacket pNew = new ClientboundTeleportEntityPacket(copyPacket(packet));
                ENTITY_ID_PACKTELENT.setInt(pNew, att.attached.getBukkitEntity().getEntityId());
                Vector resultPos = new Vector(POS_X_PACKTELENT.getDouble(pNew), POS_Y_PACKTELENT.getDouble(pNew), POS_Z_PACKTELENT.getDouble(pNew)).add(relative);
                if (att.positionalOffset != null) {
                    resultPos = att.fixedForOffset(resultPos, e.getYRot(), e.getXRot());
                    byte yaw, pitch;
                    if (att.noRotate) {
                        Entity attachedEntity = ((CraftEntity) att.attached.getBukkitEntity()).getHandle();
                        yaw = EntityAttachmentHelper.compressAngle(attachedEntity.getYRot());
                        pitch = EntityAttachmentHelper.compressAngle(attachedEntity.getXRot());
                    } else {
                        yaw = packet.getyRot();
                        pitch = packet.getxRot();
                    }
                    if (att.noPitch) {
                        Entity attachedEntity = ((CraftEntity) att.attached.getBukkitEntity()).getHandle();
                        pitch = EntityAttachmentHelper.compressAngle(attachedEntity.getXRot());
                    }
                    byte newYaw = EntityAttachmentHelper.adaptedCompressedAngle(yaw, att.positionalOffset.getYaw());
                    pitch = EntityAttachmentHelper.adaptedCompressedAngle(pitch, att.positionalOffset.getPitch());
                    POS_X_PACKTELENT.setDouble(pNew, resultPos.getX());
                    POS_Y_PACKTELENT.setDouble(pNew, resultPos.getY());
                    POS_Z_PACKTELENT.setDouble(pNew, resultPos.getZ());
                    YAW_PACKTELENT.setByte(pNew, newYaw);
                    PITCH_PACKTELENT.setByte(pNew, pitch);
                    if (NMSHandler.debugPackets) {
                        Debug.log("Attach Teleport Packet: " + pNew.getClass().getCanonicalName() + " for " + att.attached.getUUID() + " sent to " + player.getName() + " with raw yaw " + yaw + " adapted to " + newYaw);
                    }
                }
                att.visiblePositions.put(player.getUUID(), resultPos.clone());
                oldManager.send(pNew);
            }
        }
    }
    if (e.passengers != null && !e.passengers.isEmpty()) {
        for (Entity ent : e.passengers) {
            tryProcessTeleportPacketForAttach(packet, ent, new Vector(ent.getX() - e.getX(), ent.getY() - e.getY(), ent.getZ() - e.getZ()));
        }
    }
}
Also used : CraftEntity(org.bukkit.craftbukkit.v1_17_R1.entity.CraftEntity) Entity(net.minecraft.world.entity.Entity) CraftEntity(org.bukkit.craftbukkit.v1_17_R1.entity.CraftEntity) EntityAttachmentHelper(com.denizenscript.denizen.utilities.entity.EntityAttachmentHelper) Vector(org.bukkit.util.Vector)

Example 88 with CraftEntity

use of org.bukkit.craftbukkit.v1_8_R2.entity.CraftEntity in project solinia3-core by mixxit.

the class SoliniaLivingEntity method sendItemAnimation.

private void sendItemAnimation(ISoliniaLivingEntity other, SkillType skillType) {
    if (skillType.equals(SkillType.Archery)) {
        net.minecraft.server.v1_15_R1.Entity ep = ((CraftEntity) getBukkitLivingEntity()).getHandle();
        getBukkitLivingEntity().getWorld().playSound(getBukkitLivingEntity().getLocation(), Sound.ENTITY_ARROW_SHOOT, 1.0F, 1.0F);
        // Send shoot arrow to nearby people
        for (Entity listening : getBukkitLivingEntity().getNearbyEntities(20, 20, 20)) {
            if (listening instanceof Player)
                EntityUtils.sendAnimationPacket(getBukkitLivingEntity(), (Player) listening, SolAnimationType.SwingArm);
        }
        // Self send shoot arrow
        if (getBukkitLivingEntity() instanceof Player)
            EntityUtils.sendAnimationPacket(getBukkitLivingEntity(), (Player) getBukkitLivingEntity(), SolAnimationType.SwingArm);
        Arrow arrow = getBukkitLivingEntity().launchProjectile(Arrow.class);
        arrow.setPickupStatus(org.bukkit.entity.AbstractArrow.PickupStatus.DISALLOWED);
        arrow.setBounce(false);
        arrow.setVelocity(other.getBukkitLivingEntity().getEyeLocation().toVector().subtract(arrow.getLocation().toVector()).normalize().multiply(4));
    }
}
Also used : Arrow(org.bukkit.entity.Arrow) CraftEntity(org.bukkit.craftbukkit.v1_15_R1.entity.CraftEntity) ISoliniaLivingEntity(com.solinia.solinia.Interfaces.ISoliniaLivingEntity) Entity(org.bukkit.entity.Entity) LivingEntity(org.bukkit.entity.LivingEntity) Player(org.bukkit.entity.Player) ISoliniaPlayer(com.solinia.solinia.Interfaces.ISoliniaPlayer) CraftEntity(org.bukkit.craftbukkit.v1_15_R1.entity.CraftEntity)

Example 89 with CraftEntity

use of org.bukkit.craftbukkit.v1_8_R2.entity.CraftEntity in project MagicPlugin by elBukkit.

the class CompatibilityUtils method magicDamage.

@Override
public void magicDamage(Damageable target, double amount, Entity source) {
    try {
        if (target == null || target.isDead())
            return;
        // Might need to config-drive this, or just go back to defaulting to normal damage
        if (!USE_MAGIC_DAMAGE || target instanceof Witch || target instanceof Enderman || target instanceof ArmorStand || !(target instanceof LivingEntity)) {
            damage(target, amount, source);
            return;
        }
        net.minecraft.world.entity.Entity targetHandle = ((CraftEntity) target).getHandle();
        if (targetHandle == null)
            return;
        net.minecraft.world.entity.Entity sourceHandle = source == null ? null : ((CraftEntity) source).getHandle();
        // Bukkit won't allow magic damage from anything but a potion..
        if (sourceHandle != null && source instanceof LivingEntity) {
            Location location = target.getLocation();
            ThrownPotion potion = getOrCreatePotionEntity(location);
            net.minecraft.world.entity.Entity potionHandle = ((CraftEntity) potion).getHandle();
            potion.setShooter((LivingEntity) source);
            DamageSource magicSource = DamageSource.indirectMagic(potionHandle, sourceHandle);
            // This is a bit of hack that lets us damage the ender dragon, who is a weird and annoying collection
            // of various non-living entity pieces.
            ((EntityDamageSource) magicSource).setThorns();
            try (EnteredStateTracker.Touchable damaging = isDamaging.enter()) {
                damaging.touch();
                targetHandle.hurt(magicSource, (float) amount);
            }
        } else {
            try (EnteredStateTracker.Touchable damaging = isDamaging.enter()) {
                damaging.touch();
                targetHandle.hurt(DamageSource.MAGIC, (float) amount);
            }
        }
    } catch (Exception ex) {
        ex.printStackTrace();
    }
}
Also used : EntityDamageSource(net.minecraft.world.damagesource.EntityDamageSource) DamageSource(net.minecraft.world.damagesource.DamageSource) CraftEntity(org.bukkit.craftbukkit.v1_17_R1.entity.CraftEntity) EntityDamageSource(net.minecraft.world.damagesource.EntityDamageSource) CraftLivingEntity(org.bukkit.craftbukkit.v1_17_R1.entity.CraftLivingEntity) LivingEntity(org.bukkit.entity.LivingEntity) ArmorStand(org.bukkit.entity.ArmorStand) CraftArmorStand(org.bukkit.craftbukkit.v1_17_R1.entity.CraftArmorStand) Enderman(org.bukkit.entity.Enderman) ThrownPotion(org.bukkit.entity.ThrownPotion) EnteredStateTracker(com.elmakers.mine.bukkit.utility.EnteredStateTracker) Witch(org.bukkit.entity.Witch) Location(org.bukkit.Location)

Example 90 with CraftEntity

use of org.bukkit.craftbukkit.v1_8_R2.entity.CraftEntity in project MagicPlugin by elBukkit.

the class CompatibilityUtils method getHitbox.

@Override
public BoundingBox getHitbox(Entity entity) {
    net.minecraft.world.entity.Entity nmsEntity = ((CraftEntity) entity).getHandle();
    AABB aabb = nmsEntity.getBoundingBox();
    if (aabb == null) {
        return null;
    }
    return new BoundingBox(aabb.minX, aabb.maxX, aabb.minY, aabb.maxY, aabb.minZ, aabb.maxZ);
}
Also used : BoundingBox(com.elmakers.mine.bukkit.utility.BoundingBox) CraftEntity(org.bukkit.craftbukkit.v1_17_R1.entity.CraftEntity) AABB(net.minecraft.world.phys.AABB)

Aggregations

Entity (org.bukkit.entity.Entity)29 Iterator (java.util.Iterator)21 List (java.util.List)21 LivingEntity (org.bukkit.entity.LivingEntity)21 CraftEntity (org.bukkit.craftbukkit.v1_18_R1.entity.CraftEntity)17 CraftEntity (org.bukkit.craftbukkit.v1_17_R1.entity.CraftEntity)16 UUID (java.util.UUID)12 Location (org.bukkit.Location)11 EnteredStateTracker (com.elmakers.mine.bukkit.utility.EnteredStateTracker)10 DamageSource (net.minecraft.world.damagesource.DamageSource)10 EntityDamageSource (net.minecraft.world.damagesource.EntityDamageSource)10 CraftEntity (org.bukkit.craftbukkit.v1_10_R1.entity.CraftEntity)10 HashSet (java.util.HashSet)8 Set (java.util.Set)8 CraftEntity (org.bukkit.craftbukkit.v1_11_R1.entity.CraftEntity)8 CraftEntity (org.bukkit.craftbukkit.v1_8_R3.entity.CraftEntity)8 CraftEntity (org.bukkit.craftbukkit.v1_9_R2.entity.CraftEntity)7 CraftEntity (org.bukkit.craftbukkit.v1_18_R2.entity.CraftEntity)6 BukkitRunnable (org.bukkit.scheduler.BukkitRunnable)6 EntityAttachmentHelper (com.denizenscript.denizen.utilities.entity.EntityAttachmentHelper)5