Commits

Jerom van der Sar authored and turt2live committed 1c220ddc6e0
Add ability to keep items on death via plugins. Adds BUKKIT-5724

When a player dies their inventory is normally scattered over the the area in which they died. Plugins should be able to modify this behaviour by defining whether or not the player's inventory will be dropped on the ground or waiting for the player when they eventually respawn. This commit adds the methods required to the PlayerDeathEvent for plugins to be able to incorporate the behaviour mentioned as a simple boolean flag.
No tags

src/main/java/org/bukkit/event/entity/PlayerDeathEvent.java

Modified
7 7
8 8 /**
9 9 * Thrown whenever a {@link Player} dies
10 10 */
11 11 public class PlayerDeathEvent extends EntityDeathEvent {
12 12 private int newExp = 0;
13 13 private String deathMessage = "";
14 14 private int newLevel = 0;
15 15 private int newTotalExp = 0;
16 16 private boolean keepLevel = false;
17 + private boolean keepInventory = false;
17 18
18 19 public PlayerDeathEvent(final Player player, final List<ItemStack> drops, final int droppedExp, final String deathMessage) {
19 20 this(player, drops, droppedExp, 0, deathMessage);
20 21 }
21 22
22 23 public PlayerDeathEvent(final Player player, final List<ItemStack> drops, final int droppedExp, final int newExp, final String deathMessage) {
23 24 this(player, drops, droppedExp, newExp, 0, 0, deathMessage);
24 25 }
25 26
26 27 public PlayerDeathEvent(final Player player, final List<ItemStack> drops, final int droppedExp, final int newExp, final int newTotalExp, final int newLevel, final String deathMessage) {
128 129 /**
129 130 * Sets if the Player should keep all EXP at respawn.
130 131 * <p>
131 132 * This overrides all other EXP settings
132 133 *
133 134 * @param keepLevel True to keep all current value levels
134 135 */
135 136 public void setKeepLevel(boolean keepLevel) {
136 137 this.keepLevel = keepLevel;
137 138 }
139 +
140 + /**
141 + * Sets if the Player keeps inventory on death.
142 + *
143 + * @param keepInventory True to keep the inventory
144 + */
145 + public void setKeepInventory(boolean keepInventory) {
146 + this.keepInventory = keepInventory;
147 + }
148 +
149 + /**
150 + * Gets if the Player keeps inventory on death.
151 + *
152 + * @return True if the player keeps inventory on death
153 + */
154 + public boolean getKeepInventory() {
155 + return keepInventory;
156 + }
138 157 }

Everything looks good. We'll let you know here if there's anything you should know about.

Add shortcut