Prevent nesting of bleed damage

This commit prevents the nesting of damage event processing in general in
regards to bleed, health related stuff will need a further glance over down
the line, however; This will fix a major problematic area
This commit is contained in:
Shane Freeder 2019-11-13 19:53:02 +00:00
parent 3ce0d7b972
commit b7dd491c01
No known key found for this signature in database
GPG Key ID: A3F61EA5A085289C
2 changed files with 17 additions and 0 deletions

View File

@ -319,6 +319,10 @@ public class EntityListener implements Listener {
return; return;
} }
if (CombatUtils.isProcessingNoInvulnDamage()) {
return;
}
if (event.getEntity() instanceof ArmorStand) { if (event.getEntity() instanceof ArmorStand) {
return; return;
} }

View File

@ -39,6 +39,8 @@ import java.util.HashMap;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import javax.annotation.Nullable;
public final class CombatUtils { public final class CombatUtils {
private CombatUtils() {} private CombatUtils() {}
@ -554,6 +556,11 @@ public final class CombatUtils {
target.damage(damage); target.damage(damage);
} }
private static boolean processingNoInvulnDamage;
public static boolean isProcessingNoInvulnDamage() {
return processingNoInvulnDamage;
}
public static void dealNoInvulnerabilityTickDamage(LivingEntity target, double damage, Entity attacker) { public static void dealNoInvulnerabilityTickDamage(LivingEntity target, double damage, Entity attacker) {
if (target.isDead()) { if (target.isDead()) {
return; return;
@ -564,7 +571,11 @@ public final class CombatUtils {
// potentially mis-attributing the death cause; calling a fake event would partially fix this, but this and setting the last damage // 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 // 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 // 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
// Snapshot current state so we can pop up properly
boolean wasMetaSet = target.getMetadata(mcMMO.CUSTOM_DAMAGE_METAKEY).size() != 0; boolean wasMetaSet = target.getMetadata(mcMMO.CUSTOM_DAMAGE_METAKEY).size() != 0;
boolean wasProcessing = processingNoInvulnDamage;
// set markers
processingNoInvulnDamage = true;
target.setMetadata(mcMMO.CUSTOM_DAMAGE_METAKEY, mcMMO.metadataValue); target.setMetadata(mcMMO.CUSTOM_DAMAGE_METAKEY, mcMMO.metadataValue);
int noDamageTicks = target.getNoDamageTicks(); int noDamageTicks = target.getNoDamageTicks();
target.setNoDamageTicks(0); target.setNoDamageTicks(0);
@ -572,6 +583,8 @@ public final class CombatUtils {
target.setNoDamageTicks(noDamageTicks); target.setNoDamageTicks(noDamageTicks);
if (!wasMetaSet) if (!wasMetaSet)
target.removeMetadata(mcMMO.CUSTOM_DAMAGE_METAKEY, mcMMO.p); target.removeMetadata(mcMMO.CUSTOM_DAMAGE_METAKEY, mcMMO.p);
if (!wasProcessing)
processingNoInvulnDamage = false;
} }
public static void dealNoInvulnerabilityTickDamageRupture(LivingEntity target, double damage, Entity attacker, int toolTier) { public static void dealNoInvulnerabilityTickDamageRupture(LivingEntity target, double damage, Entity attacker, int toolTier) {