Mirror von
https://github.com/PaperMC/Paper.git
synchronisiert 2024-11-15 04:20:04 +01:00
38b3182a90
Upstream has released updates that appear 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: befcf86d SPIGOT-7740: Fix using new map cursor types 09229095 Add EntityDamageEvent.DamageCause#CAMPFIRE CraftBukkit Changes: a1d2cd152 SPIGOT-7747: Mob head is not dropped when mob was blown up by a charged creeper 8078294bc SPIGOT-7746: Server Crashing when Players Getting into End Portals 8d842e250 SPIGOT-7744: Fix exception for shooting projectiles with flame enchantment 64e0ad129 SPIGOT-7744: Fix crash when shooting arrows in creative mode 819f7a10a Fix player items not dropping on death 0a0229bb5 Implement DamageCause#CAMPFIRE and minor improvement in exception for Unhandled block damage
78 Zeilen
3.4 KiB
Diff
78 Zeilen
3.4 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 e56f9295e8624d1d73443f8f2178c2bc177f3f9f..8209b4d0edf9b9d47d6496c6695c426b26e19e3a 100644
|
|
--- a/src/main/java/net/minecraft/server/level/ServerPlayer.java
|
|
+++ b/src/main/java/net/minecraft/server/level/ServerPlayer.java
|
|
@@ -899,6 +899,46 @@ public class ServerPlayer extends net.minecraft.world.entity.player.Player {
|
|
});
|
|
}
|
|
|
|
+ // Paper start - PlayerDeathEvent#getItemsToKeep
|
|
+ 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.has(item, EnchantmentEffectComponents.PREVENT_EQUIPMENT_DROP) || 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 - PlayerDeathEvent#getItemsToKeep
|
|
+
|
|
@Override
|
|
public void die(DamageSource damageSource) {
|
|
// this.gameEvent(GameEvent.ENTITY_DIE); // Paper - move below event cancellation check
|
|
@@ -983,7 +1023,12 @@ public class ServerPlayer extends net.minecraft.world.entity.player.Player {
|
|
this.dropExperience(damageSource.getEntity());
|
|
// 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 - PlayerDeathEvent#getItemsToKeep
|
|
+ for (NonNullList<ItemStack> inv : this.getInventory().compartments) {
|
|
+ processKeep(event, inv);
|
|
+ }
|
|
+ processKeep(event, null);
|
|
+ // Paper end - PlayerDeathEvent#getItemsToKeep
|
|
}
|
|
|
|
this.setCamera(this); // Remove spectated target
|