Search in sources :

Example 91 with CraftEntity

use of org.bukkit.craftbukkit.v1_8_R1.entity.CraftEntity in project Magma-1.16.x by magmafoundation.

the class CraftEventFactory method handleEntityDamageEvent.

private static EntityDamageEvent handleEntityDamageEvent(Entity entity, DamageSource source, Map<DamageModifier, Double> modifiers, Map<DamageModifier, Function<? super Double, Double>> modifierFunctions, boolean cancelled) {
    if (source.isExplosion()) {
        DamageCause damageCause;
        Entity damager = entityDamage;
        entityDamage = null;
        EntityDamageEvent event;
        if (damager == null) {
            event = new EntityDamageByBlockEvent(null, entity.getBukkitEntity(), DamageCause.BLOCK_EXPLOSION, modifiers, modifierFunctions);
        } else if (entity instanceof EnderDragonEntity && /*PAIL FIXME ((EnderDragonEntity) entity).target == damager*/
        false) {
            event = new EntityDamageEvent(entity.getBukkitEntity(), DamageCause.ENTITY_EXPLOSION, modifiers, modifierFunctions);
        } else {
            if (damager instanceof org.bukkit.entity.TNTPrimed) {
                damageCause = DamageCause.BLOCK_EXPLOSION;
            } else {
                damageCause = DamageCause.ENTITY_EXPLOSION;
            }
            event = new EntityDamageByEntityEvent(damager.getBukkitEntity(), entity.getBukkitEntity(), damageCause, modifiers, modifierFunctions);
        }
        event.setCancelled(cancelled);
        callEvent(event);
        if (!event.isCancelled()) {
            event.getEntity().setLastDamageCause(event);
        }
        return event;
    } else if (source instanceof EntityDamageSource) {
        Entity damager = source.getEntity();
        DamageCause cause = (source.isSweep()) ? DamageCause.ENTITY_SWEEP_ATTACK : DamageCause.ENTITY_ATTACK;
        if (source instanceof IndirectEntityDamageSource) {
            damager = ((IndirectEntityDamageSource) source).getProximateDamageSource();
            if (damager.getBukkitEntity() instanceof ThrownPotion) {
                cause = DamageCause.MAGIC;
            } else if (damager.getBukkitEntity() instanceof Projectile) {
                cause = DamageCause.PROJECTILE;
            }
        } else if ("thorns".equals(source.msgId)) {
            cause = DamageCause.THORNS;
        }
        return callEntityDamageEvent(damager, entity, cause, modifiers, modifierFunctions, cancelled);
    } else if (source == DamageSource.OUT_OF_WORLD) {
        EntityDamageEvent event = new EntityDamageByBlockEvent(null, entity.getBukkitEntity(), DamageCause.VOID, modifiers, modifierFunctions);
        event.setCancelled(cancelled);
        callEvent(event);
        if (!event.isCancelled()) {
            event.getEntity().setLastDamageCause(event);
        }
        return event;
    } else if (source == DamageSource.LAVA) {
        EntityDamageEvent event = (new EntityDamageByBlockEvent(null, entity.getBukkitEntity(), DamageCause.LAVA, modifiers, modifierFunctions));
        event.setCancelled(cancelled);
        callEvent(event);
        if (!event.isCancelled()) {
            event.getEntity().setLastDamageCause(event);
        }
        return event;
    } else if (blockDamage != null) {
        DamageCause cause = null;
        Block damager = blockDamage;
        blockDamage = null;
        if (source == DamageSource.CACTUS || source == DamageSource.SWEET_BERRY_BUSH) {
            cause = DamageCause.CONTACT;
        } else if (source == DamageSource.HOT_FLOOR) {
            cause = DamageCause.HOT_FLOOR;
        } else if (source == DamageSource.MAGIC) {
            cause = DamageCause.MAGIC;
        } else if (source == DamageSource.FALL) {
            cause = DamageCause.FALL;
        } else if (source == DamageSource.ANVIL || source == DamageSource.FALLING_BLOCK) {
            cause = DamageCause.FALLING_BLOCK;
        } else if (source == DamageSource.IN_FIRE) {
            cause = DamageCause.FIRE;
        } else if (source == DamageSource.ON_FIRE) {
            cause = DamageCause.FIRE_TICK;
        } else if (source == DamageSource.LAVA) {
            cause = DamageCause.LAVA;
        } else if (damager instanceof LightningStrike) {
            cause = DamageCause.LIGHTNING;
        } else if (source == MELTING) {
            cause = DamageCause.MELTING;
        } else if (source == POISON) {
            cause = DamageCause.POISON;
        } else if (source == DamageSource.LIGHTNING_BOLT) {
            cause = DamageCause.LIGHTNING;
        } else if (source == DamageSource.GENERIC) {
            cause = DamageCause.CUSTOM;
        } else {
            cause = DamageCause.CUSTOM;
        }
        EntityDamageEvent event = new EntityDamageByBlockEvent(damager, entity.getBukkitEntity(), cause, modifiers, modifierFunctions);
        event.setCancelled(cancelled);
        callEvent(event);
        if (!event.isCancelled()) {
            event.getEntity().setLastDamageCause(event);
        }
        return event;
    } else if (entityDamage != null) {
        DamageCause cause = null;
        CraftEntity damager = entityDamage.getBukkitEntity();
        entityDamage = null;
        if (source == DamageSource.ANVIL || source == DamageSource.FALLING_BLOCK) {
            cause = DamageCause.FALLING_BLOCK;
        } else if (damager instanceof LightningStrike) {
            cause = DamageCause.LIGHTNING;
        } else if (source == DamageSource.FALL) {
            cause = DamageCause.FALL;
        } else if (source == DamageSource.DRAGON_BREATH) {
            cause = DamageCause.DRAGON_BREATH;
        } else if (source == DamageSource.MAGIC) {
            cause = DamageCause.MAGIC;
        } else if (source == DamageSource.CACTUS) {
            cause = DamageCause.CONTACT;
        } else if (source == DamageSource.IN_FIRE) {
            cause = DamageCause.FIRE;
        } else if (source == DamageSource.ON_FIRE) {
            cause = DamageCause.FIRE_TICK;
        } else if (source == DamageSource.LAVA) {
            cause = DamageCause.LAVA;
        } else if (source == MELTING) {
            cause = DamageCause.MELTING;
        } else if (source == POISON) {
            cause = DamageCause.POISON;
        } else {
            cause = DamageCause.CUSTOM;
        }
        EntityDamageEvent event = new EntityDamageByEntityEvent(damager, entity.getBukkitEntity(), cause, modifiers, modifierFunctions);
        event.setCancelled(cancelled);
        callEvent(event);
        if (!event.isCancelled()) {
            event.getEntity().setLastDamageCause(event);
        }
        return event;
    }
    DamageCause cause = null;
    if (source == DamageSource.IN_FIRE) {
        cause = DamageCause.FIRE;
    } else if (source == DamageSource.STARVE) {
        cause = DamageCause.STARVATION;
    } else if (source == DamageSource.WITHER) {
        cause = DamageCause.WITHER;
    } else if (source == DamageSource.IN_WALL) {
        cause = DamageCause.SUFFOCATION;
    } else if (source == DamageSource.DROWN) {
        cause = DamageCause.DROWNING;
    } else if (source == DamageSource.ON_FIRE) {
        cause = DamageCause.FIRE_TICK;
    } else if (source == MELTING) {
        cause = DamageCause.MELTING;
    } else if (source == POISON) {
        cause = DamageCause.POISON;
    } else if (source == DamageSource.MAGIC) {
        cause = DamageCause.MAGIC;
    } else if (source == DamageSource.FALL) {
        cause = DamageCause.FALL;
    } else if (source == DamageSource.FLY_INTO_WALL) {
        cause = DamageCause.FLY_INTO_WALL;
    } else if (source == DamageSource.CRAMMING) {
        cause = DamageCause.CRAMMING;
    } else if (source == DamageSource.DRY_OUT) {
        cause = DamageCause.DRYOUT;
    } else if (source == DamageSource.GENERIC) {
        cause = DamageCause.CUSTOM;
    }
    if (cause != null) {
        return callEntityDamageEvent(null, entity, cause, modifiers, modifierFunctions, cancelled);
    } else {
        return new EntityDamageEvent(entity.getBukkitEntity(), DamageCause.CUSTOM, modifiers, modifierFunctions);
    }
}
Also used : LightningStrike(org.bukkit.entity.LightningStrike) VillagerEntity(net.minecraft.entity.merchant.villager.VillagerEntity) WaterMobEntity(net.minecraft.entity.passive.WaterMobEntity) ProjectileEntity(net.minecraft.entity.projectile.ProjectileEntity) GolemEntity(net.minecraft.entity.passive.GolemEntity) AbstractRaiderEntity(net.minecraft.entity.monster.AbstractRaiderEntity) SlimeEntity(net.minecraft.entity.monster.SlimeEntity) LivingEntity(org.bukkit.entity.LivingEntity) ExperienceOrbEntity(net.minecraft.entity.item.ExperienceOrbEntity) AreaEffectCloudEntity(net.minecraft.entity.AreaEffectCloudEntity) StriderEntity(net.minecraft.entity.passive.StriderEntity) PotionEntity(net.minecraft.entity.projectile.PotionEntity) AnimalEntity(net.minecraft.entity.passive.AnimalEntity) EnderDragonEntity(net.minecraft.entity.boss.dragon.EnderDragonEntity) MonsterEntity(net.minecraft.entity.monster.MonsterEntity) CraftEntity(org.bukkit.craftbukkit.v1_16_R3.entity.CraftEntity) PlayerEntity(net.minecraft.entity.player.PlayerEntity) SpellcastingIllagerEntity(net.minecraft.entity.monster.SpellcastingIllagerEntity) ServerPlayerEntity(net.minecraft.entity.player.ServerPlayerEntity) FireworkRocketEntity(net.minecraft.entity.projectile.FireworkRocketEntity) MobEntity(net.minecraft.entity.MobEntity) HumanEntity(org.bukkit.entity.HumanEntity) Entity(net.minecraft.entity.Entity) GhastEntity(net.minecraft.entity.monster.GhastEntity) ItemEntity(net.minecraft.entity.item.ItemEntity) CraftLivingEntity(org.bukkit.craftbukkit.v1_16_R3.entity.CraftLivingEntity) EnderDragonEntity(net.minecraft.entity.boss.dragon.EnderDragonEntity) EntityDamageByBlockEvent(org.bukkit.event.entity.EntityDamageByBlockEvent) CraftEntity(org.bukkit.craftbukkit.v1_16_R3.entity.CraftEntity) IndirectEntityDamageSource(net.minecraft.util.IndirectEntityDamageSource) EntityDamageSource(net.minecraft.util.EntityDamageSource) Projectile(org.bukkit.entity.Projectile) EntityDamageByEntityEvent(org.bukkit.event.entity.EntityDamageByEntityEvent) ThrownPotion(org.bukkit.entity.ThrownPotion) CraftBlock(org.bukkit.craftbukkit.v1_16_R3.block.CraftBlock) Block(org.bukkit.block.Block) DamageCause(org.bukkit.event.entity.EntityDamageEvent.DamageCause) IndirectEntityDamageSource(net.minecraft.util.IndirectEntityDamageSource) EntityDamageEvent(org.bukkit.event.entity.EntityDamageEvent)

