Mirror von
https://github.com/PaperMC/Paper.git
synchronisiert 2024-11-15 20:40:07 +01:00
e4d10a6d67
Upstream has released updates that appears to apply and compile correctly. This update has not been tested by PaperMC and as with ANY update, please do your own testing Bukkit Changes: 122289ff Add FaceAttachable interface to handle Grindstone facing in common with Switches a6db750e SPIGOT-5647: ZombieVillager entity should have getVillagerType() CraftBukkit Changes:bbe3d58e
SPIGOT-5650: Lectern.setPage(int) causes a NullPointerException3075579f
Add FaceAttachable interface to handle Grindstone facing in common with Switches95bd4238
SPIGOT-5647: ZombieVillager entity should have getVillagerType()4d975ac3
SPIGOT-5617: setBlockData does not work when NotPlayEvent is called by redstone current
78 Zeilen
3.1 KiB
Diff
78 Zeilen
3.1 KiB
Diff
From 0963bc06c2375acce010e07318a5d9b8484f6907 Mon Sep 17 00:00:00 2001
|
|
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
|
|
index f788e7eff0..d00b687d25 100644
|
|
--- a/src/main/java/net/minecraft/server/EntityPlayer.java
|
|
+++ b/src/main/java/net/minecraft/server/EntityPlayer.java
|
|
@@ -516,6 +516,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
|
|
+
|
|
@Override
|
|
public void die(DamageSource damagesource) {
|
|
boolean flag = this.world.getGameRules().getBoolean(GameRules.SHOW_DEATH_MESSAGES);
|
|
@@ -602,7 +642,12 @@ public class EntityPlayer extends EntityHuman implements ICrafting {
|
|
this.dropExperience();
|
|
// 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.setSpectatorTarget(this); // Remove spectated target
|
|
--
|
|
2.25.1
|
|
|