org.bukkit.event.entity.PlayerDeathEvent Maven / Gradle / Ivy
package org.bukkit.event.entity;
import org.bukkit.entity.Player;
import org.bukkit.inventory.ItemStack;
import java.util.List;
/**
* 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 drops, final int droppedExp, final String deathMessage) {
this(player, drops, droppedExp, 0, deathMessage);
}
public PlayerDeathEvent(final Player player, final List 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 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;
}
/**
* 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;
}
/**
* 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;
}
/**
* Gets how much EXP the Player should have at respawn.
*
* 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.
*
* 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.
*
* 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.
*
* This overrides all other EXP settings
*
* This doesn't prevent prevent the EXP from dropping.
* {@link #setDroppedExp(int)} should be used stop the
* EXP from dropping.
*
* @param keepLevel True to keep all current value levels
*/
public void setKeepLevel(boolean keepLevel) {
this.keepLevel = keepLevel;
}
/**
* Gets if the Player keeps inventory on death.
*
* @return True if the player keeps inventory on death
*/
public boolean getKeepInventory() {
return keepInventory;
}
/**
* Sets if the Player keeps inventory on death.
*
* @param keepInventory True to keep the inventory
*/
public void setKeepInventory(boolean keepInventory) {
this.keepInventory = keepInventory;
}
}