Example 92 with CraftEntity

use of org.bukkit.craftbukkit.v1_8_R1.entity.CraftEntity in project jojokobi-util by JonathanDotExe.

the class NMSEntityUtil method rotateVehicle.

public static void rotateVehicle(Entity entity, float yaw, float pitch) {
    CraftEntity craftEntity = (CraftEntity) entity;
    net.minecraft.world.entity.Entity e = craftEntity.getHandle();
    e.setXRot(pitch);
    e.setYRot(yaw);
}
Also used : CraftEntity(org.bukkit.craftbukkit.v1_18_R2.entity.CraftEntity)

Example 93 with CraftEntity

use of org.bukkit.craftbukkit.v1_8_R1.entity.CraftEntity in project NyaaCore by NyaaCat.

the class RayTraceUtils method rayTraceEntities.

public static List<LivingEntity> rayTraceEntities(LivingEntity player, float distance, Predicate<Entity> predicate) {
    List<LivingEntity> result = new ArrayList<>();
    Vector start = player.getEyeLocation().toVector();
    Vector end = start.clone().add(player.getEyeLocation().getDirection().multiply(distance));
    for (Entity e : player.getWorld().getNearbyEntities(player.getEyeLocation(), distance, distance, distance, predicate)) {
        if (e instanceof LivingEntity && e instanceof CraftEntity && e.isValid()) {
            net.minecraft.world.entity.Entity nmsEntity = ((CraftEntity) e).getHandle();
            Optional<Vec3D> hit = nmsEntity.getBoundingBox().clip(toVec3DInternal(start), toVec3DInternal(end));
            if (hit.isPresent()) {
                result.add((LivingEntity) e);
            }
        }
    }
    return result;
}
Also used : LivingEntity(org.bukkit.entity.LivingEntity) Entity(org.bukkit.entity.Entity) LivingEntity(org.bukkit.entity.LivingEntity) CraftEntity(org.bukkit.craftbukkit.v1_18_R2.entity.CraftEntity) ArrayList(java.util.ArrayList) CraftEntity(org.bukkit.craftbukkit.v1_18_R2.entity.CraftEntity) Vector(org.bukkit.util.Vector) Vec3D(net.minecraft.world.phys.Vec3D)

