From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 From: BillyGalbreath Date: Wed, 20 Jan 2021 14:23:37 -0600 Subject: [PATCH] Allow adding items to BlockDropItemEvent diff --git a/src/main/java/org/bukkit/craftbukkit/event/CraftEventFactory.java b/src/main/java/org/bukkit/craftbukkit/event/CraftEventFactory.java index a0a116ac7a4e5ecfd7514b26add44e75be88f631..9ff0f70154367b99317ed3927a97ec08c7e9e015 100644 --- a/src/main/java/org/bukkit/craftbukkit/event/CraftEventFactory.java +++ b/src/main/java/org/bukkit/craftbukkit/event/CraftEventFactory.java @@ -380,13 +380,30 @@ public class CraftEventFactory { } public static void handleBlockDropItemEvent(Block block, BlockState state, EntityPlayer player, List items) { - BlockDropItemEvent event = new BlockDropItemEvent(block, state, player.getBukkitEntity(), Lists.transform(items, (item) -> (org.bukkit.entity.Item) item.getBukkitEntity())); + // Paper start + List list = new ArrayList<>(); + for (EntityItem item : items) { + list.add((Item) item.getBukkitEntity()); + } + BlockDropItemEvent event = new BlockDropItemEvent(block, state, player.getBukkitEntity(), list); + // Paper end Bukkit.getPluginManager().callEvent(event); if (!event.isCancelled()) { - for (EntityItem item : items) { - item.world.addEntity(item); + // Paper start + for (Item bukkit : list) { + if (!bukkit.isValid()) { + Entity item = ((org.bukkit.craftbukkit.entity.CraftItem) bukkit).getHandle(); + item.world.addEntity(item); + } + } + } else { + for (Item bukkit : list) { + if (bukkit.isValid()) { + bukkit.remove(); + } } + // Paper end } }