diff options
Diffstat (limited to 'Spigot-Server-Patches/0430-PlayerDeathEvent-getItemsToKeep.patch')
-rw-r--r-- | Spigot-Server-Patches/0430-PlayerDeathEvent-getItemsToKeep.patch | 79 |
1 files changed, 79 insertions, 0 deletions
diff --git a/Spigot-Server-Patches/0430-PlayerDeathEvent-getItemsToKeep.patch b/Spigot-Server-Patches/0430-PlayerDeathEvent-getItemsToKeep.patch new file mode 100644 index 0000000000..7f1815dcfa --- /dev/null +++ b/Spigot-Server-Patches/0430-PlayerDeathEvent-getItemsToKeep.patch @@ -0,0 +1,79 @@ +From 4feb8f9b2bffe706d9eade116d6bf311dc77c451 Mon Sep 17 00:00:00 2001 +From: Aikar <[email protected]> +Date: Wed, 27 Mar 2019 23:01:33 -0400 +Subject: [PATCH] PlayerDeathEvent#getItemsToKeep + +Exposes a mutable array on items a player should keep on death + +Example Usage: https://gist.github.com/aikar/5bb202de6057a051a950ce1f29feb0b4 + +diff --git a/src/main/java/net/minecraft/server/EntityPlayer.java b/src/main/java/net/minecraft/server/EntityPlayer.java +index 1d37300832..b9d0c0f740 100644 +--- a/src/main/java/net/minecraft/server/EntityPlayer.java ++++ b/src/main/java/net/minecraft/server/EntityPlayer.java +@@ -490,6 +490,46 @@ public class EntityPlayer extends EntityHuman implements ICrafting { + }); + } + ++ // Paper start - process inventory ++ private static void processKeep(org.bukkit.event.entity.PlayerDeathEvent event, NonNullList<ItemStack> inv) { ++ List<org.bukkit.inventory.ItemStack> itemsToKeep = event.getItemsToKeep(); ++ if (inv == null) { ++ // remainder of items left in toKeep - plugin added stuff on death that wasn't in the initial loot? ++ if (!itemsToKeep.isEmpty()) { ++ for (org.bukkit.inventory.ItemStack itemStack : itemsToKeep) { ++ event.getEntity().getInventory().addItem(itemStack); ++ } ++ } ++ ++ return; ++ } ++ ++ for (int i = 0; i < inv.size(); ++i) { ++ ItemStack item = inv.get(i); ++ if (EnchantmentManager.shouldNotDrop(item) || itemsToKeep.isEmpty() || item.isEmpty()) { ++ inv.set(i, ItemStack.NULL_ITEM); ++ continue; ++ } ++ ++ final org.bukkit.inventory.ItemStack bukkitStack = item.getBukkitStack(); ++ boolean keep = false; ++ final Iterator<org.bukkit.inventory.ItemStack> iterator = itemsToKeep.iterator(); ++ while (iterator.hasNext()) { ++ final org.bukkit.inventory.ItemStack itemStack = iterator.next(); ++ if (bukkitStack.equals(itemStack)) { ++ iterator.remove(); ++ keep = true; ++ break; ++ } ++ } ++ ++ if (!keep) { ++ inv.set(i, ItemStack.NULL_ITEM); ++ } ++ } ++ } ++ // Paper end ++ + public void die(DamageSource damagesource) { + boolean flag = this.world.getGameRules().getBoolean("showDeathMessages"); + // CraftBukkit start - fire PlayerDeathEvent +@@ -567,8 +607,14 @@ public class EntityPlayer extends EntityHuman implements ICrafting { + this.releaseShoulderEntities(); + // we clean the player's inventory after the EntityDeathEvent is called so plugins can get the exact state of the inventory. + if (!event.getKeepInventory()) { +- this.inventory.clear(); ++ // Paper start - replace logic ++ for (NonNullList<ItemStack> inv : this.inventory.getComponents()) { ++ processKeep(event, inv); ++ } ++ processKeep(event, null); ++ // Paper end + } ++ + this.closeInventory(org.bukkit.event.inventory.InventoryCloseEvent.Reason.DEATH); // Paper + this.setSpectatorTarget(this); // Remove spectated target + // CraftBukkit end +-- +2.21.0 + |