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
No known key found for this signature in database
GPG Key ID: A3F61EA5A085289C
2 changed files with 21 additions and 38 deletions

View File

@ -252,24 +252,6 @@ public class EntityListener implements Listener {
Bukkit.broadcastMessage(""); Bukkit.broadcastMessage("");
}*/ }*/
@EventHandler(priority = EventPriority.LOWEST, ignoreCancelled = true)
public void onEntityDamageLowest(EntityDamageByEntityEvent event)
{
Entity defender = event.getEntity();
if(defender.getMetadata(mcMMO.CUSTOM_DAMAGE_METAKEY).size() > 0)
{
if(defender instanceof Player)
{
LivingEntity defLive = (LivingEntity) defender;
defLive.setHealth(Math.max(0, (defLive.getHealth() - event.getFinalDamage())));
event.setCancelled(true);
}
return;
}
}
@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true) @EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
public void onEntityCombustByEntityEvent(EntityCombustByEntityEvent event) { public void onEntityCombustByEntityEvent(EntityCombustByEntityEvent event) {
//Prevent players from setting fire to each other if they are in the same party //Prevent players from setting fire to each other if they are in the same party
@ -330,6 +312,13 @@ public class EntityListener implements Listener {
return; return;
} }
// Don't process this event for marked entities, for players this is handled above,
// However, for entities, we do not wanna cancel this event to allow plugins to observe changes
// properly
if (defender.getMetadata(mcMMO.CUSTOM_DAMAGE_METAKEY).size() > 0) {
return;
}
if (event.getEntity() instanceof ArmorStand) { if (event.getEntity() instanceof ArmorStand) {
return; return;
} }

View File

@ -558,21 +558,19 @@ public final class CombatUtils {
return; return;
} }
double incDmg = getFakeDamageFinalResult(attacker, target, DamageCause.ENTITY_ATTACK, damage); // 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,
double newHealth = Math.max(0, target.getHealth() - incDmg); // 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
if(newHealth == 0) // 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;
// TODO: This is horrible, but there is no cleaner way to do this without potentially breaking existing code right now target.setMetadata(mcMMO.CUSTOM_DAMAGE_METAKEY, mcMMO.metadataValue);
boolean wasMetaSet = target.getMetadata(mcMMO.CUSTOM_DAMAGE_METAKEY).size() != 0; int noDamageTicks = target.getNoDamageTicks();
target.setMetadata(mcMMO.CUSTOM_DAMAGE_METAKEY, mcMMO.metadataValue); target.setNoDamageTicks(0);
target.damage(9999, attacker); target.damage(damage, attacker);
if (!wasMetaSet) target.setNoDamageTicks(noDamageTicks);
target.removeMetadata(mcMMO.CUSTOM_DAMAGE_METAKEY, mcMMO.p); if (!wasMetaSet)
} target.removeMetadata(mcMMO.CUSTOM_DAMAGE_METAKEY, mcMMO.p);
else
target.setHealth(newHealth);
} }
public static void dealNoInvulnerabilityTickDamageRupture(LivingEntity target, double damage, Entity attacker, int toolTier) { public static void dealNoInvulnerabilityTickDamageRupture(LivingEntity target, double damage, Entity attacker, int toolTier) {
@ -580,11 +578,7 @@ public final class CombatUtils {
return; return;
} }
// This is horrible, but there is no cleaner way to do this without potentially breaking existing code dealNoInvulnerabilityTickDamage(target, damage, attacker);
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);
// //IFrame storage // //IFrame storage
//// int noDamageTicks = target.getNoDamageTicks(); //// int noDamageTicks = target.getNoDamageTicks();