Paper/Spigot-API-Patches/0181-PlayerDeathEvent-getItemsToKeep.patch
Aikar be067fea11
PlayerDeathEvent#getItemsToKeep
Exposes a mutable array on items a player should keep on death.

This allows a cleaner method to implement "Keep certain items on death"
than how plugins currently do it in that it never removes them in first
place, so its safe if the player logs out/server is shutdown before respawn.

Example Usage: https://gist.github.com/aikar/5bb202de6057a051a950ce1f29feb0b4
2019-03-28 01:12:38 -04:00

40 Zeilen
1.5 KiB
Diff

From 9552cb45732ed2d11f179cdf766996d3c0843001 Mon Sep 17 00:00:00 2001
From: Aikar <aikar@aikar.co>
Date: Mon, 11 Mar 2013 20:04:34 -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/org/bukkit/event/entity/PlayerDeathEvent.java b/src/main/java/org/bukkit/event/entity/PlayerDeathEvent.java
index 5b0ef1eb1..b30818177 100644
--- a/src/main/java/org/bukkit/event/entity/PlayerDeathEvent.java
+++ b/src/main/java/org/bukkit/event/entity/PlayerDeathEvent.java
@@ -18,6 +18,22 @@ public class PlayerDeathEvent extends EntityDeathEvent {
private boolean keepLevel = false;
private boolean keepInventory = false;
+ // Paper start
+ private List<ItemStack> itemsToKeep = new java.util.ArrayList<>();
+
+ /**
+ * A mutable collection to add items that the player should keep on death (Similar to KeepInventory game rule)
+ *
+ * You <b>MUST</b> remove the item from the .getDrops() collection too or it will duplicate!
+ *
+ * @return The list to hold items to keep
+ */
+ @NotNull
+ public List<ItemStack> getItemsToKeep() {
+ return itemsToKeep;
+ }
+ // Paper end
+
public PlayerDeathEvent(@NotNull final Player player, @NotNull final List<ItemStack> drops, final int droppedExp, @Nullable final String deathMessage) {
this(player, drops, droppedExp, 0, deathMessage);
}
--
2.21.0