Skip to content

Commit

Permalink
Stop block explosions damaging claimed entities (#1122)
Browse files Browse the repository at this point in the history
  • Loading branch information
Jikoo committed Nov 29, 2020
1 parent eaaa423 commit 293142d
Showing 1 changed file with 28 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -735,6 +735,7 @@ private void handleEntityDamageEvent(EntityDamageEvent event, boolean sendErrorM
{
DamageCause cause = event.getCause();
if (cause != null && (
cause == DamageCause.BLOCK_EXPLOSION ||
cause == DamageCause.ENTITY_EXPLOSION ||
cause == DamageCause.FALLING_BLOCK ||
cause == DamageCause.FIRE ||
Expand All @@ -750,6 +751,8 @@ private void handleEntityDamageEvent(EntityDamageEvent event, boolean sendErrorM
}
}

if (handleBlockExplosionDamage(event)) return;

//the rest is only interested in entities damaging entities (ignoring environmental damage)
if (!(event instanceof EntityDamageByEntityEvent)) return;

Expand Down Expand Up @@ -1169,6 +1172,31 @@ else if (!(event.getEntity().getWorld().getPVP() && event.getEntity().getType()
}
}

/**
* Handles entity damage caused by block explosions.
*
* @param event the EntityDamageEvent
* @return true if the damage has been handled
*/
private boolean handleBlockExplosionDamage(EntityDamageEvent event)
{
if (event.getCause() != DamageCause.BLOCK_EXPLOSION) return false;

Entity entity = event.getEntity();

// Skip players - does allow players to use block explosions to bypass PVP protections,
// but also doesn't disable self-damage.
if (entity instanceof Player) return false;

Claim claim = GriefPrevention.instance.dataStore.getClaimAt(entity.getLocation(), false, null);

// Only block explosion damage inside claims.
if (claim == null) return false;

event.setCancelled(true);
return true;
}

@EventHandler(ignoreCancelled = true, priority = EventPriority.LOWEST)
public void onCrossbowFireWork(EntityShootBowEvent shootEvent)
{
Expand Down

0 comments on commit 293142d

Please sign in to comment.