From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 From: Matthew Miller Date: Sun, 17 Jan 2021 13:16:09 +1000 Subject: [PATCH] Implement BlockPreDispenseEvent diff --git a/src/main/java/net/minecraft/world/level/block/BlockDispenser.java b/src/main/java/net/minecraft/world/level/block/BlockDispenser.java index 0000000000000000000000000000000000000000..0000000000000000000000000000000000000000 100644 --- a/src/main/java/net/minecraft/world/level/block/BlockDispenser.java +++ b/src/main/java/net/minecraft/world/level/block/BlockDispenser.java @@ -0,0 +0,0 @@ public class BlockDispenser extends BlockTileEntity { IDispenseBehavior idispensebehavior = this.a(itemstack); if (idispensebehavior != IDispenseBehavior.NONE) { + if (!org.bukkit.craftbukkit.event.CraftEventFactory.handleBlockPreDispenseEvent(worldserver, blockposition, itemstack, i)) return; // Paper - BlockPreDispenseEvent is called here eventFired = false; // CraftBukkit - reset event status tileentitydispenser.setItem(i, idispensebehavior.dispense(sourceblock, itemstack)); } diff --git a/src/main/java/org/bukkit/craftbukkit/event/CraftEventFactory.java b/src/main/java/org/bukkit/craftbukkit/event/CraftEventFactory.java index 0000000000000000000000000000000000000000..0000000000000000000000000000000000000000 100644 --- a/src/main/java/org/bukkit/craftbukkit/event/CraftEventFactory.java +++ b/src/main/java/org/bukkit/craftbukkit/event/CraftEventFactory.java @@ -0,0 +0,0 @@ import net.minecraft.world.phys.MovingObjectPosition; import net.minecraft.world.phys.MovingObjectPositionBlock; import net.minecraft.world.phys.MovingObjectPositionEntity; import net.minecraft.world.phys.Vec3D; +import io.papermc.paper.event.block.BlockPreDispenseEvent; // Paper import org.bukkit.Bukkit; import org.bukkit.Location; // Paper import org.bukkit.Material; @@ -0,0 +0,0 @@ public class CraftEventFactory { BlockFailedDispenseEvent event = new BlockFailedDispenseEvent(block); return event.callEvent(); } + + public static boolean handleBlockPreDispenseEvent(WorldServer worldserver, BlockPosition blockposition, ItemStack itemStack, int slot) { + org.bukkit.block.Block block = worldserver.getWorld().getBlockAt(blockposition.getX(), blockposition.getY(), blockposition.getZ()); + BlockPreDispenseEvent event = new BlockPreDispenseEvent(block, org.bukkit.craftbukkit.inventory.CraftItemStack.asCraftMirror(itemStack), slot); + return event.callEvent(); + } // Paper end }