3
0
Mirror von https://github.com/PaperMC/Paper.git synchronisiert 2024-11-15 04:20:04 +01:00
Paper/Spigot-Server-Patches/0355-BlockDestroyEvent.patch

42 Zeilen
2.1 KiB
Diff

2019-07-20 06:01:24 +02:00
From 5cf46619cee7f54e790731dc27455a63ed09046a 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
2019-07-20 06:01:24 +02:00
index ef561cd95b..dad0c893fd 100644
--- a/src/main/java/net/minecraft/server/World.java
+++ b/src/main/java/net/minecraft/server/World.java
2019-06-22 20:06:08 +02:00
@@ -524,8 +524,20 @@ public abstract class World implements IIBlockAccess, GeneratorAccess, AutoClose
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) {
2019-05-06 01:24:37 +02:00
+ 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) {
2019-05-05 19:19:34 +02:00
TileEntity tileentity = iblockdata.getBlock().isTileEntity() ? this.getTileEntity(blockposition) : null;
--
2019-06-22 20:06:08 +02:00
2.22.0