Passing the event is bad - pass just event.getDamage() instead.

This commit is contained in:
GJ 2013-02-22 12:10:15 -05:00
parent 3b07d4055a
commit 63974f3968
2 changed files with 8 additions and 7 deletions

View File

@ -131,7 +131,7 @@ public class EntityListener implements Listener {
if (defender instanceof LivingEntity) {
LivingEntity livingDefender = (LivingEntity) defender;
if (!CombatTools.isInvincible(livingDefender, event)) {
if (!CombatTools.isInvincible(livingDefender, event.getDamage())) {
CombatTools.combatChecks(event, attacker, livingDefender);
}
}
@ -160,6 +160,7 @@ public class EntityListener implements Listener {
if (livingEntity instanceof Player) {
Player player = (Player) entity;
// TODO: Is it even possible for the player to be off-line here?
if (!player.isOnline() || Misc.isNPCEntity(player)) {
return;
}
@ -173,7 +174,7 @@ public class EntityListener implements Listener {
return;
}
if (!CombatTools.isInvincible(player, event)) {
if (!CombatTools.isInvincible(player, event.getDamage())) {
if (cause == DamageCause.FALL && player.getItemInHand().getType() != Material.ENDER_PEARL && !(Acrobatics.afkLevelingDisabled && player.isInsideVehicle()) && Permissions.roll(player)) {
AcrobaticsManager acrobaticsManager = new AcrobaticsManager(mcMMOPlayer);
acrobaticsManager.rollCheck(event);
@ -192,7 +193,7 @@ public class EntityListener implements Listener {
Tameable pet = (Tameable) livingEntity;
AnimalTamer owner = pet.getOwner();
if ((!CombatTools.isInvincible(livingEntity, event)) && pet.isTamed() && owner instanceof Player && pet instanceof Wolf) {
if ((!CombatTools.isInvincible(livingEntity, event.getDamage())) && pet.isTamed() && owner instanceof Player && pet instanceof Wolf) {
TamingManager tamingManager = new TamingManager(Users.getPlayer((Player) owner));
tamingManager.preventDamage(event);
}

View File

@ -572,17 +572,17 @@ public final class CombatTools {
/**
* Checks to see if an entity is currently invincible.
*
* @param le The LivingEntity to check
* @param event The event the entity is involved in
* @param entity The {@link LivingEntity} to check
* @param eventDamage The damage from the event the entity is involved in
* @return true if the entity is invincible, false otherwise
*/
public static boolean isInvincible(LivingEntity le, EntityDamageEvent event) {
public static boolean isInvincible(LivingEntity entity, int eventDamage) {
/*
* So apparently if you do more damage to a LivingEntity than its last damage int you bypass the invincibility.
* So yeah, this is for that.
*/
if (le.getNoDamageTicks() > le.getMaximumNoDamageTicks() / 2.0F && event.getDamage() <= le.getLastDamage()) {
if ((entity.getNoDamageTicks() > entity.getMaximumNoDamageTicks() / 2.0F) && (eventDamage <= entity.getLastDamage())) {
return true;
}