From 52fe52d83dc534290c93b491ff3069b13b48c2b8 Mon Sep 17 00:00:00 2001 From: CraftBukkit/Spigot Date: Tue, 9 Mar 2021 08:47:34 +1100 Subject: [PATCH] #810: Add option for a consumer before spawning an item By: Martoph --- .../java/org/bukkit/craftbukkit/CraftWorld.java | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/paper-server/src/main/java/org/bukkit/craftbukkit/CraftWorld.java b/paper-server/src/main/java/org/bukkit/craftbukkit/CraftWorld.java index 9ee5a1bfe3..e0b6451456 100644 --- a/paper-server/src/main/java/org/bukkit/craftbukkit/CraftWorld.java +++ b/paper-server/src/main/java/org/bukkit/craftbukkit/CraftWorld.java @@ -596,15 +596,28 @@ public class CraftWorld implements World { @Override public org.bukkit.entity.Item dropItem(Location loc, ItemStack item) { + return dropItem(loc, item, null); + } + + @Override + public org.bukkit.entity.Item dropItem(Location loc, ItemStack item, Consumer function) { Validate.notNull(item, "Cannot drop a Null item."); EntityItem entity = new EntityItem(world, loc.getX(), loc.getY(), loc.getZ(), CraftItemStack.asNMSCopy(item)); entity.pickupDelay = 10; + if (function != null) { + function.accept((org.bukkit.entity.Item) entity.getBukkitEntity()); + } world.addEntity(entity, SpawnReason.CUSTOM); return (org.bukkit.entity.Item) entity.getBukkitEntity(); } @Override public org.bukkit.entity.Item dropItemNaturally(Location loc, ItemStack item) { + return dropItemNaturally(loc, item, null); + } + + @Override + public org.bukkit.entity.Item dropItemNaturally(Location loc, ItemStack item, Consumer function) { double xs = (world.random.nextFloat() * 0.5F) + 0.25D; double ys = (world.random.nextFloat() * 0.5F) + 0.25D; double zs = (world.random.nextFloat() * 0.5F) + 0.25D; @@ -612,7 +625,7 @@ public class CraftWorld implements World { loc.setX(loc.getX() + xs); loc.setY(loc.getY() + ys); loc.setZ(loc.getZ() + zs); - return dropItem(loc, item); + return dropItem(loc, item, function); } @Override