Skip to content

Commit

Permalink
Prevent nesting of bleed damage
Browse files Browse the repository at this point in the history
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
  • Loading branch information
electronicboy committed Nov 13, 2019
1 parent 3ce0d7b commit b7dd491
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 0 deletions.
4 changes: 4 additions & 0 deletions src/main/java/com/gmail/nossr50/listeners/EntityListener.java
Expand Up @@ -319,6 +319,10 @@ public void onEntityDamageByEntity(EntityDamageByEntityEvent event) {
return;
}

if (CombatUtils.isProcessingNoInvulnDamage()) {
return;
}

if (event.getEntity() instanceof ArmorStand) {
return;
}
Expand Down
13 changes: 13 additions & 0 deletions src/main/java/com/gmail/nossr50/util/skills/CombatUtils.java
Expand Up @@ -39,6 +39,8 @@
import java.util.List;
import java.util.Map;

import javax.annotation.Nullable;

public final class CombatUtils {
private CombatUtils() {}

Expand Down Expand Up @@ -554,6 +556,11 @@ public static void dealDamage(LivingEntity target, double damage, DamageCause ca
target.damage(damage);
}

private static boolean processingNoInvulnDamage;
public static boolean isProcessingNoInvulnDamage() {
return processingNoInvulnDamage;
}

public static void dealNoInvulnerabilityTickDamage(LivingEntity target, double damage, Entity attacker) {
if (target.isDead()) {
return;
Expand All @@ -564,14 +571,20 @@ public static void dealNoInvulnerabilityTickDamage(LivingEntity target, double d
// 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
// Snapshot current state so we can pop up properly
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);
int noDamageTicks = target.getNoDamageTicks();
target.setNoDamageTicks(0);
target.damage(damage, attacker);
target.setNoDamageTicks(noDamageTicks);
if (!wasMetaSet)
target.removeMetadata(mcMMO.CUSTOM_DAMAGE_METAKEY, mcMMO.p);
if (!wasProcessing)
processingNoInvulnDamage = false;
}

public static void dealNoInvulnerabilityTickDamageRupture(LivingEntity target, double damage, Entity attacker, int toolTier) {
Expand Down

1 comment on commit b7dd491

@nossr50
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Seems like an appropriate solution

Please sign in to comment.