From 6abb4398b9b4349ab672b61607ab8ebecad92a24 Mon Sep 17 00:00:00 2001 From: Parker Hawke Date: Thu, 25 Jun 2020 19:01:18 -0400 Subject: [PATCH] SPIGOT-5830: Server crash when campfire lit via dispenser. Also adds a missing call to BlockIgniteEvent for players igniting campfires with flint and steel. --- nms-patches/BlockCampfire.patch | 2 +- nms-patches/ItemFlintAndSteel.patch | 9 +++++++++ .../org/bukkit/craftbukkit/event/CraftEventFactory.java | 9 +++++++++ 3 files changed, 19 insertions(+), 1 deletion(-) diff --git a/nms-patches/BlockCampfire.patch b/nms-patches/BlockCampfire.patch index de9715346a..3cc6405bd0 100644 --- a/nms-patches/BlockCampfire.patch +++ b/nms-patches/BlockCampfire.patch @@ -5,7 +5,7 @@ BlockPosition blockposition = movingobjectpositionblock.getBlockPosition(); + // CraftBukkit start -+ if (org.bukkit.craftbukkit.event.CraftEventFactory.callBlockIgniteEvent(world, blockposition, entity).isCancelled()) { ++ if (org.bukkit.craftbukkit.event.CraftEventFactory.callBlockIgniteEvent(world, blockposition, iprojectile).isCancelled()) { + return; + } + // CraftBukkit end diff --git a/nms-patches/ItemFlintAndSteel.patch b/nms-patches/ItemFlintAndSteel.patch index 639d4ce650..abb0dcabf6 100644 --- a/nms-patches/ItemFlintAndSteel.patch +++ b/nms-patches/ItemFlintAndSteel.patch @@ -1,5 +1,14 @@ --- a/net/minecraft/server/ItemFlintAndSteel.java +++ b/net/minecraft/server/ItemFlintAndSteel.java +@@ -13,7 +13,7 @@ + BlockPosition blockposition = itemactioncontext.getClickPosition(); + IBlockData iblockdata = world.getType(blockposition); + +- if (BlockCampfire.h(iblockdata)) { ++ if (BlockCampfire.h(iblockdata) && !org.bukkit.craftbukkit.event.CraftEventFactory.callBlockIgniteEvent(world, blockposition, entityhuman).isCancelled()) { // CraftBukkit + world.playSound(entityhuman, blockposition, SoundEffects.ITEM_FLINTANDSTEEL_USE, SoundCategory.BLOCKS, 1.0F, ItemFlintAndSteel.RANDOM.nextFloat() * 0.4F + 0.8F); + world.setTypeAndData(blockposition, (IBlockData) iblockdata.set(BlockProperties.r, true), 11); + if (entityhuman != null) { @@ -27,6 +27,14 @@ BlockPosition blockposition1 = blockposition.shift(itemactioncontext.getClickedFace()); diff --git a/src/main/java/org/bukkit/craftbukkit/event/CraftEventFactory.java b/src/main/java/org/bukkit/craftbukkit/event/CraftEventFactory.java index e60f5ca773..e6970cbd22 100644 --- a/src/main/java/org/bukkit/craftbukkit/event/CraftEventFactory.java +++ b/src/main/java/org/bukkit/craftbukkit/event/CraftEventFactory.java @@ -50,6 +50,7 @@ import net.minecraft.server.GeneratorAccess; import net.minecraft.server.IBlockData; import net.minecraft.server.IChatBaseComponent; import net.minecraft.server.IInventory; +import net.minecraft.server.IProjectile; import net.minecraft.server.ItemActionContext; import net.minecraft.server.ItemStack; import net.minecraft.server.Items; @@ -208,6 +209,7 @@ import org.bukkit.inventory.EquipmentSlot; import org.bukkit.inventory.InventoryView; import org.bukkit.inventory.meta.BookMeta; import org.bukkit.potion.PotionEffect; +import org.bukkit.projectiles.ProjectileSource; public class CraftEventFactory { public static final DamageSource MELTING = CraftDamageSource.copyOf(DamageSource.BURN); @@ -1213,6 +1215,13 @@ public class CraftEventFactory { cause = IgniteCause.FLINT_AND_STEEL; } + if (igniter instanceof IProjectile) { + Entity shooter = ((IProjectile) igniter).getShooter(); + if (shooter != null) { + bukkitIgniter = shooter.getBukkitEntity(); + } + } + BlockIgniteEvent event = new BlockIgniteEvent(bukkitWorld.getBlockAt(pos.getX(), pos.getY(), pos.getZ()), cause, bukkitIgniter); world.getServer().getPluginManager().callEvent(event); return event;