Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix block explosions damaging claimed entities #1122

Merged
merged 1 commit into from
Nov 29, 2020
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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