Skip to content

Commit

Permalink
Include fireworks in other-explosion flag.
Browse files Browse the repository at this point in the history
Unfortunately, since fireworks neither have a "shooter" entity nor fire an EntityExplode,
the only way to mitigate damage is a complete on/off for any damage they cause.

Fortunately (probably), this should not interfere with elytra boosting, since the
acceleration is applied directly to the player upon use, not from the firework "explosion".

Fixes WORLDGUARD-3786.
  • Loading branch information
wizjany committed Jan 4, 2017
1 parent c0f3171 commit 22ef224
Showing 1 changed file with 13 additions and 0 deletions.
Expand Up @@ -39,6 +39,7 @@
import org.bukkit.event.EventHandler;
import org.bukkit.event.EventPriority;
import org.bukkit.event.entity.EntityDamageEvent;
import org.bukkit.event.entity.EntityDamageByEntityEvent;
import org.bukkit.event.entity.EntityDamageEvent.DamageCause;

import javax.annotation.Nullable;
Expand Down Expand Up @@ -106,17 +107,29 @@ public void onEntityDamage(EntityDamageEvent event) {
if (entity instanceof Player && event.getCause() == DamageCause.FALL) {
if (!query.testState(entity.getLocation(), (Player) entity, DefaultFlag.FALL_DAMAGE)) {
event.setCancelled(true);
return;
}
} else {
try {
if (entity instanceof Player && event.getCause() == DamageCause.FLY_INTO_WALL) {
if (!query.testState(entity.getLocation(), (Player) entity, DefaultFlag.FALL_DAMAGE)) {
event.setCancelled(true);
return;
}
}
} catch (NoSuchFieldError ignored) {
}
}

if (event instanceof EntityDamageByEntityEvent) {
Entity damager = (((EntityDamageByEntityEvent) event)).getDamager();
if (damager != null && damager.getType() == EntityType.FIREWORK) {
if (!query.testState(entity.getLocation(), (RegionAssociable) null, DefaultFlag.OTHER_EXPLOSION)) {
event.setCancelled(true);
return;
}
}
}
}

/**
Expand Down

2 comments on commit 22ef224

@mibby
Copy link

@mibby mibby commented on 22ef224 Jan 7, 2017

Choose a reason for hiding this comment

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

@wizjany Would it be possible to split this off into a separate flag? I'd like to disable firework damage but keep other explosions globally.

@stuntguy3000
Copy link
Contributor

Choose a reason for hiding this comment

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

+1

Please sign in to comment.