SPIGOT-7806: Handle both loot and inventory item drop behaviour in PlayerDeathEvent
By: Doc <nachito94@msn.com>
This commit is contained in:
@@ -924,7 +924,13 @@ public class CraftEventFactory {
|
||||
for (org.bukkit.inventory.ItemStack stack : event.getDrops()) {
|
||||
if (stack == null || stack.getType() == Material.AIR) continue;
|
||||
|
||||
victim.drop(CraftItemStack.asNMSCopy(stack), true, false, false); // SPIGOT-7800, SPIGOT-7801: Vanilla Behaviour for dropped items
|
||||
if (stack instanceof CraftItemStack craftItemStack && craftItemStack.isForInventoryDrop()) {
|
||||
victim.drop(CraftItemStack.asNMSCopy(stack), true, false, false); // SPIGOT-7800, SPIGOT-7801: Vanilla Behaviour for Player Inventory dropped items
|
||||
} else {
|
||||
victim.forceDrops = true;
|
||||
victim.spawnAtLocation(CraftItemStack.asNMSCopy(stack)); // SPIGOT-7806: Vanilla Behaviour for items not related to Player Inventory dropped items
|
||||
victim.forceDrops = false;
|
||||
}
|
||||
}
|
||||
|
||||
return event;
|
||||
|
||||
@@ -18,6 +18,7 @@ import org.bukkit.enchantments.Enchantment;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.bukkit.inventory.meta.ItemMeta;
|
||||
import org.bukkit.material.MaterialData;
|
||||
import org.jetbrains.annotations.ApiStatus;
|
||||
|
||||
@DelegateDeserialization(ItemStack.class)
|
||||
public final class CraftItemStack extends ItemStack {
|
||||
@@ -85,6 +86,7 @@ public final class CraftItemStack extends ItemStack {
|
||||
}
|
||||
|
||||
net.minecraft.world.item.ItemStack handle;
|
||||
private boolean isForInventoryDrop;
|
||||
|
||||
/**
|
||||
* Mirror
|
||||
@@ -104,6 +106,27 @@ public final class CraftItemStack extends ItemStack {
|
||||
setItemMeta(itemMeta);
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets if the item is marked as an inventory drop in death events.
|
||||
*
|
||||
* @return true if the item is marked as an inventory drop
|
||||
*/
|
||||
@ApiStatus.Internal
|
||||
public boolean isForInventoryDrop() {
|
||||
return this.isForInventoryDrop;
|
||||
}
|
||||
|
||||
/**
|
||||
* Marks this item as an inventory drop in death events.
|
||||
*
|
||||
* @return the ItemStack marked as an inventory drop
|
||||
*/
|
||||
@ApiStatus.Internal
|
||||
public ItemStack markForInventoryDrop() {
|
||||
this.isForInventoryDrop = true;
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public MaterialData getData() {
|
||||
return handle != null ? CraftMagicNumbers.getMaterialData(handle.getItem()) : super.getData();
|
||||
|
||||
Reference in New Issue
Block a user