mirror of
https://github.com/EngineHub/WorldGuard.git
synced 2025-01-03 15:08:02 +01:00
Revert previous changes to explosion event handling.
Event abstraction sucks and everything needs rewriting.
This commit is contained in:
parent
03aac83f4c
commit
830472d36e
@ -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.
|
||||||
*/
|
*/
|
||||||
public abstract class AbstractBlockEvent extends DelegateEvent implements BulkEvent {
|
abstract class AbstractBlockEvent extends DelegateEvent implements BulkEvent {
|
||||||
|
|
||||||
private final World world;
|
private final World world;
|
||||||
private List<Block> blocks;
|
private List<Block> blocks;
|
||||||
|
@ -25,7 +25,6 @@
|
|||||||
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;
|
||||||
@ -116,6 +115,7 @@
|
|||||||
import org.bukkit.event.entity.EntityDamageByEntityEvent;
|
import org.bukkit.event.entity.EntityDamageByEntityEvent;
|
||||||
import org.bukkit.event.entity.EntityDamageEvent;
|
import org.bukkit.event.entity.EntityDamageEvent;
|
||||||
import org.bukkit.event.entity.EntityDeathEvent;
|
import org.bukkit.event.entity.EntityDeathEvent;
|
||||||
|
import org.bukkit.event.entity.EntityEvent;
|
||||||
import org.bukkit.event.entity.EntityExplodeEvent;
|
import org.bukkit.event.entity.EntityExplodeEvent;
|
||||||
import org.bukkit.event.entity.EntityInteractEvent;
|
import org.bukkit.event.entity.EntityInteractEvent;
|
||||||
import org.bukkit.event.entity.EntityKnockbackByEntityEvent;
|
import org.bukkit.event.entity.EntityKnockbackByEntityEvent;
|
||||||
@ -181,9 +181,11 @@ public EventAbstractionListener(WorldGuardPlugin plugin) {
|
|||||||
public void registerEvents() {
|
public void registerEvents() {
|
||||||
super.registerEvents();
|
super.registerEvents();
|
||||||
|
|
||||||
|
PluginManager pm = getPlugin().getServer().getPluginManager();
|
||||||
if (PaperLib.isPaper()) {
|
if (PaperLib.isPaper()) {
|
||||||
PluginManager pm = getPlugin().getServer().getPluginManager();
|
|
||||||
pm.registerEvents(new EventAbstractionListener.PaperListener(), getPlugin());
|
pm.registerEvents(new EventAbstractionListener.PaperListener(), getPlugin());
|
||||||
|
} else {
|
||||||
|
pm.registerEvents(new EventAbstractionListener.SpigotListener(), getPlugin());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -359,10 +361,7 @@ public void onEntityChangeBlock(EntityChangeBlockEvent event) {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@EventHandler(ignoreCancelled = true)
|
private static <T extends EntityEvent & Cancellable> void handleKnockback(T event, Entity damager) {
|
||||||
public void onEntityKnockbackByEntity(EntityKnockbackByEntityEvent event) {
|
|
||||||
Entity damager = event.getSourceEntity();
|
|
||||||
|
|
||||||
final DamageEntityEvent eventToFire = new DamageEntityEvent(event, create(damager), event.getEntity());
|
final DamageEntityEvent eventToFire = new DamageEntityEvent(event, create(damager), event.getEntity());
|
||||||
if (damager instanceof BreezeWindCharge) {
|
if (damager instanceof BreezeWindCharge) {
|
||||||
eventToFire.getRelevantFlags().add(Flags.BREEZE_WIND_CHARGE);
|
eventToFire.getRelevantFlags().add(Flags.BREEZE_WIND_CHARGE);
|
||||||
@ -372,24 +371,19 @@ public void onEntityKnockbackByEntity(EntityKnockbackByEntityEvent event) {
|
|||||||
Events.fireToCancel(event, eventToFire);
|
Events.fireToCancel(event, eventToFire);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@SuppressWarnings("UnstableApiUsage")
|
||||||
@EventHandler(ignoreCancelled = true)
|
@EventHandler(ignoreCancelled = true)
|
||||||
public void onEntityExplode(EntityExplodeEvent event) {
|
public void onEntityExplode(EntityExplodeEvent event) {
|
||||||
Entity entity = event.getEntity();
|
Entity entity = event.getEntity();
|
||||||
AbstractBlockEvent wgEvent;
|
|
||||||
|
|
||||||
if (event.getExplosionResult() == ExplosionResult.TRIGGER_BLOCK) {
|
if (event.getExplosionResult() == ExplosionResult.TRIGGER_BLOCK) {
|
||||||
wgEvent = new UseBlockEvent(event, create(entity), event.getLocation().getWorld(), event.blockList(), Material.AIR);
|
UseBlockEvent useEvent = new UseBlockEvent(event, create(entity), event.getLocation().getWorld(), event.blockList(), Material.AIR);
|
||||||
|
useEvent.getRelevantFlags().add(Entities.getExplosionFlag(entity));
|
||||||
|
useEvent.setSilent(true);
|
||||||
|
Events.fireBulkEventToCancel(event, useEvent);
|
||||||
} else if (event.getExplosionResult() == ExplosionResult.DESTROY || event.getExplosionResult() == ExplosionResult.DESTROY_WITH_DECAY) {
|
} 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);
|
Events.fireBulkEventToCancel(event, new BreakBlockEvent(event, create(entity), event.getLocation().getWorld(), event.blockList(), Material.AIR));
|
||||||
} else {
|
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
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);
|
||||||
}
|
}
|
||||||
@ -1295,7 +1289,7 @@ private static void playDenyEffect(Location location) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private class PaperListener implements Listener {
|
private static class PaperListener implements Listener {
|
||||||
@EventHandler(ignoreCancelled = true)
|
@EventHandler(ignoreCancelled = true)
|
||||||
public void onEntityTransform(EntityZapEvent event) {
|
public void onEntityTransform(EntityZapEvent event) {
|
||||||
Events.fireToCancel(event, new DamageEntityEvent(event, create(event.getBolt()), event.getEntity()));
|
Events.fireToCancel(event, new DamageEntityEvent(event, create(event.getBolt()), event.getEntity()));
|
||||||
@ -1308,5 +1302,18 @@ public void onSignOpen(PlayerOpenSignEvent event) {
|
|||||||
Events.fireToCancel(event, new UseBlockEvent(event, create(event.getPlayer()), event.getSign().getBlock()));
|
Events.fireToCancel(event, new UseBlockEvent(event, create(event.getPlayer()), event.getSign().getBlock()));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@EventHandler(ignoreCancelled = true)
|
||||||
|
public void onEntityKnockbackByEntity(com.destroystokyo.paper.event.entity.EntityKnockbackByEntityEvent event) {
|
||||||
|
handleKnockback(event, event.getHitBy());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@SuppressWarnings("removal")
|
||||||
|
private static class SpigotListener implements Listener {
|
||||||
|
@EventHandler(ignoreCancelled = true)
|
||||||
|
public void onEntityKnockbackByEntity(EntityKnockbackByEntityEvent event) {
|
||||||
|
handleKnockback(event, event.getSourceEntity());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -61,6 +61,7 @@
|
|||||||
import org.bukkit.entity.Projectile;
|
import org.bukkit.entity.Projectile;
|
||||||
import org.bukkit.entity.TNTPrimed;
|
import org.bukkit.entity.TNTPrimed;
|
||||||
import org.bukkit.entity.Tameable;
|
import org.bukkit.entity.Tameable;
|
||||||
|
import org.bukkit.entity.WindCharge;
|
||||||
import org.bukkit.entity.Wither;
|
import org.bukkit.entity.Wither;
|
||||||
import org.bukkit.entity.WitherSkull;
|
import org.bukkit.entity.WitherSkull;
|
||||||
import org.bukkit.entity.Wolf;
|
import org.bukkit.entity.Wolf;
|
||||||
@ -503,6 +504,16 @@ public void onEntityExplode(EntityExplodeEvent event) {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
if (wcfg.useRegions && !(ent instanceof WindCharge)) {
|
||||||
|
for (Block block : event.blockList()) {
|
||||||
|
if (!WorldGuard.getInstance().getPlatform().getRegionContainer().createQuery()
|
||||||
|
.testState(BukkitAdapter.adapt(block.getLocation()), null, Entities.getExplosionFlag(ent))) {
|
||||||
|
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,12 +523,32 @@ public void onEntityExplode(EntityExplodeEvent event) {
|
|||||||
event.blockList().clear();
|
event.blockList().clear();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
if (wcfg.useRegions) {
|
||||||
|
for (Block block : event.blockList()) {
|
||||||
|
if (!WorldGuard.getInstance().getPlatform().getRegionContainer().createQuery()
|
||||||
|
.testState(BukkitAdapter.adapt(block.getLocation()), 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()
|
||||||
|
.testState(BukkitAdapter.adapt(block.getLocation()), null, Flags.OTHER_EXPLOSION)) {
|
||||||
|
event.blockList().clear();
|
||||||
|
if (wcfg.explosionFlagCancellation) event.setCancelled(true);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (wcfg.signChestProtection) {
|
if (wcfg.signChestProtection) {
|
||||||
|
@ -246,7 +246,7 @@ public static boolean isAoECloud(EntityType type) {
|
|||||||
* This is true for custom creations or the summon command.
|
* This is true for custom creations or the summon command.
|
||||||
*
|
*
|
||||||
* @param spawnReason the reason
|
* @param spawnReason the reason
|
||||||
* @return true if considerd plugin spawning
|
* @return true if considered plugin spawning
|
||||||
*/
|
*/
|
||||||
public static boolean isPluginSpawning(CreatureSpawnEvent.SpawnReason spawnReason) {
|
public static boolean isPluginSpawning(CreatureSpawnEvent.SpawnReason spawnReason) {
|
||||||
return switch (spawnReason) {
|
return switch (spawnReason) {
|
||||||
|
Loading…
Reference in New Issue
Block a user