2019-12-13 17:22:16 +01:00
|
|
|
From 737e70fa2923a0b94fe8e6ab6835d1538450c1dd Mon Sep 17 00:00:00 2001
|
2019-03-28 05:58:05 +01:00
|
|
|
From: Aikar <aikar@aikar.co>
|
|
|
|
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
|
2019-12-13 17:22:16 +01:00
|
|
|
index 65b6051cf..72938a2e2 100644
|
2019-03-28 05:58:05 +01:00
|
|
|
--- a/src/main/java/net/minecraft/server/EntityPlayer.java
|
|
|
|
+++ b/src/main/java/net/minecraft/server/EntityPlayer.java
|
2019-06-25 03:47:58 +02:00
|
|
|
@@ -510,6 +510,46 @@ public class EntityPlayer extends EntityHuman implements ICrafting {
|
2019-03-28 05:58:05 +01:00
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
+ // 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
|
|
|
|
+
|
2019-05-05 19:19:34 +02:00
|
|
|
@Override
|
2019-03-28 05:58:05 +01:00
|
|
|
public void die(DamageSource damagesource) {
|
2019-06-25 03:47:58 +02:00
|
|
|
boolean flag = this.world.getGameRules().getBoolean(GameRules.SHOW_DEATH_MESSAGES);
|
2019-07-23 21:17:32 +02:00
|
|
|
@@ -594,7 +634,12 @@ public class EntityPlayer extends EntityHuman implements ICrafting {
|
2019-03-28 05:58:05 +01:00
|
|
|
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
|
|
|
|
}
|
2019-05-05 19:19:34 +02:00
|
|
|
|
2019-03-28 05:58:05 +01:00
|
|
|
this.setSpectatorTarget(this); // Remove spectated target
|
|
|
|
--
|
2019-12-12 17:20:43 +01:00
|
|
|
2.24.1
|
2019-03-28 05:58:05 +01:00
|
|
|
|