Example 94 with CraftEntity

use of org.bukkit.craftbukkit.v1_8_R1.entity.CraftEntity in project Panilla by ds58.

the class PacketInspector method stripNbtFromItemEntity.

@Override
public void stripNbtFromItemEntity(UUID entityId) {
    org.bukkit.entity.Entity bukkitEntity = Bukkit.getServer().getEntity(entityId);
    if (bukkitEntity instanceof CraftEntity) {
        CraftEntity craftEntity = (CraftEntity) bukkitEntity;
        Entity entity = craftEntity.getHandle();
        if (entity instanceof EntityItem) {
            EntityItem item = (EntityItem) entity;
            if (item.getItemStack() == null) {
                return;
            }
            if (!item.getItemStack().hasTag()) {
                return;
            }
            item.getItemStack().setTag(null);
        }
    }
}
Also used : CraftEntity(org.bukkit.craftbukkit.v1_15_R1.entity.CraftEntity) CraftEntity(org.bukkit.craftbukkit.v1_15_R1.entity.CraftEntity)

Example 95 with CraftEntity

use of org.bukkit.craftbukkit.v1_8_R1.entity.CraftEntity in project Panilla by ds58.

the class PacketInspector method stripNbtFromItemEntity.

@Override
public void stripNbtFromItemEntity(UUID entityId) {
    org.bukkit.entity.Entity bukkitEntity = Bukkit.getServer().getEntity(entityId);
    if (bukkitEntity instanceof CraftEntity) {
        CraftEntity craftEntity = (CraftEntity) bukkitEntity;
        Entity entity = craftEntity.getHandle();
        if (entity instanceof EntityItem) {
            EntityItem item = (EntityItem) entity;
            if (item.getItemStack() == null) {
                return;
            }
            if (!item.getItemStack().hasTag()) {
                return;
            }
            item.getItemStack().setTag(null);
        }
    }
}
Also used : CraftEntity(org.bukkit.craftbukkit.v1_16_R1.entity.CraftEntity) CraftEntity(org.bukkit.craftbukkit.v1_16_R1.entity.CraftEntity)

