Files
Bukkit/src/main/java/org/bukkit/event/entity/PlayerDeathEvent.java
Jerom van der Sar e0dc9470ef 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.
2014-08-17 11:40:42 -06:00

158 lines
4.2 KiB
Java

package org.bukkit.event.entity;
import java.util.List;
import org.bukkit.entity.Player;
import org.bukkit.inventory.ItemStack;
/**
* Thrown whenever a {@link Player} dies
*/
public class PlayerDeathEvent extends EntityDeathEvent {
private int newExp = 0;
private String deathMessage = "";
private int newLevel = 0;
private int newTotalExp = 0;
private boolean keepLevel = false;
private boolean keepInventory = false;
public PlayerDeathEvent(final Player player, final List<ItemStack> drops, final int droppedExp, final String deathMessage) {
this(player, drops, droppedExp, 0, deathMessage);
}
public PlayerDeathEvent(final Player player, final List<ItemStack> drops, final int droppedExp, final int newExp, final String deathMessage) {
this(player, drops, droppedExp, newExp, 0, 0, deathMessage);
}
public PlayerDeathEvent(final Player player, final List<ItemStack> drops, final int droppedExp, final int newExp, final int newTotalExp, final int newLevel, final String deathMessage) {
super(player, drops, droppedExp);
this.newExp = newExp;
this.newTotalExp = newTotalExp;
this.newLevel = newLevel;
this.deathMessage = deathMessage;
}
@Override
public Player getEntity() {
return (Player) entity;
}
/**
* Set the death message that will appear to everyone on the server.
*
* @param deathMessage Message to appear to other players on the server.
*/
public void setDeathMessage(String deathMessage) {
this.deathMessage = deathMessage;
}
/**
* Get the death message that will appear to everyone on the server.
*
* @return Message to appear to other players on the server.
*/
public String getDeathMessage() {
return deathMessage;
}
/**
* Gets how much EXP the Player should have at respawn.
* <p>
* This does not indicate how much EXP should be dropped, please see
* {@link #getDroppedExp()} for that.
*
* @return New EXP of the respawned player
*/
public int getNewExp() {
return newExp;
}
/**
* Sets how much EXP the Player should have at respawn.
* <p>
* This does not indicate how much EXP should be dropped, please see
* {@link #setDroppedExp(int)} for that.
*
* @param exp New EXP of the respawned player
*/
public void setNewExp(int exp) {
newExp = exp;
}
/**
* Gets the Level the Player should have at respawn.
*
* @return New Level of the respawned player
*/
public int getNewLevel() {
return newLevel;
}
/**
* Sets the Level the Player should have at respawn.
*
* @param level New Level of the respawned player
*/
public void setNewLevel(int level) {
newLevel = level;
}
/**
* Gets the Total EXP the Player should have at respawn.
*
* @return New Total EXP of the respawned player
*/
public int getNewTotalExp() {
return newTotalExp;
}
/**
* Sets the Total EXP the Player should have at respawn.
*
* @param totalExp New Total EXP of the respawned player
*/
public void setNewTotalExp(int totalExp) {
newTotalExp = totalExp;
}
/**
* Gets if the Player should keep all EXP at respawn.
* <p>
* This flag overrides other EXP settings
*
* @return True if Player should keep all pre-death exp
*/
public boolean getKeepLevel() {
return keepLevel;
}
/**
* Sets if the Player should keep all EXP at respawn.
* <p>
* This overrides all other EXP settings
*
* @param keepLevel True to keep all current value levels
*/
public void setKeepLevel(boolean keepLevel) {
this.keepLevel = keepLevel;
}
/**
* Sets if the Player keeps inventory on death.
*
* @param keepInventory True to keep the inventory
*/
public void setKeepInventory(boolean keepInventory) {
this.keepInventory = keepInventory;
}
/**
* Gets if the Player keeps inventory on death.
*
* @return True if the player keeps inventory on death
*/
public boolean getKeepInventory() {
return keepInventory;
}
}