aboutsummaryrefslogtreecommitdiffhomepage
path: root/patches/server/0219-Add-TNTPrimeEvent.patch
blob: c9cfc333c7a73a4f3dd1c1e509dba63c8ad6842b (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
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
From: Mark Vainomaa <mikroskeem@mikroskeem.eu>
Date: Mon, 16 Jul 2018 00:05:05 +0300
Subject: [PATCH] Add TNTPrimeEvent


diff --git a/src/main/java/net/minecraft/world/entity/boss/enderdragon/EnderDragon.java b/src/main/java/net/minecraft/world/entity/boss/enderdragon/EnderDragon.java
index 6e2e570aa1c85eced9ed9578188db43df132a290..f5aee15f80e226c8d59e66b1a53f529e2fb524a5 100644
--- a/src/main/java/net/minecraft/world/entity/boss/enderdragon/EnderDragon.java
+++ b/src/main/java/net/minecraft/world/entity/boss/enderdragon/EnderDragon.java
@@ -543,6 +543,11 @@ public class EnderDragon extends Mob implements Enemy {
                     });
                     craftBlock.getNMS().spawnAfterBreak((ServerLevel) this.level(), blockposition, ItemStack.EMPTY, false);
                 }
+                // Paper start - TNTPrimeEvent
+                org.bukkit.block.Block tntBlock = CraftBlock.at(this.level(), blockposition);
+                if (!new com.destroystokyo.paper.event.block.TNTPrimeEvent(tntBlock, com.destroystokyo.paper.event.block.TNTPrimeEvent.PrimeReason.EXPLOSION, explosionSource.getIndirectSourceEntity().getBukkitEntity()).callEvent())
+                    continue;
+                // Paper end - TNTPrimeEvent
                 nmsBlock.wasExploded((ServerLevel) this.level(), blockposition, this.explosionSource);
 
                 this.level().removeBlock(blockposition, false);
diff --git a/src/main/java/net/minecraft/world/level/block/FireBlock.java b/src/main/java/net/minecraft/world/level/block/FireBlock.java
index be6e65e66d60dbc8b356666b4505af835d367e20..422e5750669457bea6e4b8de799d289e8e315a09 100644
--- a/src/main/java/net/minecraft/world/level/block/FireBlock.java
+++ b/src/main/java/net/minecraft/world/level/block/FireBlock.java
@@ -302,12 +302,19 @@ public class FireBlock extends BaseFireBlock {
 
                 world.setBlock(blockposition, this.getStateWithAge(world, blockposition, l), 3);
             } else {
-                world.removeBlock(blockposition, false);
+                if(iblockdata.getBlock() != Blocks.TNT) world.removeBlock(blockposition, false); // Paper - TNTPrimeEvent; We might be cancelling it below, move the setAir down
             }
 
             Block block = iblockdata.getBlock();
 
             if (block instanceof TntBlock) {
+                // Paper start - TNTPrimeEvent
+                org.bukkit.block.Block tntBlock = org.bukkit.craftbukkit.block.CraftBlock.at(world, blockposition);
+                if (!new com.destroystokyo.paper.event.block.TNTPrimeEvent(tntBlock, com.destroystokyo.paper.event.block.TNTPrimeEvent.PrimeReason.FIRE, null).callEvent()) {
+                    return;
+                }
+                world.removeBlock(blockposition, false);
+                // Paper end - TNTPrimeEvent
                 TntBlock.explode(world, blockposition);
             }
         }
