aboutsummaryrefslogtreecommitdiffhomepage
path: root/Spigot-Server-Patches/0331-BlockDestroyEvent.patch
blob: ea42113e24e97bc9da975c1d9a15eecf56bd0df0 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
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 a0f93486b21e3bdbcf3b705c005c2e13f75589ed..722db2c45da211ef376fff4aa17964009b2e53e2 100644
--- a/src/main/java/net/minecraft/server/World.java
+++ b/src/main/java/net/minecraft/server/World.java
@@ -535,8 +535,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
 
-            if (!(iblockdata.getBlock() instanceof BlockFireAbstract)) {
+            if (playEffect && !(iblockdata.getBlock() instanceof BlockFireAbstract)) { // Paper
                 this.triggerEffect(2001, blockposition, Block.getCombinedId(iblockdata));
             }