Paper/Spigot-Server-Patches/0341-BlockDestroyEvent.patch
Aikar 10502558e9
Workaround for some hacky environments that mess up things
2 people had issues where some plugin is doing some reallly insane NMS hackery
that created invalid worlds, which caused some errors...

Really don't understand what in the world they did, but putting in a dumb guard that
shouldn't even be necessary to just not send the sound effect rather than erroring.
2020-05-23 22:27:37 -04:00

39 lines
2.2 KiB
Diff

From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
From: Aikar <aikar@aikar.co>
Date: Wed, 6 Feb 2019 00:20:33 -0500
Subject: [PATCH] BlockDestroyEvent
Adds an event for when the server is going to destroy a current block,
potentially causing it to drop. This event can be cancelled to avoid
the block destruction, such as preventing signs from popping when
floating in the air.
This can replace many uses of BlockPhysicsEvent
diff --git a/src/main/java/net/minecraft/server/World.java b/src/main/java/net/minecraft/server/World.java
index e3253bd36b08dc0963a69d8bd417c9f666ea4406..98ea9bb98a1a447e1ab8a54839d263ee1cad58ff 100644
--- a/src/main/java/net/minecraft/server/World.java
+++ b/src/main/java/net/minecraft/server/World.java
@@ -453,8 +453,20 @@ public abstract class World implements GeneratorAccess, AutoCloseable {
return false;
} else {
Fluid fluid = this.getFluid(blockposition);
+ // Paper start - while the above setAir method is named same and looks very similar
+ // they are NOT used with same intent and the above should not fire this event. The above method is more of a BlockSetToAirEvent,
+ // it doesn't imply destruction of a block that plays a sound effect / drops an item.
+ boolean playEffect = true;
+ if (com.destroystokyo.paper.event.block.BlockDestroyEvent.getHandlerList().getRegisteredListeners().length > 0) {
+ com.destroystokyo.paper.event.block.BlockDestroyEvent event = new com.destroystokyo.paper.event.block.BlockDestroyEvent(MCUtil.toBukkitBlock(this, blockposition), fluid.getBlockData().createCraftBlockData(), flag);
+ if (!event.callEvent()) {
+ return false;
+ }
+ playEffect = event.playEffect();
+ }
+ // Paper end
- this.triggerEffect(2001, blockposition, Block.getCombinedId(iblockdata));
+ if (playEffect) this.triggerEffect(2001, blockposition, Block.getCombinedId(iblockdata)); // Paper
if (flag) {
TileEntity tileentity = iblockdata.getBlock().isTileEntity() ? this.getTileEntity(blockposition) : null;