Paper/patches/server/0565-Allow-adding-items-to-BlockDropItemEvent.patch
Jake Potrebic 9147456fc9
Updated Upstream (CraftBukkit/Spigot) (#8815)
Upstream has released updates that appear to apply and compile correctly.
This update has not been tested by PaperMC and as with ANY update, please do your own testing

CraftBukkit Changes:
ab8ace685 SPIGOT-7236: Bone meal doesn't increase use statistic
7dcb59b8e Avoid switch on material in previous commit

Spigot Changes:
19641c75 SPIGOT-7235: World.Spigot#strikeLightningEffect doesn't do anything
2023-01-27 12:52:04 -08:00

45 lines
1.9 KiB
Diff

From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
From: BillyGalbreath <blake.galbreath@gmail.com>
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 3d1817d686c53e893cfabe439b927ce8db770d32..49693aa4d136701c822ab4b386ab7ed8b061a156 100644
--- a/src/main/java/org/bukkit/craftbukkit/event/CraftEventFactory.java
+++ b/src/main/java/org/bukkit/craftbukkit/event/CraftEventFactory.java
@@ -400,13 +400,30 @@ public class CraftEventFactory {
}
public static void handleBlockDropItemEvent(Block block, BlockState state, ServerPlayer player, List<ItemEntity> items) {
- BlockDropItemEvent event = new BlockDropItemEvent(block, state, player.getBukkitEntity(), Lists.transform(items, (item) -> (org.bukkit.entity.Item) item.getBukkitEntity()));
+ // Paper start
+ List<Item> list = new ArrayList<>();
+ for (ItemEntity 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 (ItemEntity item : items) {
- item.level.addFreshEntity(item);
+ // Paper start
+ for (Item bukkit : list) {
+ if (!bukkit.isValid()) {
+ Entity item = ((org.bukkit.craftbukkit.entity.CraftItem) bukkit).getHandle();
+ item.level.addFreshEntity(item);
+ }
+ }
+ } else {
+ for (Item bukkit : list) {
+ if (bukkit.isValid()) {
+ bukkit.remove();
+ }
}
+ // Paper end
}
}