From b854308c88e932908b36b5ac3670ba29e348dbf3 Mon Sep 17 00:00:00 2001 From: Mark Vainomaa Date: Mon, 16 Jul 2018 00:06:26 +0300 Subject: [PATCH] Add TNTPrimeEvent --- .../0126-Add-TNTPrimeEvent.patch | 123 ++++++++++++++++ .../0330-Add-TNTPrimeEvent.patch | 135 ++++++++++++++++++ 2 files changed, 258 insertions(+) create mode 100644 Spigot-API-Patches/0126-Add-TNTPrimeEvent.patch create mode 100644 Spigot-Server-Patches/0330-Add-TNTPrimeEvent.patch diff --git a/Spigot-API-Patches/0126-Add-TNTPrimeEvent.patch b/Spigot-API-Patches/0126-Add-TNTPrimeEvent.patch new file mode 100644 index 0000000000..954aff898a --- /dev/null +++ b/Spigot-API-Patches/0126-Add-TNTPrimeEvent.patch @@ -0,0 +1,123 @@ +From c37e7e3d8691666860125168b5721d58cac6cbc6 Mon Sep 17 00:00:00 2001 +From: Mark Vainomaa +Date: Sun, 15 Jul 2018 22:17:55 +0300 +Subject: [PATCH] Add TNTPrimeEvent + + +diff --git a/src/main/java/com/destroystokyo/paper/event/block/TNTPrimeEvent.java b/src/main/java/com/destroystokyo/paper/event/block/TNTPrimeEvent.java +new file mode 100644 +index 00000000..4f8d5d2d +--- /dev/null ++++ b/src/main/java/com/destroystokyo/paper/event/block/TNTPrimeEvent.java +@@ -0,0 +1,108 @@ ++package com.destroystokyo.paper.event.block; ++ ++import org.bukkit.block.Block; ++import org.bukkit.entity.Entity; ++import org.bukkit.event.Cancellable; ++import org.bukkit.event.HandlerList; ++import org.bukkit.event.block.BlockEvent; ++ ++/** ++ * Called when TNT block is about to turn into {@link org.bukkit.entity.TNTPrimed} ++ *

++ * Cancelling it won't turn TNT into {@link org.bukkit.entity.TNTPrimed} and leaves ++ * the TNT block as-is ++ * ++ * @author Mark Vainomaa ++ */ ++public class TNTPrimeEvent extends BlockEvent implements Cancellable { ++ private static final HandlerList handlers = new HandlerList(); ++ private boolean cancelled; ++ private PrimeReason reason; ++ private Entity primerEntity; ++ ++ public TNTPrimeEvent(Block theBlock, PrimeReason reason, Entity primerEntity) { ++ super(theBlock); ++ this.reason = reason; ++ this.primerEntity = primerEntity; ++ } ++ ++ /** ++ * Gets the TNT prime reason ++ * ++ * @return Prime reason ++ */ ++ public PrimeReason getReason() { ++ return this.reason; ++ } ++ ++ /** ++ * Gets the TNT primer {@link Entity}. ++ * ++ * It's null if {@link #getReason()} is {@link PrimeReason#REDSTONE} or {@link PrimeReason#FIRE}. ++ * It's not null if {@link #getReason()} is {@link PrimeReason#ITEM} or {@link PrimeReason#PROJECTILE} ++ * It might be null if {@link #getReason()} is {@link PrimeReason#EXPLOSION} ++ * ++ * @return The {@link Entity} who primed the TNT ++ */ ++ public Entity getPrimerEntity() { ++ return this.primerEntity; ++ } ++ ++ /** ++ * Gets whether spawning {@link org.bukkit.entity.TNTPrimed} should be cancelled or not ++ * ++ * @return Whether spawning {@link org.bukkit.entity.TNTPrimed} should be cancelled or not ++ */ ++ @Override ++ public boolean isCancelled() { ++ return this.cancelled; ++ } ++ ++ /** ++ * Sets whether to cancel spawning {@link org.bukkit.entity.TNTPrimed} or not ++ * ++ * @param cancel whether spawning {@link org.bukkit.entity.TNTPrimed} should be cancelled or not ++ */ ++ @Override ++ public void setCancelled(boolean cancel) { ++ this.cancelled = cancel; ++ } ++ ++ @Override ++ public HandlerList getHandlers() { ++ return handlers; ++ } ++ ++ public static HandlerList getHandlerList() { ++ return handlers; ++ } ++ ++ public enum PrimeReason { ++ /** ++ * When TNT prime was caused by other explosion (chain reaction) ++ */ ++ EXPLOSION, ++ ++ /** ++ * When TNT prime was caused by fire ++ */ ++ FIRE, ++ ++ /** ++ * When {@link org.bukkit.entity.Player} used {@link org.bukkit.Material#FLINT_AND_STEEL} or ++ * {@link org.bukkit.Material#FIREBALL} on given TNT block ++ */ ++ ITEM, ++ ++ /** ++ * When TNT prime was caused by an {@link Entity} shooting TNT ++ * using a bow with {@link org.bukkit.enchantments.Enchantment#ARROW_FIRE} enchantment ++ */ ++ PROJECTILE, ++ ++ /** ++ * When redstone power triggered the TNT prime ++ */ ++ REDSTONE ++ } ++} +-- +2.18.0 + diff --git a/Spigot-Server-Patches/0330-Add-TNTPrimeEvent.patch b/Spigot-Server-Patches/0330-Add-TNTPrimeEvent.patch new file mode 100644 index 0000000000..07a798bce3 --- /dev/null +++ b/Spigot-Server-Patches/0330-Add-TNTPrimeEvent.patch @@ -0,0 +1,135 @@ +From ad3c6714f4743e1118ee70fcaa9eae2cc195d9e8 Mon Sep 17 00:00:00 2001 +From: Mark Vainomaa +Date: Mon, 16 Jul 2018 00:05:05 +0300 +Subject: [PATCH] Add TNTPrimeEvent + + +diff --git a/src/main/java/net/minecraft/server/BlockFire.java b/src/main/java/net/minecraft/server/BlockFire.java +index 6832a19a..8f6f993f 100644 +--- a/src/main/java/net/minecraft/server/BlockFire.java ++++ b/src/main/java/net/minecraft/server/BlockFire.java +@@ -1,5 +1,6 @@ + package net.minecraft.server; + ++import com.destroystokyo.paper.event.block.TNTPrimeEvent; // Paper - TNTPrimeEvent + import com.google.common.collect.Maps; + import java.util.Map; + import java.util.Random; +@@ -262,10 +263,16 @@ public class BlockFire extends Block { + + world.setTypeAndData(blockposition, this.getBlockData().set(BlockFire.AGE, Integer.valueOf(l)), 3); + } else { +- world.setAir(blockposition); ++ if(iblockdata.getBlock() != Blocks.TNT) world.setAir(blockposition); // Paper - TNTPrimeEvent + } + + if (iblockdata.getBlock() == Blocks.TNT) { ++ // Paper start - TNTPrimeEvent ++ org.bukkit.block.Block tntBlock = world.getWorld().getBlockAt(blockposition.getX(), blockposition.getY(), blockposition.getZ()); ++ if(!new TNTPrimeEvent(tntBlock, TNTPrimeEvent.PrimeReason.FIRE, null).callEvent()) ++ return; ++ world.setAir(blockposition); ++ // Paper end + Blocks.TNT.postBreak(world, blockposition, iblockdata.set(BlockTNT.EXPLODE, Boolean.valueOf(true))); + } + } +diff --git a/src/main/java/net/minecraft/server/BlockTNT.java b/src/main/java/net/minecraft/server/BlockTNT.java +index 9473e314..3a922553 100644 +--- a/src/main/java/net/minecraft/server/BlockTNT.java ++++ b/src/main/java/net/minecraft/server/BlockTNT.java +@@ -1,5 +1,7 @@ + package net.minecraft.server; + ++import com.destroystokyo.paper.event.block.TNTPrimeEvent; // Paper - TNTPrimeEvent ++ + public class BlockTNT extends Block { + + public static final BlockStateBoolean EXPLODE = BlockStateBoolean.of("explode"); +@@ -13,6 +15,11 @@ public class BlockTNT extends Block { + public void onPlace(World world, BlockPosition blockposition, IBlockData iblockdata) { + super.onPlace(world, blockposition, iblockdata); + if (world.isBlockIndirectlyPowered(blockposition)) { ++ // Paper start - TNTPrimeEvent ++ org.bukkit.block.Block tntBlock = world.getWorld().getBlockAt(blockposition.getX(), blockposition.getY(), blockposition.getZ()); ++ if(!new TNTPrimeEvent(tntBlock, TNTPrimeEvent.PrimeReason.REDSTONE, null).callEvent()) ++ return; ++ // Paper end + this.postBreak(world, blockposition, iblockdata.set(BlockTNT.EXPLODE, Boolean.valueOf(true))); + world.setAir(blockposition); + } +@@ -21,6 +28,11 @@ public class BlockTNT extends Block { + + public void a(IBlockData iblockdata, World world, BlockPosition blockposition, Block block, BlockPosition blockposition1) { + if (world.isBlockIndirectlyPowered(blockposition)) { ++ // Paper start - TNTPrimeEvent ++ org.bukkit.block.Block tntBlock = world.getWorld().getBlockAt(blockposition.getX(), blockposition.getY(), blockposition.getZ()); ++ if(!new TNTPrimeEvent(tntBlock, TNTPrimeEvent.PrimeReason.REDSTONE, null).callEvent()) ++ return; ++ // Paper end + this.postBreak(world, blockposition, iblockdata.set(BlockTNT.EXPLODE, Boolean.valueOf(true))); + world.setAir(blockposition); + } +@@ -29,6 +41,12 @@ public class BlockTNT extends Block { + + public void wasExploded(World world, BlockPosition blockposition, Explosion explosion) { + if (!world.isClientSide) { ++ // Paper start - TNTPrimeEvent ++ org.bukkit.block.Block tntBlock = world.getWorld().getBlockAt(blockposition.getX(), blockposition.getY(), blockposition.getZ()); ++ org.bukkit.entity.Entity source = explosion.source != null ? explosion.source.bukkitEntity : null; ++ if(!new TNTPrimeEvent(tntBlock, TNTPrimeEvent.PrimeReason.EXPLOSION, source).callEvent()) ++ return; ++ // Paper end + EntityTNTPrimed entitytntprimed = new EntityTNTPrimed(world, (double) ((float) blockposition.getX() + 0.5F), (double) blockposition.getY(), (double) ((float) blockposition.getZ() + 0.5F), explosion.getSource()); + + entitytntprimed.setFuseTicks((short) (world.random.nextInt(entitytntprimed.getFuseTicks() / 4) + entitytntprimed.getFuseTicks() / 8)); +@@ -56,6 +74,11 @@ public class BlockTNT extends Block { + ItemStack itemstack = entityhuman.b(enumhand); + + if (!itemstack.isEmpty() && (itemstack.getItem() == Items.FLINT_AND_STEEL || itemstack.getItem() == Items.FIRE_CHARGE)) { ++ // Paper start - TNTPrimeEvent ++ org.bukkit.block.Block tntBlock = world.getWorld().getBlockAt(blockposition.getX(), blockposition.getY(), blockposition.getZ()); ++ if(!new TNTPrimeEvent(tntBlock, TNTPrimeEvent.PrimeReason.ITEM, entityhuman.bukkitEntity).callEvent()) ++ return true; ++ // Paper end + this.a(world, blockposition, iblockdata.set(BlockTNT.EXPLODE, Boolean.valueOf(true)), (EntityLiving) entityhuman); + world.setTypeAndData(blockposition, Blocks.AIR.getBlockData(), 11); + if (itemstack.getItem() == Items.FLINT_AND_STEEL) { +@@ -80,6 +103,11 @@ public class BlockTNT extends Block { + return; + } + // CraftBukkit end ++ // Paper start - TNTPrimeEvent ++ org.bukkit.block.Block tntBlock = world.getWorld().getBlockAt(blockposition.getX(), blockposition.getY(), blockposition.getZ()); ++ if(!new TNTPrimeEvent(tntBlock, TNTPrimeEvent.PrimeReason.PROJECTILE, entityarrow.bukkitEntity).callEvent()) ++ return; ++ // Paper end + this.a(world, blockposition, world.getType(blockposition).set(BlockTNT.EXPLODE, Boolean.valueOf(true)), entityarrow.shooter instanceof EntityLiving ? (EntityLiving) entityarrow.shooter : null); + world.setAir(blockposition); + } +diff --git a/src/main/java/net/minecraft/server/EntityEnderDragon.java b/src/main/java/net/minecraft/server/EntityEnderDragon.java +index c925de97..86995ed3 100644 +--- a/src/main/java/net/minecraft/server/EntityEnderDragon.java ++++ b/src/main/java/net/minecraft/server/EntityEnderDragon.java +@@ -9,6 +9,7 @@ import org.apache.logging.log4j.Logger; + import org.bukkit.event.entity.EntityExplodeEvent; + import org.bukkit.event.entity.EntityRegainHealthEvent; + // CraftBukkit end ++import com.destroystokyo.paper.event.block.TNTPrimeEvent; // Paper - TNTPrimeEvent + + // PAIL: Fixme + public class EntityEnderDragon extends EntityInsentient implements IComplex, IMonster { +@@ -474,6 +475,11 @@ public class EntityEnderDragon extends EntityInsentient implements IComplex, IMo + if (nmsBlock.a(explosionSource)) { + nmsBlock.dropNaturally(this.world, new BlockPosition(blockX, blockY, blockZ), nmsBlock.fromLegacyData(block.getData()), event.getYield(), 0); + } ++ // Paper start - TNTPrimeEvent ++ org.bukkit.block.Block tntBlock = world.getWorld().getBlockAt(blockX, blockY, blockZ); ++ if(!new TNTPrimeEvent(tntBlock, TNTPrimeEvent.PrimeReason.EXPLOSION, explosionSource.getSource().bukkitEntity).callEvent()) ++ continue; ++ // Paper end + nmsBlock.wasExploded(world, new BlockPosition(blockX, blockY, blockZ), explosionSource); + + this.world.setAir(new BlockPosition(blockX, blockY, blockZ)); +-- +2.18.0 +