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);
}
}
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);
}
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;
}
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);
}
}
}
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);
}
}
}
Aggregations