}
}
// System.out.println(event.getCause());
// Attacking entities.
if (event instanceof EntityDamageByEntityEvent) {
final EntityDamageByEntityEvent e = (EntityDamageByEntityEvent) event;
final Entity damager = e.getDamager();
final int tick = TickTask.getTick();
if (damagedPlayer != null && !damagedIsDead){
// TODO: check once more when to set this (!) in terms of order.
FightData.getData(damagedPlayer).damageTakenByEntityTick = tick;
if (hasThorns(damagedPlayer)){
// TODO: Cleanup here.
// Remember the id of the attacker to allow counter damage.
damagedData.thornsId = damager.getEntityId();
}
else{
damagedData.thornsId = Integer.MIN_VALUE;
}
}
final DamageCause damageCause = event.getCause();
final Player player = damager instanceof Player ? (Player) damager : null;
Player attacker = player;
// TODO: deobfuscate.
if (damager instanceof TNTPrimed) {
final Entity source = ((TNTPrimed) damager).getSource();
if (source instanceof Player) {
attacker = (Player) source;
}
}
if (attacker != null && (damageCause == DamageCause.BLOCK_EXPLOSION || damageCause == DamageCause.ENTITY_EXPLOSION)) {
// NOTE: Pigs don't have data.
final FightData data = FightData.getData(attacker);
data.lastExplosionEntityId = damaged.getEntityId();
data.lastExplosionDamageTick = tick;
return;
}
if (player != null){
final double damage = BridgeHealth.getDamage(e);
final FightData data = FightData.getData(player);
if (damageCause == DamageCause.ENTITY_ATTACK){
// TODO: Might/should skip the damage comparison, though checking on lowest priority.
if (damaged.getEntityId() == data.lastExplosionEntityId && tick == data.lastExplosionDamageTick) {
data.lastExplosionDamageTick = -1;
data.lastExplosionEntityId = Integer.MAX_VALUE;
} else if (handleNormalDamage(player, damaged, damage, tick, data)){
e.setCancelled(true);
}
}
}
}
}