diff --git a/src/main/java/net/minecraft/world/level/block/TntBlock.java b/src/main/java/net/minecraft/world/level/block/TntBlock.java
index 5e14568b325dc805e507d23ae66e789fc35ec3df..d256b0f3998028709334dd6c394d184f2c36efce 100644
--- a/src/main/java/net/minecraft/world/level/block/TntBlock.java
+++ b/src/main/java/net/minecraft/world/level/block/TntBlock.java
@@ -52,6 +52,12 @@ public class TntBlock extends Block {
     protected void onPlace(BlockState state, Level world, BlockPos pos, BlockState oldState, boolean notify) {
         if (!oldState.is(state.getBlock())) {
             if (world.hasNeighborSignal(pos) && CraftEventFactory.callTNTPrimeEvent(world, pos, PrimeCause.REDSTONE, null, null)) { // CraftBukkit - TNTPrimeEvent
+                // Paper start - TNTPrimeEvent
+                org.bukkit.block.Block tntBlock = org.bukkit.craftbukkit.block.CraftBlock.at(world, pos);
+                if (!new com.destroystokyo.paper.event.block.TNTPrimeEvent(tntBlock, com.destroystokyo.paper.event.block.TNTPrimeEvent.PrimeReason.REDSTONE, null).callEvent()) {
+                    return;
+                }
+                // Paper end - TNTPrimeEvent
                 TntBlock.explode(world, pos);
                 world.removeBlock(pos, false);
             }
@@ -62,6 +68,12 @@ public class TntBlock extends Block {
     @Override
     protected void neighborChanged(BlockState state, Level world, BlockPos pos, Block sourceBlock, @Nullable Orientation wireOrientation, boolean notify) {
         if (world.hasNeighborSignal(pos) && CraftEventFactory.callTNTPrimeEvent(world, pos, PrimeCause.REDSTONE, null, null)) { // CraftBukkit - TNTPrimeEvent
+            // Paper start - TNTPrimeEvent
+            org.bukkit.block.Block tntBlock = org.bukkit.craftbukkit.block.CraftBlock.at(world, pos);
+            if (!new com.destroystokyo.paper.event.block.TNTPrimeEvent(tntBlock, com.destroystokyo.paper.event.block.TNTPrimeEvent.PrimeReason.REDSTONE, null).callEvent()) {
+                return;
+            }
+            // Paper end - TNTPrimeEvent
             TntBlock.explode(world, pos);
             world.removeBlock(pos, false);
         }
@@ -79,6 +91,13 @@ public class TntBlock extends Block {
 
     @Override
     public void wasExploded(ServerLevel world, BlockPos pos, Explosion explosion) {
+        // Paper start - TNTPrimeEvent
+        org.bukkit.block.Block tntBlock = org.bukkit.craftbukkit.block.CraftBlock.at(world, pos);
+        org.bukkit.entity.Entity source = explosion.getDirectSourceEntity() != null ? explosion.getDirectSourceEntity().getBukkitEntity() : null;
+        if (!new com.destroystokyo.paper.event.block.TNTPrimeEvent(tntBlock, com.destroystokyo.paper.event.block.TNTPrimeEvent.PrimeReason.EXPLOSION, source).callEvent()) {
+            return;
+        }
+        // Paper end - TNTPrimeEvent
         PrimedTnt entitytntprimed = new PrimedTnt(world, (double) pos.getX() + 0.5D, (double) pos.getY(), (double) pos.getZ() + 0.5D, explosion.getIndirectSourceEntity());
         int i = entitytntprimed.getFuse();
 
@@ -110,6 +129,12 @@ public class TntBlock extends Block {
                 return InteractionResult.CONSUME;
             }
             // CraftBukkit end
+            // Paper start - TNTPrimeEvent
+            org.bukkit.block.Block tntBlock = org.bukkit.craftbukkit.block.CraftBlock.at(world, pos);
+            if (!new com.destroystokyo.paper.event.block.TNTPrimeEvent(tntBlock, com.destroystokyo.paper.event.block.TNTPrimeEvent.PrimeReason.ITEM, player.getBukkitEntity()).callEvent()) {
+                return InteractionResult.FAIL;
+            }
+            // Paper end - TNTPrimeEvent
             TntBlock.explode(world, pos, player);
             world.setBlock(pos, Blocks.AIR.defaultBlockState(), 11);
             Item item = stack.getItem();
@@ -137,6 +162,12 @@ public class TntBlock extends Block {
                     return;
                 }
                 // CraftBukkit end
+                // Paper start - TNTPrimeEvent
+                org.bukkit.block.Block tntBlock = org.bukkit.craftbukkit.block.CraftBlock.at(world, blockposition);
+                if (!new com.destroystokyo.paper.event.block.TNTPrimeEvent(tntBlock, com.destroystokyo.paper.event.block.TNTPrimeEvent.PrimeReason.PROJECTILE, projectile.getBukkitEntity()).callEvent()) {
+                    return;
+                }
+                // Paper end - TNTPrimeEvent
                 TntBlock.explode(world, blockposition, entity instanceof LivingEntity ? (LivingEntity) entity : null);
                 world.removeBlock(blockposition, false);
             }