001    package org.bukkit.event.entity;
002    
003    import java.util.List;
004    
005    import org.bukkit.entity.Player;
006    import org.bukkit.inventory.ItemStack;
007    
008    /**
009     * Thrown whenever a {@link Player} dies
010     */
011    public class PlayerDeathEvent extends EntityDeathEvent {
012        private int newExp = 0;
013        private String deathMessage = "";
014        private int newLevel = 0;
015        private int newTotalExp = 0;
016        private boolean keepLevel = false;
017        private boolean keepInventory = false;
018    
019        public PlayerDeathEvent(final Player player, final List<ItemStack> drops, final int droppedExp, final String deathMessage) {
020            this(player, drops, droppedExp, 0, deathMessage);
021        }
022    
023        public PlayerDeathEvent(final Player player, final List<ItemStack> drops, final int droppedExp, final int newExp, final String deathMessage) {
024            this(player, drops, droppedExp, newExp, 0, 0, deathMessage);
025        }
026    
027        public PlayerDeathEvent(final Player player, final List<ItemStack> drops, final int droppedExp, final int newExp, final int newTotalExp, final int newLevel, final String deathMessage) {
028            super(player, drops, droppedExp);
029            this.newExp = newExp;
030            this.newTotalExp = newTotalExp;
031            this.newLevel = newLevel;
032            this.deathMessage = deathMessage;
033        }
034    
035        @Override
036        public Player getEntity() {
037            return (Player) entity;
038        }
039    
040        /**
041         * Set the death message that will appear to everyone on the server.
042         *
043         * @param deathMessage Message to appear to other players on the server.
044         */
045        public void setDeathMessage(String deathMessage) {
046            this.deathMessage = deathMessage;
047        }
048    
049        /**
050         * Get the death message that will appear to everyone on the server.
051         *
052         * @return Message to appear to other players on the server.
053         */
054        public String getDeathMessage() {
055            return deathMessage;
056        }
057    
058        /**
059         * Gets how much EXP the Player should have at respawn.
060         * <p>
061         * This does not indicate how much EXP should be dropped, please see
062         * {@link #getDroppedExp()} for that.
063         *
064         * @return New EXP of the respawned player
065         */
066        public int getNewExp() {
067            return newExp;
068        }
069    
070        /**
071         * Sets how much EXP the Player should have at respawn.
072         * <p>
073         * This does not indicate how much EXP should be dropped, please see
074         * {@link #setDroppedExp(int)} for that.
075         *
076         * @param exp New EXP of the respawned player
077         */
078        public void setNewExp(int exp) {
079            newExp = exp;
080        }
081    
082        /**
083         * Gets the Level the Player should have at respawn.
084         *
085         * @return New Level of the respawned player
086         */
087        public int getNewLevel() {
088            return newLevel;
089        }
090    
091        /**
092         * Sets the Level the Player should have at respawn.
093         *
094         * @param level New Level of the respawned player
095         */
096        public void setNewLevel(int level) {
097            newLevel = level;
098        }
099    
100        /**
101         * Gets the Total EXP the Player should have at respawn.
102         *
103         * @return New Total EXP of the respawned player
104         */
105        public int getNewTotalExp() {
106            return newTotalExp;
107        }
108    
109        /**
110         * Sets the Total EXP the Player should have at respawn.
111         *
112         * @param totalExp New Total EXP of the respawned player
113         */
114        public void setNewTotalExp(int totalExp) {
115            newTotalExp = totalExp;
116        }
117    
118        /**
119         * Gets if the Player should keep all EXP at respawn.
120         * <p>
121         * This flag overrides other EXP settings
122         *
123         * @return True if Player should keep all pre-death exp
124         */
125        public boolean getKeepLevel() {
126            return keepLevel;
127        }
128    
129        /**
130         * Sets if the Player should keep all EXP at respawn.
131         * <p>
132         * This overrides all other EXP settings
133         *
134         * @param keepLevel True to keep all current value levels
135         */
136        public void setKeepLevel(boolean keepLevel) {
137            this.keepLevel = keepLevel;
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        }
157    }