Aggregations

Location (org.bukkit.Location)40 Entity (org.bukkit.entity.Entity)38 LivingEntity (org.bukkit.entity.LivingEntity)33 Entity (net.minecraft.world.entity.Entity)25 CraftEntity (org.bukkit.craftbukkit.v1_17_R1.entity.CraftEntity)25 CraftEntity (org.bukkit.craftbukkit.v1_18_R2.entity.CraftEntity)24 Iterator (java.util.Iterator)21 List (java.util.List)21 CraftEntity (org.bukkit.craftbukkit.v1_16_R3.entity.CraftEntity)21 UUID (java.util.UUID)20 CraftEntity (org.bukkit.craftbukkit.v1_18_R1.entity.CraftEntity)20 CraftEntity (org.bukkit.craftbukkit.v1_12_R1.entity.CraftEntity)17 Player (org.bukkit.entity.Player)16 CraftEntity (org.bukkit.craftbukkit.v1_8_R3.entity.CraftEntity)15 Vector (org.bukkit.util.Vector)14 EntityAttachmentHelper (com.denizenscript.denizen.utilities.entity.EntityAttachmentHelper)12 Vec3 (net.minecraft.world.phys.Vec3)12 SkinnableEntity (net.citizensnpcs.npc.skin.SkinnableEntity)11 EntityDamageSource (net.minecraft.world.damagesource.EntityDamageSource)11 EnteredStateTracker (com.elmakers.mine.bukkit.utility.EnteredStateTracker)10