mirror of
https://github.com/BentoBoxWorld/BentoBox.git
synced 2025-01-26 18:11:43 +01:00
Fixed entities being damaged by TNTs or Creepers even if it was disabled
Fixes https://github.com/BentoBoxWorld/BentoBox/issues/1075
This commit is contained in:
parent
87b503b96c
commit
c179b3e20a
@ -11,6 +11,8 @@ import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.EventPriority;
|
||||
import org.bukkit.event.block.Action;
|
||||
import org.bukkit.event.entity.EntityChangeBlockEvent;
|
||||
import org.bukkit.event.entity.EntityDamageByEntityEvent;
|
||||
import org.bukkit.event.entity.EntityDamageEvent;
|
||||
import org.bukkit.event.entity.EntityExplodeEvent;
|
||||
import org.bukkit.event.player.PlayerInteractEvent;
|
||||
|
||||
@ -78,10 +80,27 @@ public class TNTListener extends FlagListener {
|
||||
*/
|
||||
@EventHandler(priority = EventPriority.LOW, ignoreCancelled = true)
|
||||
public void onExplosion(final EntityExplodeEvent e) {
|
||||
// Remove any blocks from the explosion list if they are inside a protected area and if the entity was a TNT
|
||||
// Remove any blocks from the explosion list if they are inside a protected area
|
||||
if (tntTypes.contains(e.getEntityType())
|
||||
&& e.blockList().removeIf(b -> getIslands().getProtectedIslandAt(b.getLocation()).map(i -> !i.isAllowed(Flags.TNT_DAMAGE)).orElse(false))) {
|
||||
// If any were removed, then prevent damage too
|
||||
// If any were removed
|
||||
e.setCancelled(true); // Seems to have no effect.
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Prevents TNT explosion from damaging entities.
|
||||
* @param e event
|
||||
*/
|
||||
@EventHandler(priority = EventPriority.LOW, ignoreCancelled = true)
|
||||
public void onExplosion(final EntityDamageByEntityEvent e) {
|
||||
// Check if this a TNT exploding
|
||||
if (!e.getCause().equals(EntityDamageEvent.DamageCause.ENTITY_EXPLOSION) || !tntTypes.contains(e.getDamager().getType())) {
|
||||
return;
|
||||
}
|
||||
|
||||
// Check if it is disallowed, then cancel it.
|
||||
if(getIslands().getProtectedIslandAt(e.getEntity().getLocation()).map(i -> !i.isAllowed(Flags.TNT_DAMAGE)).orElse(false)) {
|
||||
e.setCancelled(true);
|
||||
}
|
||||
}
|
||||
|
@ -5,6 +5,8 @@ import org.bukkit.entity.EntityType;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.EventPriority;
|
||||
import org.bukkit.event.entity.EntityDamageByEntityEvent;
|
||||
import org.bukkit.event.entity.EntityDamageEvent;
|
||||
import org.bukkit.event.entity.EntityExplodeEvent;
|
||||
|
||||
import world.bentobox.bentobox.api.flags.FlagListener;
|
||||
@ -22,7 +24,7 @@ import world.bentobox.bentobox.lists.Flags;
|
||||
public class CreeperListener extends FlagListener {
|
||||
|
||||
/**
|
||||
* Prevent damage from explosion
|
||||
* Prevent blocks being destroyed from explosion
|
||||
* @param e - event
|
||||
*/
|
||||
@EventHandler(priority = EventPriority.LOW, ignoreCancelled = true)
|
||||
@ -49,4 +51,21 @@ public class CreeperListener extends FlagListener {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Prevent entities being damaged by explosion
|
||||
* @param e - event
|
||||
* @since 1.10.0
|
||||
*/
|
||||
@EventHandler(priority = EventPriority.LOW, ignoreCancelled = true)
|
||||
public void onExplosion(final EntityDamageByEntityEvent e) {
|
||||
if (!e.getCause().equals(EntityDamageEvent.DamageCause.ENTITY_EXPLOSION) || !getIWM().inWorld(e.getEntity().getLocation())
|
||||
|| !e.getDamager().getType().equals(EntityType.CREEPER)) {
|
||||
return;
|
||||
}
|
||||
// If creeper damage is not allowed in world cancel the damage
|
||||
if (!Flags.CREEPER_DAMAGE.isSetForWorld(e.getEntity().getWorld())) {
|
||||
e.setCancelled(true);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user