Don't process mcmmo damage for invuln (#4028)

This commit is contained in:
Shane Freeder
2019-08-24 17:40:27 +01:00
parent 44a3238c79
commit 5ea2c493e8
2 changed files with 21 additions and 38 deletions

View File

@ -558,21 +558,19 @@ public final class CombatUtils {
return;
}
double incDmg = getFakeDamageFinalResult(attacker, target, DamageCause.ENTITY_ATTACK, damage);
double newHealth = Math.max(0, target.getHealth() - incDmg);
if(newHealth == 0)
{
// TODO: This is horrible, but there is no cleaner way to do this without potentially breaking existing code right now
boolean wasMetaSet = target.getMetadata(mcMMO.CUSTOM_DAMAGE_METAKEY).size() != 0;
target.setMetadata(mcMMO.CUSTOM_DAMAGE_METAKEY, mcMMO.metadataValue);
target.damage(9999, attacker);
if (!wasMetaSet)
target.removeMetadata(mcMMO.CUSTOM_DAMAGE_METAKEY, mcMMO.p);
}
else
target.setHealth(newHealth);
// TODO: This is horrible, but there is no cleaner way to do this without potentially breaking existing code right now
// calling damage here is a double edged sword: On one hand, without a call, plugins won't see this properly when the entity dies,
// potentially mis-attributing the death cause; calling a fake event would partially fix this, but this and setting the last damage
// cause do have issues around plugin observability. This is not a perfect solution, but it appears to be the best one here
// We also set no damage ticks to 0, to ensure that damage is applied for this case, and reset it back to the original value
boolean wasMetaSet = target.getMetadata(mcMMO.CUSTOM_DAMAGE_METAKEY).size() != 0;
target.setMetadata(mcMMO.CUSTOM_DAMAGE_METAKEY, mcMMO.metadataValue);
int noDamageTicks = target.getNoDamageTicks();
target.setNoDamageTicks(0);
target.damage(damage, attacker);
target.setNoDamageTicks(noDamageTicks);
if (!wasMetaSet)
target.removeMetadata(mcMMO.CUSTOM_DAMAGE_METAKEY, mcMMO.p);
}
public static void dealNoInvulnerabilityTickDamageRupture(LivingEntity target, double damage, Entity attacker, int toolTier) {
@ -580,11 +578,7 @@ public final class CombatUtils {
return;
}
// This is horrible, but there is no cleaner way to do this without potentially breaking existing code
boolean wasMetaSet = target.getMetadata(mcMMO.CUSTOM_DAMAGE_METAKEY).size() != 0;
target.setMetadata(mcMMO.CUSTOM_DAMAGE_METAKEY, mcMMO.metadataValue);
target.damage(damage, attacker);
if (!wasMetaSet) target.removeMetadata(mcMMO.CUSTOM_DAMAGE_METAKEY, mcMMO.p);
dealNoInvulnerabilityTickDamage(target, damage, attacker);
// //IFrame storage
//// int noDamageTicks = target.getNoDamageTicks();