Fix breeze damage flags

This commit is contained in:
Joo200 2024-07-22 21:40:57 +02:00 committed by wizjany
parent b73a0a7179
commit afb619d2ac
No known key found for this signature in database
GPG Key ID: 1DB5861C03B76B5E
7 changed files with 64 additions and 44 deletions

View File

@ -215,6 +215,7 @@ public void loadConfiguration() {
blockEnderDragonPortalCreation = getBoolean("mobs.block-enderdragon-portal-creation", false); blockEnderDragonPortalCreation = getBoolean("mobs.block-enderdragon-portal-creation", false);
blockFireballExplosions = getBoolean("mobs.block-fireball-explosions", false); blockFireballExplosions = getBoolean("mobs.block-fireball-explosions", false);
blockFireballBlockDamage = getBoolean("mobs.block-fireball-block-damage", false); blockFireballBlockDamage = getBoolean("mobs.block-fireball-block-damage", false);
blockWindChargeExplosions = getBoolean("mobs.block-windcharge-explosions", false);
antiWolfDumbness = getBoolean("mobs.anti-wolf-dumbness", false); antiWolfDumbness = getBoolean("mobs.anti-wolf-dumbness", false);
allowTamedSpawns = getBoolean("mobs.allow-tamed-spawns", true); allowTamedSpawns = getBoolean("mobs.allow-tamed-spawns", true);
disableEndermanGriefing = getBoolean("mobs.disable-enderman-griefing", false); disableEndermanGriefing = getBoolean("mobs.disable-enderman-griefing", false);

View File

@ -45,7 +45,7 @@
* This event is an internal event. We do not recommend handling or throwing * This event is an internal event. We do not recommend handling or throwing
* this event or its subclasses as the interface is highly subject to change. * this event or its subclasses as the interface is highly subject to change.
*/ */
abstract class AbstractBlockEvent extends DelegateEvent implements BulkEvent { public abstract class AbstractBlockEvent extends DelegateEvent implements BulkEvent {
private final World world; private final World world;
private List<Block> blocks; private List<Block> blocks;

View File

@ -25,6 +25,7 @@
import com.sk89q.worldguard.bukkit.WorldGuardPlugin; import com.sk89q.worldguard.bukkit.WorldGuardPlugin;
import com.sk89q.worldguard.bukkit.cause.Cause; import com.sk89q.worldguard.bukkit.cause.Cause;
import com.sk89q.worldguard.bukkit.event.DelegateEvent; import com.sk89q.worldguard.bukkit.event.DelegateEvent;
import com.sk89q.worldguard.bukkit.event.block.AbstractBlockEvent;
import com.sk89q.worldguard.bukkit.event.block.BreakBlockEvent; import com.sk89q.worldguard.bukkit.event.block.BreakBlockEvent;
import com.sk89q.worldguard.bukkit.event.block.PlaceBlockEvent; import com.sk89q.worldguard.bukkit.event.block.PlaceBlockEvent;
import com.sk89q.worldguard.bukkit.event.block.UseBlockEvent; import com.sk89q.worldguard.bukkit.event.block.UseBlockEvent;
@ -46,10 +47,12 @@
import com.sk89q.worldguard.bukkit.util.Materials; import com.sk89q.worldguard.bukkit.util.Materials;
import com.sk89q.worldguard.config.WorldConfiguration; import com.sk89q.worldguard.config.WorldConfiguration;
import com.sk89q.worldguard.protection.flags.Flags; import com.sk89q.worldguard.protection.flags.Flags;
import com.sk89q.worldguard.protection.flags.StateFlag;
import io.papermc.lib.PaperLib; import io.papermc.lib.PaperLib;
import io.papermc.paper.event.player.PlayerOpenSignEvent; import io.papermc.paper.event.player.PlayerOpenSignEvent;
import org.bukkit.Bukkit; import org.bukkit.Bukkit;
import org.bukkit.Effect; import org.bukkit.Effect;
import org.bukkit.ExplosionResult;
import org.bukkit.GameMode; import org.bukkit.GameMode;
import org.bukkit.Location; import org.bukkit.Location;
import org.bukkit.Material; import org.bukkit.Material;
@ -65,7 +68,6 @@
import org.bukkit.block.data.BlockData; import org.bukkit.block.data.BlockData;
import org.bukkit.block.data.Waterlogged; import org.bukkit.block.data.Waterlogged;
import org.bukkit.block.data.type.Dispenser; import org.bukkit.block.data.type.Dispenser;
import org.bukkit.entity.AbstractWindCharge;
import org.bukkit.entity.AreaEffectCloud; import org.bukkit.entity.AreaEffectCloud;
import org.bukkit.entity.Creeper; import org.bukkit.entity.Creeper;
import org.bukkit.entity.Entity; import org.bukkit.entity.Entity;
@ -358,14 +360,21 @@ public void onEntityChangeBlock(EntityChangeBlockEvent event) {
@EventHandler(ignoreCancelled = true) @EventHandler(ignoreCancelled = true)
public void onEntityExplode(EntityExplodeEvent event) { public void onEntityExplode(EntityExplodeEvent event) {
Entity entity = event.getEntity(); Entity entity = event.getEntity();
if (entity instanceof AbstractWindCharge) { AbstractBlockEvent wgEvent;
UseBlockEvent useEvent = new UseBlockEvent(event, create(entity), event.getLocation().getWorld(), event.blockList(), Material.AIR);
useEvent.getRelevantFlags().add(Flags.WIND_CHARGE_BURST); if (event.getExplosionResult() == ExplosionResult.TRIGGER_BLOCK) {
useEvent.setSilent(true); wgEvent = new UseBlockEvent(event, create(entity), event.getLocation().getWorld(), event.blockList(), Material.AIR);
Events.fireBulkEventToCancel(event, useEvent); } else if (event.getExplosionResult() == ExplosionResult.DESTROY || event.getExplosionResult() == ExplosionResult.DESTROY_WITH_DECAY) {
wgEvent = new BreakBlockEvent(event, create(entity), event.getLocation().getWorld(), event.blockList(), Material.AIR);
} else {
return; return;
} }
Events.fireBulkEventToCancel(event, new BreakBlockEvent(event, create(entity), event.getLocation().getWorld(), event.blockList(), Material.AIR));
wgEvent.getRelevantFlags().add(Entities.getExplosionFlag(event.getEntity()));
wgEvent.setSilent(true);
Events.fireBulkEventToCancel(event, wgEvent);
if (entity instanceof Creeper) { if (entity instanceof Creeper) {
Cause.untrackParentCause(entity); Cause.untrackParentCause(entity);
} }
@ -750,7 +759,7 @@ public void onHangingBreak(HangingBreakEvent event) {
if (event.isCancelled() && remover instanceof Player) { if (event.isCancelled() && remover instanceof Player) {
playDenyEffect((Player) remover, event.getEntity().getLocation()); playDenyEffect((Player) remover, event.getEntity().getLocation());
} }
} else if (event.getCause() == HangingBreakEvent.RemoveCause.EXPLOSION){ } else if (event.getCause() == HangingBreakEvent.RemoveCause.EXPLOSION) {
DestroyEntityEvent destroyEntityEvent = new DestroyEntityEvent(event, Cause.unknown(), event.getEntity()); DestroyEntityEvent destroyEntityEvent = new DestroyEntityEvent(event, Cause.unknown(), event.getEntity());
destroyEntityEvent.getRelevantFlags().add(Flags.OTHER_EXPLOSION); destroyEntityEvent.getRelevantFlags().add(Flags.OTHER_EXPLOSION);
if (event.getEntity() instanceof ItemFrame) { if (event.getEntity() instanceof ItemFrame) {
@ -1112,7 +1121,7 @@ public void onLingeringApply(AreaEffectCloudApplyEvent event) {
} }
@EventHandler(ignoreCancelled = true) @EventHandler(ignoreCancelled = true)
public void onPlayerInteractAtEntity(PlayerInteractAtEntityEvent event){ public void onPlayerInteractAtEntity(PlayerInteractAtEntityEvent event) {
onPlayerInteractEntity(event); onPlayerInteractEntity(event);
} }

View File

@ -44,6 +44,7 @@
import org.bukkit.World; import org.bukkit.World;
import org.bukkit.block.Block; import org.bukkit.block.Block;
import org.bukkit.block.BlockState; import org.bukkit.block.BlockState;
import org.bukkit.entity.AbstractWindCharge;
import org.bukkit.entity.ArmorStand; import org.bukkit.entity.ArmorStand;
import org.bukkit.entity.Creeper; import org.bukkit.entity.Creeper;
import org.bukkit.entity.EnderCrystal; import org.bukkit.entity.EnderCrystal;
@ -311,13 +312,17 @@ private void onEntityDamageByProjectile(EntityDamageByEntityEvent event) {
return; return;
} }
} }
if (event.getDamager() instanceof Fireball) { if (event.getDamager() instanceof Fireball fireball) {
Fireball fireball = (Fireball) event.getDamager();
if (fireball instanceof WitherSkull) { if (fireball instanceof WitherSkull) {
if (wcfg.blockWitherSkullExplosions) { if (wcfg.blockWitherSkullExplosions) {
event.setCancelled(true); event.setCancelled(true);
return; return;
} }
} else if (fireball instanceof AbstractWindCharge) {
if (wcfg.blockWindChargeExplosions) {
event.setCancelled(true);
return;
}
} else { } else {
if (wcfg.blockFireballExplosions) { if (wcfg.blockFireballExplosions) {
event.setCancelled(true); event.setCancelled(true);
@ -325,8 +330,9 @@ private void onEntityDamageByProjectile(EntityDamageByEntityEvent event) {
} }
} }
if (wcfg.useRegions) { if (wcfg.useRegions) {
WorldGuardPlugin.inst().getLogger().info("Getting damager type " + event.getDamager().getType());
RegionQuery query = WorldGuard.getInstance().getPlatform().getRegionContainer().createQuery(); RegionQuery query = WorldGuard.getInstance().getPlatform().getRegionContainer().createQuery();
if (!query.testState(localPlayer.getLocation(), localPlayer, Flags.GHAST_FIREBALL) && wcfg.explosionFlagCancellation) { if (!query.testState(localPlayer.getLocation(), localPlayer, Entities.getExplosionFlag(event.getDamager())) && wcfg.explosionFlagCancellation) {
event.setCancelled(true); event.setCancelled(true);
return; return;
} }
@ -483,6 +489,11 @@ public void onEntityExplode(EntityExplodeEvent event) {
event.blockList().clear(); event.blockList().clear();
return; return;
} }
} else if (ent instanceof AbstractWindCharge) {
if (wcfg.blockWindChargeExplosions) {
event.setCancelled(true);
return;
}
} else { } else {
if (wcfg.blockFireballExplosions) { if (wcfg.blockFireballExplosions) {
event.setCancelled(true); event.setCancelled(true);
@ -493,16 +504,6 @@ public void onEntityExplode(EntityExplodeEvent event) {
return; return;
} }
} }
// allow wither skull blocking since there is no dedicated flag atm
if (wcfg.useRegions) {
for (Block block : event.blockList()) {
if (!WorldGuard.getInstance().getPlatform().getRegionContainer().createQuery().getApplicableRegions(BukkitAdapter.adapt(block.getLocation())).testState(null, Flags.GHAST_FIREBALL)) {
event.blockList().clear();
if (wcfg.explosionFlagCancellation) event.setCancelled(true);
return;
}
}
}
} else if (ent instanceof Wither) { } else if (ent instanceof Wither) {
if (wcfg.blockWitherExplosions) { if (wcfg.blockWitherExplosions) {
event.setCancelled(true); event.setCancelled(true);
@ -512,33 +513,13 @@ public void onEntityExplode(EntityExplodeEvent event) {
event.blockList().clear(); event.blockList().clear();
return; return;
} }
if (wcfg.useRegions) {
for (Block block : event.blockList()) {
if (!StateFlag.test(WorldGuard.getInstance().getPlatform().getRegionContainer().createQuery().queryState(BukkitAdapter.adapt(block.getLocation()),
(RegionAssociable) null, Flags.WITHER_DAMAGE))) {
event.blockList().clear();
event.setCancelled(true);
return;
}
}
}
} else { } else {
// unhandled entity // unhandled entity
if (wcfg.blockOtherExplosions) { if (wcfg.blockOtherExplosions) {
event.setCancelled(true); event.setCancelled(true);
return; return;
} }
if (wcfg.useRegions) {
for (Block block : event.blockList()) {
if (!WorldGuard.getInstance().getPlatform().getRegionContainer().createQuery().getApplicableRegions(BukkitAdapter.adapt(block.getLocation())).testState(null, Flags.OTHER_EXPLOSION)) {
event.blockList().clear();
if (wcfg.explosionFlagCancellation) event.setCancelled(true);
return;
} }
}
}
}
if (wcfg.signChestProtection) { if (wcfg.signChestProtection) {
for (Block block : event.blockList()) { for (Block block : event.blockList()) {
@ -592,6 +573,11 @@ public void onExplosionPrime(ExplosionPrimeEvent event) {
event.setCancelled(true); event.setCancelled(true);
return; return;
} }
} else if (event instanceof AbstractWindCharge) {
if (wcfg.blockWindChargeExplosions) {
event.setCancelled(true);
return;
}
} }
} }

View File

@ -19,6 +19,9 @@
package com.sk89q.worldguard.bukkit.util; package com.sk89q.worldguard.bukkit.util;
import com.sk89q.worldguard.protection.flags.Flags;
import com.sk89q.worldguard.protection.flags.StateFlag;
import org.bukkit.entity.AbstractWindCharge;
import org.bukkit.entity.Allay; import org.bukkit.entity.Allay;
import org.bukkit.entity.Ambient; import org.bukkit.entity.Ambient;
import org.bukkit.entity.ArmorStand; import org.bukkit.entity.ArmorStand;
@ -28,6 +31,8 @@
import org.bukkit.entity.EnderDragon; import org.bukkit.entity.EnderDragon;
import org.bukkit.entity.Entity; import org.bukkit.entity.Entity;
import org.bukkit.entity.EntityType; import org.bukkit.entity.EntityType;
import org.bukkit.entity.Fireball;
import org.bukkit.entity.Firework;
import org.bukkit.entity.Flying; import org.bukkit.entity.Flying;
import org.bukkit.entity.Hanging; import org.bukkit.entity.Hanging;
import org.bukkit.entity.LivingEntity; import org.bukkit.entity.LivingEntity;
@ -43,11 +48,13 @@
import org.bukkit.entity.TNTPrimed; import org.bukkit.entity.TNTPrimed;
import org.bukkit.entity.Tameable; import org.bukkit.entity.Tameable;
import org.bukkit.entity.Vehicle; import org.bukkit.entity.Vehicle;
import org.bukkit.entity.Wither;
import org.bukkit.entity.minecart.ExplosiveMinecart; import org.bukkit.entity.minecart.ExplosiveMinecart;
import org.bukkit.event.entity.CreatureSpawnEvent; import org.bukkit.event.entity.CreatureSpawnEvent;
import org.bukkit.inventory.InventoryHolder; import org.bukkit.inventory.InventoryHolder;
import org.bukkit.projectiles.ProjectileSource; import org.bukkit.projectiles.ProjectileSource;
import javax.annotation.Nonnull;
import javax.annotation.Nullable; import javax.annotation.Nullable;
public final class Entities { public final class Entities {
@ -245,4 +252,19 @@ public static boolean isPluginSpawning(CreatureSpawnEvent.SpawnReason spawnReaso
default -> false; default -> false;
}; };
} }
/**
* Get the explosion flag relevant for an entity type.
* @param entity the entity
* @return the relevant StateFlag or OTHER_EXPLOSION if none is matching
*/
public static @Nonnull StateFlag getExplosionFlag(Entity entity) {
return switch (entity) {
case AbstractWindCharge abstractWindCharge -> Flags.WIND_CHARGE_BURST;
case Firework firework -> Flags.FIREWORK_DAMAGE;
case Fireball fireball -> Flags.GHAST_FIREBALL;
case Wither wither -> Flags.WITHER_DAMAGE;
case null, default -> Flags.OTHER_EXPLOSION;
};
}
} }

View File

@ -22,6 +22,7 @@
import com.google.common.collect.BiMap; import com.google.common.collect.BiMap;
import com.google.common.collect.HashBiMap; import com.google.common.collect.HashBiMap;
import com.sk89q.worldguard.protection.flags.Flags; import com.sk89q.worldguard.protection.flags.Flags;
import org.bukkit.Bukkit;
import org.bukkit.Material; import org.bukkit.Material;
import org.bukkit.Tag; import org.bukkit.Tag;
import org.bukkit.entity.EntityType; import org.bukkit.entity.EntityType;

View File

@ -101,6 +101,7 @@ public abstract class WorldConfiguration {
public boolean blockEnderDragonPortalCreation; public boolean blockEnderDragonPortalCreation;
public boolean blockFireballExplosions; public boolean blockFireballExplosions;
public boolean blockFireballBlockDamage; public boolean blockFireballBlockDamage;
public boolean blockWindChargeExplosions;
public boolean blockOtherExplosions; public boolean blockOtherExplosions;
public boolean blockEntityPaintingDestroy; public boolean blockEntityPaintingDestroy;
public boolean blockEntityItemFrameDestroy; public boolean blockEntityItemFrameDestroy;