Correct TNT workaround (pigs don't have fight-data).

This commit is contained in:
asofold 2013-11-07 02:52:12 +01:00
parent b43fa259dc
commit 10e5e96388
2 changed files with 35 additions and 29 deletions

View File

@ -138,12 +138,10 @@ public class FightData extends ACheckData {
public int speedShortTermTick; public int speedShortTermTick;
// TNT workaround: Allow ENTITY_ATTACK if these attributes match. // TNT workaround: Allow ENTITY_ATTACK if these attributes match.
/** Amount of damage dealt by the last explosion. */
public double lastExplosionDamage = Double.MAX_VALUE;
/** Tick the last explosion damage was dealt at. */ /** Tick the last explosion damage was dealt at. */
public int lastExplosionDamageTick = -1 ; public int lastExplosionDamageTick = -1 ;
/** Last explosion damage causing player (damager). */ /** Last explosion damaged entity (id). */
public String lastExplosionDamagePlayer = null; public int lastExplosionEntityId = Integer.MAX_VALUE;
public FightData(final FightConfig cc){ public FightData(final FightConfig cc){

View File

@ -4,6 +4,7 @@ import org.bukkit.Location;
import org.bukkit.enchantments.Enchantment; import org.bukkit.enchantments.Enchantment;
import org.bukkit.entity.Entity; import org.bukkit.entity.Entity;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import org.bukkit.entity.TNTPrimed;
import org.bukkit.event.EventHandler; import org.bukkit.event.EventHandler;
import org.bukkit.event.EventPriority; import org.bukkit.event.EventPriority;
import org.bukkit.event.entity.EntityDamageByEntityEvent; import org.bukkit.event.entity.EntityDamageByEntityEvent;
@ -92,9 +93,8 @@ public class FightListener extends CheckListener implements JoinLeaveListener{
* The EntityDamageByEntityEvent * The EntityDamageByEntityEvent
* @return * @return
*/ */
private boolean handleNormalDamage(final Player player, final Entity damaged, final double damage, final int tick) { private boolean handleNormalDamage(final Player player, final Entity damaged, final double damage, final int tick, final FightData data) {
final FightConfig cc = FightConfig.getConfig(player); final FightConfig cc = FightConfig.getConfig(player);
final FightData data = FightData.getData(player);
// Hotfix attempt for enchanted books. // Hotfix attempt for enchanted books.
// TODO: maybe a generaluzed version for the future... // TODO: maybe a generaluzed version for the future...
@ -306,9 +306,10 @@ public class FightListener extends CheckListener implements JoinLeaveListener{
if (event instanceof EntityDamageByEntityEvent) { if (event instanceof EntityDamageByEntityEvent) {
final EntityDamageByEntityEvent e = (EntityDamageByEntityEvent) event; final EntityDamageByEntityEvent e = (EntityDamageByEntityEvent) event;
final Entity damager = e.getDamager(); final Entity damager = e.getDamager();
final int tick = TickTask.getTick();
if (damagedPlayer != null && !damagedIsDead){ if (damagedPlayer != null && !damagedIsDead){
// TODO: check once more when to set this (!) in terms of order. // TODO: check once more when to set this (!) in terms of order.
FightData.getData(damagedPlayer).damageTakenByEntityTick = TickTask.getTick(); FightData.getData(damagedPlayer).damageTakenByEntityTick = tick;
if (hasThorns(damagedPlayer)){ if (hasThorns(damagedPlayer)){
// TODO: Cleanup here. // TODO: Cleanup here.
// Remember the id of the attacker to allow counter damage. // Remember the id of the attacker to allow counter damage.
@ -318,28 +319,35 @@ public class FightListener extends CheckListener implements JoinLeaveListener{
damagedData.thornsId = Integer.MIN_VALUE; damagedData.thornsId = Integer.MIN_VALUE;
} }
} }
if (damager instanceof Player){ final DamageCause damageCause = event.getCause();
final Player player = (Player) damager; final Player player = damager instanceof Player ? (Player) damager : null;
final DamageCause damageCause = event.getCause(); Player attacker = player;
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)) {
final FightData data = FightData.getData(attacker);
data.lastExplosionEntityId = damaged.getEntityId();
data.lastExplosionDamageTick = tick;
return;
}
if (player != null){
final double damage = BridgeHealth.getDamage(e); final double damage = BridgeHealth.getDamage(e);
final int tick = TickTask.getTick(); final FightData data = FightData.getData(player);
if (damageCause == DamageCause.BLOCK_EXPLOSION || damageCause == DamageCause.ENTITY_EXPLOSION) { // NOTE: Pigs don't have data.
if (damagedData != null) { if (damageCause == DamageCause.BLOCK_EXPLOSION || damageCause == DamageCause.ENTITY_EXPLOSION) {
damagedData.lastExplosionDamagePlayer = player.getName(); data.lastExplosionEntityId = damaged.getEntityId();
damagedData.lastExplosionDamageTick = tick; data.lastExplosionDamageTick = tick;
damagedData.lastExplosionDamage = BridgeHealth.getDamage(event); }
} if (damageCause == DamageCause.ENTITY_ATTACK){
} else if (e.getCause() == DamageCause.ENTITY_ATTACK){ // TODO: Might/should skip the damage comparison, though checking on lowest priority.
if (damagedData != null) { if (damaged.getEntityId() == data.lastExplosionEntityId && tick == data.lastExplosionDamageTick) {
// TODO: Might/should skip the damage comparison, though checking on lowest priority. data.lastExplosionDamageTick = -1;
if (damage == damagedData.lastExplosionDamage && player.getName().equals(damagedData.lastExplosionDamagePlayer) && tick == damagedData.lastExplosionDamageTick) { data.lastExplosionEntityId = Integer.MAX_VALUE;
damagedData.lastExplosionDamage = Double.MAX_VALUE; } else if (handleNormalDamage(player, damaged, damage, tick, data)){
damagedData.lastExplosionDamageTick = -1;
damagedData.lastExplosionDamagePlayer = null;
return;
}
}
if (handleNormalDamage(player, damaged, damage, tick)){
e.setCancelled(true); e.setCancelled(true);
} }
} }