mirror of
https://github.com/PaperMC/Paper.git
synced 2024-11-01 08:20:51 +01:00
1e7dd72f15
The game uses 0.95d now
78 lines
3.1 KiB
Diff
78 lines
3.1 KiB
Diff
From 0000000000000000000000000000000000000000 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
|
|
|
|
== AT ==
|
|
public net.minecraft.world.entity.player.Inventory compartments
|
|
|
|
diff --git a/src/main/java/net/minecraft/server/level/ServerPlayer.java b/src/main/java/net/minecraft/server/level/ServerPlayer.java
|
|
index c46326b7c761057f2d61542e088278553d694d7c..c65b5054728418a62923eb4192d55ba30fd8f4fb 100644
|
|
--- a/src/main/java/net/minecraft/server/level/ServerPlayer.java
|
|
+++ b/src/main/java/net/minecraft/server/level/ServerPlayer.java
|
|
@@ -857,6 +857,46 @@ public class ServerPlayer extends Player {
|
|
});
|
|
}
|
|
|
|
+ // 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 (EnchantmentHelper.hasVanishingCurse(item) || itemsToKeep.isEmpty() || item.isEmpty()) {
|
|
+ inv.set(i, ItemStack.EMPTY);
|
|
+ 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.EMPTY);
|
|
+ }
|
|
+ }
|
|
+ }
|
|
+ // Paper end
|
|
+
|
|
@Override
|
|
public void die(DamageSource damageSource) {
|
|
this.gameEvent(GameEvent.ENTITY_DIE);
|
|
@@ -940,7 +980,12 @@ public class ServerPlayer extends Player {
|
|
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.getInventory().clearContent();
|
|
+ // Paper start - replace logic
|
|
+ for (NonNullList<ItemStack> inv : this.getInventory().compartments) {
|
|
+ processKeep(event, inv);
|
|
+ }
|
|
+ processKeep(event, null);
|
|
+ // Paper end
|
|
}
|
|
|
|
this.setCamera(this); // Remove spectated target
|