Bukkit-API  1.7.9-R0.2
The inofficial Bukkit-API
PlayerDeathEvent.java
1 package org.bukkit.event.entity;
2 
3 import java.util.List;
4 
5 import org.bukkit.entity.Player;
7 
8 /**
9  * Thrown whenever a {@link Player} dies
10  */
11 public class PlayerDeathEvent extends EntityDeathEvent {
12  private int newExp = 0;
13  private String deathMessage = "";
14  private int newLevel = 0;
15  private int newTotalExp = 0;
16  private boolean keepLevel = false;
17 
18  public PlayerDeathEvent(final Player player, final List<ItemStack> drops, final int droppedExp, final String deathMessage) {
19  this(player, drops, droppedExp, 0, deathMessage);
20  }
21 
22  public PlayerDeathEvent(final Player player, final List<ItemStack> drops, final int droppedExp, final int newExp, final String deathMessage) {
23  this(player, drops, droppedExp, newExp, 0, 0, deathMessage);
24  }
25 
26  public PlayerDeathEvent(final Player player, final List<ItemStack> drops, final int droppedExp, final int newExp, final int newTotalExp, final int newLevel, final String deathMessage) {
27  super(player, drops, droppedExp);
28  this.newExp = newExp;
29  this.newTotalExp = newTotalExp;
30  this.newLevel = newLevel;
31  this.deathMessage = deathMessage;
32  }
33 
34  @Override
35  public Player getEntity() {
36  return (Player) entity;
37  }
38 
39  /**
40  * Set the death message that will appear to everyone on the server.
41  *
42  * @param deathMessage Message to appear to other players on the server.
43  */
44  public void setDeathMessage(String deathMessage) {
45  this.deathMessage = deathMessage;
46  }
47 
48  /**
49  * Get the death message that will appear to everyone on the server.
50  *
51  * @return Message to appear to other players on the server.
52  */
53  public String getDeathMessage() {
54  return deathMessage;
55  }
56 
57  /**
58  * Gets how much EXP the Player should have at respawn.
59  * <p>
60  * This does not indicate how much EXP should be dropped, please see
61  * {@link #getDroppedExp()} for that.
62  *
63  * @return New EXP of the respawned player
64  */
65  public int getNewExp() {
66  return newExp;
67  }
68 
69  /**
70  * Sets how much EXP the Player should have at respawn.
71  * <p>
72  * This does not indicate how much EXP should be dropped, please see
73  * {@link #setDroppedExp(int)} for that.
74  *
75  * @param exp New EXP of the respawned player
76  */
77  public void setNewExp(int exp) {
78  newExp = exp;
79  }
80 
81  /**
82  * Gets the Level the Player should have at respawn.
83  *
84  * @return New Level of the respawned player
85  */
86  public int getNewLevel() {
87  return newLevel;
88  }
89 
90  /**
91  * Sets the Level the Player should have at respawn.
92  *
93  * @param level New Level of the respawned player
94  */
95  public void setNewLevel(int level) {
96  newLevel = level;
97  }
98 
99  /**
100  * Gets the Total EXP the Player should have at respawn.
101  *
102  * @return New Total EXP of the respawned player
103  */
104  public int getNewTotalExp() {
105  return newTotalExp;
106  }
107 
108  /**
109  * Sets the Total EXP the Player should have at respawn.
110  *
111  * @param totalExp New Total EXP of the respawned player
112  */
113  public void setNewTotalExp(int totalExp) {
114  newTotalExp = totalExp;
115  }
116 
117  /**
118  * Gets if the Player should keep all EXP at respawn.
119  * <p>
120  * This flag overrides other EXP settings
121  *
122  * @return True if Player should keep all pre-death exp
123  */
124  public boolean getKeepLevel() {
125  return keepLevel;
126  }
127 
128  /**
129  * Sets if the Player should keep all EXP at respawn.
130  * <p>
131  * This overrides all other EXP settings
132  *
133  * @param keepLevel True to keep all current value levels
134  */
135  public void setKeepLevel(boolean keepLevel) {
136  this.keepLevel = keepLevel;
137  }
138 }