use of org.bukkit.event.entity.EntityDamageEvent in project Denizen by DenizenScript.
the class EntityHelperImpl method damage.
@Override
public void damage(LivingEntity target, float amount, Entity source, EntityDamageEvent.DamageCause cause) {
if (target == null) {
return;
}
EntityLiving nmsTarget = ((CraftLivingEntity) target).getHandle();
net.minecraft.server.v1_16_R3.Entity nmsSource = source == null ? null : ((CraftEntity) source).getHandle();
CraftEventFactory.entityDamage = nmsSource;
try {
DamageSource src = DamageSource.GENERIC;
if (nmsSource != null) {
if (nmsSource instanceof EntityHuman) {
src = DamageSource.playerAttack((EntityHuman) nmsSource);
} else if (nmsSource instanceof EntityLiving) {
src = DamageSource.mobAttack((EntityLiving) nmsSource);
}
}
if (cause != null) {
switch(cause) {
case CONTACT:
src = DamageSource.CACTUS;
break;
case ENTITY_ATTACK:
src = DamageSource.mobAttack(nmsSource instanceof EntityLiving ? (EntityLiving) nmsSource : null);
break;
case ENTITY_SWEEP_ATTACK:
if (src != DamageSource.GENERIC) {
src.sweep();
}
break;
case PROJECTILE:
src = DamageSource.projectile(nmsSource, source instanceof Projectile && ((Projectile) source).getShooter() instanceof Entity ? ((CraftEntity) ((Projectile) source).getShooter()).getHandle() : null);
break;
case SUFFOCATION:
src = DamageSource.STUCK;
break;
case FALL:
src = DamageSource.FALL;
break;
case FIRE:
src = DamageSource.FIRE;
break;
case FIRE_TICK:
src = DamageSource.BURN;
break;
case MELTING:
src = CraftEventFactory.MELTING;
break;
case LAVA:
src = DamageSource.LAVA;
break;
case DROWNING:
src = DamageSource.DROWN;
break;
case BLOCK_EXPLOSION:
src = DamageSource.d(nmsSource instanceof TNTPrimed && ((TNTPrimed) nmsSource).getSource() instanceof EntityLiving ? (EntityLiving) ((TNTPrimed) nmsSource).getSource() : null);
break;
case ENTITY_EXPLOSION:
src = DamageSource.d(nmsSource instanceof EntityLiving ? (EntityLiving) nmsSource : null);
break;
case VOID:
src = DamageSource.OUT_OF_WORLD;
break;
case LIGHTNING:
src = DamageSource.LIGHTNING;
break;
case STARVATION:
src = DamageSource.STARVE;
break;
case POISON:
src = CraftEventFactory.POISON;
break;
case MAGIC:
src = DamageSource.MAGIC;
break;
case WITHER:
src = DamageSource.WITHER;
break;
case FALLING_BLOCK:
src = DamageSource.FALLING_BLOCK;
break;
case THORNS:
src = DamageSource.a(nmsSource);
break;
case DRAGON_BREATH:
src = DamageSource.DRAGON_BREATH;
break;
case CUSTOM:
src = DamageSource.GENERIC;
break;
case FLY_INTO_WALL:
src = DamageSource.FLY_INTO_WALL;
break;
case HOT_FLOOR:
src = DamageSource.HOT_FLOOR;
break;
case CRAMMING:
src = DamageSource.CRAMMING;
break;
case DRYOUT:
src = DamageSource.DRYOUT;
break;
// case SUICIDE:
default:
EntityDamageEvent ede = fireFakeDamageEvent(target, source, cause, amount);
if (ede.isCancelled()) {
return;
}
break;
}
}
nmsTarget.damageEntity(src, amount);
} finally {
CraftEventFactory.entityDamage = null;
}
}
use of org.bukkit.event.entity.EntityDamageEvent in project Denizen by DenizenScript.
the class EntityHelperImpl method damage.
@Override
public void damage(LivingEntity target, float amount, Entity source, EntityDamageEvent.DamageCause cause) {
if (target == null) {
return;
}
net.minecraft.world.entity.LivingEntity nmsTarget = ((CraftLivingEntity) target).getHandle();
net.minecraft.world.entity.Entity nmsSource = source == null ? null : ((CraftEntity) source).getHandle();
CraftEventFactory.entityDamage = nmsSource;
try {
DamageSource src = getSourceFor(nmsSource, cause);
if (src instanceof FakeDamageSrc) {
src = ((FakeDamageSrc) src).real;
EntityDamageEvent ede = fireFakeDamageEvent(target, source, cause, amount);
if (ede.isCancelled()) {
return;
}
}
nmsTarget.hurt(src, amount);
} finally {
CraftEventFactory.entityDamage = null;
}
}
use of org.bukkit.event.entity.EntityDamageEvent in project Denizen by DenizenScript.
the class EntityHelper method fireFakeDamageEvent.
public static EntityDamageEvent fireFakeDamageEvent(Entity target, Entity source, EntityDamageEvent.DamageCause cause, float amount) {
EntityDamageEvent ede = source == null ? new EntityDamageEvent(target, cause, amount) : new EntityDamageByEntityEvent(source, target, cause, amount);
Bukkit.getPluginManager().callEvent(ede);
return ede;
}
use of org.bukkit.event.entity.EntityDamageEvent in project Denizen by DenizenScript.
the class EntityHelper method damage.
public void damage(LivingEntity target, float amount, Entity source, EntityDamageEvent.DamageCause cause) {
if (cause == null) {
if (source == null) {
target.damage(amount);
} else {
target.damage(amount, source);
}
} else {
EntityDamageEvent ede = fireFakeDamageEvent(target, source, cause, amount);
if (!ede.isCancelled()) {
target.setLastDamageCause(ede);
if (source == null) {
target.damage(ede.getFinalDamage());
} else {
target.damage(ede.getFinalDamage(), source);
}
target.setLastDamageCause(ede);
}
}
}
use of org.bukkit.event.entity.EntityDamageEvent in project AllMiniGames by MiniGameWorlds.
the class Tiny method onEvent.
@Override
protected void onEvent(Event event) {
if (event instanceof ProjectileHitEvent) {
ProjectileHitEvent e = (ProjectileHitEvent) event;
Entity hitEntity = e.getHitEntity();
if (hitEntity != null && hitEntity.equals(this.bat)) {
// event detector can detect shooter from ProjectileHitEvent
plusScore(1);
// sound
SoundTool.play(hitEntity.getLocation(), Sound.BLOCK_NOTE_BLOCK_BELL);
// particle
spawnHitParticles(hitEntity);
}
} else if (event instanceof ProjectileLaunchEvent) {
ProjectileLaunchEvent e = (ProjectileLaunchEvent) event;
Projectile proj = e.getEntity();
ProjectileSource shooterEntity = proj.getShooter();
// event detector can detect player from ProjectileLaunchEvent
Player shooter = (Player) shooterEntity;
// don't change amount of snowball
shooter.getInventory().addItem(new ItemStack(Material.SNOWBALL));
// give cooldown
shooter.setCooldown(Material.SNOWBALL, 20);
} else if (event instanceof EntityDamageEvent) {
EntityDamageEvent e = (EntityDamageEvent) event;
if (e.getEntity().equals(this.bat)) {
e.setDamage(0);
}
} else if (event instanceof EntityDeathEvent) {
EntityDeathEvent e = (EntityDeathEvent) event;
if (e.getEntity().equals(this.bat)) {
summonBat();
}
}
}
Aggregations