I’m trying to cancelling the explosion event to prevent paintings and other “block entities” from being destroyed by it. So i wrote this listener to do that
@Listener
public void onAttackEntity(AttackEntityEvent event, @First Explosive entity) {
if(FlagUtils.isBlockEntity(event.getTargetEntity().getType()) || FlagUtils.isVehicle(event.getTargetEntity().getType())) {
Region region = RegionUtils.getRegion(event.getTargetEntity().getLocation());
if (region != null) {
EnumRegionExplosion explosion = EnumRegionExplosion.OTHER_EXPLOSIONS;
if (FlagUtils.isExplosion(entity.getType())) // Check if a type of explosion handled
explosion = FlagUtils.getExplosion(entity.getType());
event.setCancelled(!region.getExplosionDestroy(explosion)); //It cancel the event but spams the console :/
}
}
}
The event itself is cancelled, however the console gets spammed by tons of messages before the explosion “occur” (the explosive entity despawn but no actual explosion occur, meaning that the event has been cancelled). I’ve also noticed that if an EnderCrystal explodes, the listener doesn’t event get called This is what i get in console when the event is being cancelled
[20:30:25] [Server thread/ERROR] [Sponge]: /*****************************************************************************************************************************/
[20:30:25] [Server thread/ERROR] [Sponge]: /* Exception occurred during a PhaseState */
[20:30:25] [Server thread/ERROR] [Sponge]: /*****************************************************************************************************************************/
[20:30:25] [Server thread/ERROR] [Sponge]: /* Sponge's tracking system is very dependent on NOT throwing exceptions */
[20:30:25] [Server thread/ERROR] [Sponge]: /* randomly,sometimes it is inevitable. Unfortunately, an exception being printed */
[20:30:25] [Server thread/ERROR] [Sponge]: /* now canbe very spammy, and as a result, cause logs to reach several hundred */
[20:30:25] [Server thread/ERROR] [Sponge]: /* megabytesin size. Since there is an exception being thrown, it is advisable to */
[20:30:25] [Server thread/ERROR] [Sponge]: /* report thislog to Sponge on GitHub. */
[20:30:25] [Server thread/ERROR] [Sponge]: /*****************************************************************************************************************************/
[20:30:25] [Server thread/ERROR] [Sponge]: /* The PhaseState having an exception: EntityTickPhase */
[20:30:25] [Server thread/ERROR] [Sponge]: /* The PhaseContext: */
[20:30:25] [Server thread/ERROR] [Sponge]: /* - Owner: EntityPlayerMP['Minehendrix'/457, l='world', x=1113,43, y=75,53, z=3358,12] */
[20:30:25] [Server thread/ERROR] [Sponge]: /* - Notifier: EntityPlayerMP['Minehendrix'/457, l='world', x=1113,43, y=75,53, z=3358,12] */
[20:30:25] [Server thread/ERROR] [Sponge]: /* - Source: EntityCreeper['Creeper'/6326, l='world', x=1112,70, y=71,00, z=3359,70] */
[20:30:25] [Server thread/ERROR] [Sponge]: /* - CapturedBlocks: CapturedBlocksSupplier{Captured=0} */
[20:30:25] [Server thread/ERROR] [Sponge]: /* - BlockItemDrops: BlockItemDropsSupplier{Captured=0} */
[20:30:25] [Server thread/ERROR] [Sponge]: /* - BlockItemEntityDrops: BlockItemEntityDropsSupplier{Captured=0} */
[20:30:25] [Server thread/ERROR] [Sponge]: /* - CapturedItems: CapturedItemsSupplier{Captured=0} */
[20:30:25] [Server thread/ERROR] [Sponge]: /* - CapturedEntities: CapturedEntitiesSupplier{Captured=0} */
[20:30:25] [Server thread/ERROR] [Sponge]: /* - CapturedItemStack: CapturedItemStackSupplier{Captured=0} */
[20:30:25] [Server thread/ERROR] [Sponge]: /* - EntityItemDrops: null */
[20:30:25] [Server thread/ERROR] [Sponge]: /* - EntityItemEntityDrops: null */
[20:30:25] [Server thread/ERROR] [Sponge]: /* - BlockEntitySpawns: CapturedBlockEntitySpawnSupplier{Captured=0} */
[20:30:25] [Server thread/ERROR] [Sponge]: /* - CapturedBlockPosition: null */
[20:30:25] [Server thread/ERROR] [Sponge]: /* org.spongepowered.asm.util.PrettyPrinter@40ea0944 */
[20:30:25] [Server thread/ERROR] [Sponge]: /*****************************************************************************************************************************/
[20:30:25] [Server thread/ERROR] [Sponge]: /* StackTrace: */
[20:30:25] [Server thread/ERROR] [Sponge]: /* java.lang.RuntimeException: Unknown Exception During Phase */
[20:30:25] [Server thread/ERROR] [Sponge]: /* org.spongepowered.common.event.tracking.PhaseTracker.printExceptionFromPhase(PhaseTracker.java:421) */
[20:30:25] [Server thread/ERROR] [Sponge]: /* org.spongepowered.common.event.tracking.TrackingUtil.tickEntity(TrackingUtil.java:168) */
[20:30:25] [Server thread/ERROR] [Sponge]: /* net.minecraft.world.WorldServer.redirect$onCallEntityUpdate$zlg000(WorldServer.java:2855) */
[20:30:25] [Server thread/ERROR] [Sponge]: /* net.minecraft.world.World.func_72866_a(World.java:4138) */
[20:30:25] [Server thread/ERROR] [Sponge]: /* net.minecraft.world.WorldServer.func_72866_a(WorldServer.java:831) */
[20:30:25] [Server thread/ERROR] [Sponge]: /* net.minecraft.world.World.func_72870_g(World.java:1952) */
[20:30:25] [Server thread/ERROR] [Sponge]: /* net.minecraft.world.World.func_72939_s(World.java:6557) */
[20:30:25] [Server thread/ERROR] [Sponge]: /* net.minecraft.world.WorldServer.func_72939_s(WorldServer.java:2219) */
[20:30:25] [Server thread/ERROR] [Sponge]: /* net.minecraft.server.MinecraftServer.func_71190_q(MinecraftServer.java:765) */
[20:30:25] [Server thread/ERROR] [Sponge]: /* net.minecraft.server.dedicated.DedicatedServer.func_71190_q(DedicatedServer.java:396) */
[20:30:25] [Server thread/ERROR] [Sponge]: /* net.minecraft.server.MinecraftServer.func_71217_p(MinecraftServer.java:666) */
[20:30:25] [Server thread/ERROR] [Sponge]: /* net.minecraft.server.MinecraftServer.run(MinecraftServer.java:524) */
[20:30:25] [Server thread/ERROR] [Sponge]: /* java.lang.Thread.run(Unknown Source) */
[20:30:25] [Server thread/ERROR] [Sponge]: /* org.spongepowered.asm.mixin.injection.callback.CancellationException: The call func_70097_a is not cancellable. */
[20:30:25] [Server thread/ERROR] [Sponge]: /* org.spongepowered.asm.mixin.injection.callback.CallbackInfo.cancel(CallbackInfo.java:101) */
[20:30:25] [Server thread/ERROR] [Sponge]: /* org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable.setReturnValue(CallbackInfoReturnable.java:106) */
[20:30:25] [Server thread/ERROR] [Sponge]: /* net.minecraft.entity.EntityHanging.handler$onAttackEntityFrom$zdp000(EntityHanging.java:600) */
[20:30:25] [Server thread/ERROR] [Sponge]: /* net.minecraft.entity.EntityHanging.func_70097_a(EntityHanging.java:186) */
[20:30:25] [Server thread/ERROR] [Sponge]: /* net.minecraft.world.Explosion.func_77278_a(Explosion.java:786) */
[20:30:25] [Server thread/ERROR] [Sponge]: /* net.minecraft.world.WorldServer.func_72885_a(WorldServer.java:3048) */
[20:30:25] [Server thread/ERROR] [Sponge]: /* net.minecraft.world.WorldServer.triggerInternalExplosion(WorldServer.java:2661) */
[20:30:25] [Server thread/ERROR] [Sponge]: /* org.spongepowered.common.interfaces.entity.explosive.IMixinExplosive.detonate(IMixinExplosive.java:49) */
[20:30:25] [Server thread/ERROR] [Sponge]: /* net.minecraft.entity.monster.EntityCreeper.redirect$onExplode$zgb003(SourceFile:685) */
[20:30:25] [Server thread/ERROR] [Sponge]: /* net.minecraft.entity.monster.EntityCreeper.func_146077_cc(SourceFile:248) */
[20:30:25] [Server thread/ERROR] [Sponge]: /* net.minecraft.entity.monster.EntityCreeper.func_70071_h_(SourceFile:158) */
[20:30:25] [Server thread/ERROR] [Sponge]: /* org.spongepowered.common.event.tracking.TrackingUtil.tickEntity(TrackingUtil.java:166) */
[20:30:25] [Server thread/ERROR] [Sponge]: /* net.minecraft.world.WorldServer.redirect$onCallEntityUpdate$zlg000(WorldServer.java:2855) */
[20:30:25] [Server thread/ERROR] [Sponge]: /* net.minecraft.world.World.func_72866_a(World.java:4138) */
[20:30:25] [Server thread/ERROR] [Sponge]: /* net.minecraft.world.WorldServer.func_72866_a(WorldServer.java:831) */
[20:30:25] [Server thread/ERROR] [Sponge]: /* net.minecraft.world.World.func_72870_g(World.java:1952) */
[20:30:25] [Server thread/ERROR] [Sponge]: /* net.minecraft.world.World.func_72939_s(World.java:6557) */
[20:30:25] [Server thread/ERROR] [Sponge]: /* net.minecraft.world.WorldServer.func_72939_s(WorldServer.java:2219) */
[20:30:25] [Server thread/ERROR] [Sponge]: /* net.minecraft.server.MinecraftServer.func_71190_q(MinecraftServer.java:765) */
[20:30:25] [Server thread/ERROR] [Sponge]: /* net.minecraft.server.dedicated.DedicatedServer.func_71190_q(DedicatedServer.java:396) */
[20:30:25] [Server thread/ERROR] [Sponge]: /* net.minecraft.server.MinecraftServer.func_71217_p(MinecraftServer.java:666) */
[20:30:25] [Server thread/ERROR] [Sponge]: /* net.minecraft.server.MinecraftServer.run(MinecraftServer.java:524) */
[20:30:25] [Server thread/ERROR] [Sponge]: /* java.lang.Thread.run(Unknown Source) */
[20:30:25] [Server thread/ERROR] [Sponge]: /* Phases Remaining: */
[20:30:25] [Server thread/ERROR] [Sponge]: /* */
[20:30:25] [Server thread/ERROR] [Sponge]: /* Minecraft : 1.12.2 */
[20:30:25] [Server thread/ERROR] [Sponge]: /* SpongeAPI : 7.1.0-SNAPSHOT-b163786 */
[20:30:25] [Server thread/ERROR] [Sponge]: /* SpongeForge : 1.12.2-2555-7.1.0-BETA-2851 */
[20:30:25] [Server thread/ERROR] [Sponge]: /* Minecraft Forge : 14.23.1.2589
How can i fix this?