Commits

Martoph authored and md_5 committed ee5006d1873
#810: Add option for a consumer before spawning an item
No tags

src/main/java/org/bukkit/craftbukkit/CraftWorld.java

Modified
589 589
590 590 return Collections.unmodifiableCollection(chunks);
591 591 }
592 592
593 593 public WorldServer getHandle() {
594 594 return world;
595 595 }
596 596
597 597 @Override
598 598 public org.bukkit.entity.Item dropItem(Location loc, ItemStack item) {
599 + return dropItem(loc, item, null);
600 + }
601 +
602 + @Override
603 + public org.bukkit.entity.Item dropItem(Location loc, ItemStack item, Consumer<org.bukkit.entity.Item> function) {
599 604 Validate.notNull(item, "Cannot drop a Null item.");
600 605 EntityItem entity = new EntityItem(world, loc.getX(), loc.getY(), loc.getZ(), CraftItemStack.asNMSCopy(item));
601 606 entity.pickupDelay = 10;
607 + if (function != null) {
608 + function.accept((org.bukkit.entity.Item) entity.getBukkitEntity());
609 + }
602 610 world.addEntity(entity, SpawnReason.CUSTOM);
603 611 return (org.bukkit.entity.Item) entity.getBukkitEntity();
604 612 }
605 613
606 614 @Override
607 615 public org.bukkit.entity.Item dropItemNaturally(Location loc, ItemStack item) {
616 + return dropItemNaturally(loc, item, null);
617 + }
618 +
619 + @Override
620 + public org.bukkit.entity.Item dropItemNaturally(Location loc, ItemStack item, Consumer<org.bukkit.entity.Item> function) {
608 621 double xs = (world.random.nextFloat() * 0.5F) + 0.25D;
609 622 double ys = (world.random.nextFloat() * 0.5F) + 0.25D;
610 623 double zs = (world.random.nextFloat() * 0.5F) + 0.25D;
611 624 loc = loc.clone();
612 625 loc.setX(loc.getX() + xs);
613 626 loc.setY(loc.getY() + ys);
614 627 loc.setZ(loc.getZ() + zs);
615 - return dropItem(loc, item);
628 + return dropItem(loc, item, function);
616 629 }
617 630
618 631 @Override
619 632 public Arrow spawnArrow(Location loc, Vector velocity, float speed, float spread) {
620 633 return spawnArrow(loc, velocity, speed, spread, Arrow.class);
621 634 }
622 635
623 636 @Override
624 637 public <T extends AbstractArrow> T spawnArrow(Location loc, Vector velocity, float speed, float spread, Class<T> clazz) {
625 638 Validate.notNull(loc, "Can not spawn arrow with a null location");

Everything looks good. We'll let you know here if there's anything you should know about.

Add shortcut