use of org.bukkit.event.entity.EntityDamageEvent in project PGM by PGMDev.
the class CombatLogTracker method onQuit.
// This must be called BEFORE the listener that removes the player from the match
@EventHandler(priority = EventPriority.LOWEST, ignoreCancelled = true)
public void onQuit(PlayerQuitEvent event) {
Match match = PGM.get().getMatchManager().getMatch(event.getPlayer().getWorld());
if (match == null || !match.isRunning())
return;
MatchPlayer player = match.getPlayer(event.getPlayer());
if (player == null || !player.isParticipating())
return;
ImminentDeath imminentDeath = this.getImminentDeath(player.getBukkit());
if (imminentDeath == null)
return;
if (!imminentDeath.alreadyDamaged) {
// Simulate the damage event that would have killed them,
// allowing the tracker to figure out the cause of death
EntityDamageEvent damageEvent;
if (imminentDeath.blockDamager != null) {
damageEvent = new EntityDamageByBlockEvent(imminentDeath.blockDamager, player.getBukkit(), imminentDeath.cause, player.getBukkit().getHealth());
} else {
damageEvent = new EntityDamageEvent(player.getBukkit(), imminentDeath.cause, player.getBukkit().getHealth());
}
match.callEvent(damageEvent);
// If the damage event was cancelled, don't simulate the kill
if (damageEvent.isCancelled())
return;
player.getBukkit().setLastDamageCause(damageEvent);
}
// Simulate the player's death. The tracker will assume the death was caused by the
// last damage event, which was either a real one or the fake one we generated above.
ArrayList<ItemStack> drops = new ArrayList<>();
for (ItemStack stack : player.getInventory().getContents()) {
if (stack != null && stack.getType() != Material.AIR)
drops.add(stack);
}
for (ItemStack stack : player.getInventory().getArmorContents()) {
if (stack != null && stack.getType() != Material.AIR)
drops.add(stack);
}
try {
currentDeathEvent = new PlayerDeathEvent(player.getBukkit(), drops, 0, player.getBukkit().getDisplayName() + " logged out to avoid death");
match.callEvent(currentDeathEvent);
} finally {
currentDeathEvent = null;
}
}
use of org.bukkit.event.entity.EntityDamageEvent in project PGM by PGMDev.
the class DeathTracker method getLastDamage.
@Nullable
DamageInfo getLastDamage(MatchPlayer victim) {
DamageInfo info = lastDamageInfos.get(victim);
if (info != null)
return info;
EntityDamageEvent damageEvent = victim.getBukkit().getLastDamageCause();
if (damageEvent != null) {
return tmm.resolveDamage(damageEvent);
}
return null;
}
use of org.bukkit.event.entity.EntityDamageEvent in project LifeSkript by LifeMC.
the class EffIgnite method execute.
@Override
protected void execute(final Event e) {
final int d;
if (duration != null) {
final Timespan t = duration.getSingle(e);
if (t == null)
return;
d = (int) (t.getTicks_i() >= Integer.MAX_VALUE ? Integer.MAX_VALUE : t.getTicks_i());
} else {
d = ignite ? DEFAULT_DURATION : 0;
}
for (final Entity en : entities.getArray(e)) {
if (e instanceof EntityDamageEvent && ((EntityDamageEvent) e).getEntity() == en && !Delay.isDelayed(e)) {
Bukkit.getScheduler().scheduleSyncDelayedTask(Skript.getInstance(), () -> en.setFireTicks(d));
} else {
if (e instanceof EntityCombustEvent && ((EntityCombustEvent) e).getEntity() == en && !Delay.isDelayed(e))
// can't change the duration, thus simply cancel the event (and create a new one)
((EntityCombustEvent) e).setCancelled(true);
en.setFireTicks(d);
}
}
}
use of org.bukkit.event.entity.EntityDamageEvent in project Denizen-For-Bukkit 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 NoCheatPlus by NoCheatPlus.
the class NoFall method dealFallDamage.
private void dealFallDamage(final Player player, final double damage) {
if (mcAccess.getHandle().dealFallDamageFiresAnEvent().decide()) {
// TODO: Better decideOptimistically?
mcAccess.getHandle().dealFallDamage(player, damage);
} else {
final EntityDamageEvent event = BridgeHealth.getEntityDamageEvent(player, DamageCause.FALL, damage);
Bukkit.getPluginManager().callEvent(event);
if (!event.isCancelled()) {
// TODO: account for no damage ticks etc.
player.setLastDamageCause(event);
mcAccess.getHandle().dealFallDamage(player, BridgeHealth.getRawDamage(event));
}
}
// Currently resetting is done from within the damage event handler.
// TODO: MUST detect if event fired at all (...) and override, if necessary. Best probe once per class (with YES).
// data.clearNoFallData();
player.setFallDistance(0);
}
Aggregations