Stop block explosions damaging claimed entities (#1122)

#1115
This commit is contained in:
Adam 2020-11-29 14:54:48 -05:00 committed by GitHub
parent eaaa42365e
commit 293142deca
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -735,6 +735,7 @@ public class EntityEventHandler implements Listener
{
DamageCause cause = event.getCause();
if (cause != null && (
cause == DamageCause.BLOCK_EXPLOSION ||
cause == DamageCause.ENTITY_EXPLOSION ||
cause == DamageCause.FALLING_BLOCK ||
cause == DamageCause.FIRE ||
@ -750,6 +751,8 @@ public class EntityEventHandler implements Listener
}
}
if (handleBlockExplosionDamage(event)) return;
//the rest is only interested in entities damaging entities (ignoring environmental damage)
if (!(event instanceof EntityDamageByEntityEvent)) return;
@ -1169,6 +1172,31 @@ public class EntityEventHandler implements Listener
}
}
/**
* 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)
{