public class PlayerDeathEvent extends EntityDeathEvent
Player
diesEvent.Result
entity
Constructor and Description |
---|
PlayerDeathEvent(@NotNull Player player,
@NotNull List<ItemStack> drops,
int droppedExp,
net.kyori.adventure.text.Component adventure$deathMessage) |
PlayerDeathEvent(@NotNull Player player,
@NotNull List<ItemStack> drops,
int droppedExp,
int newExp,
net.kyori.adventure.text.Component adventure$deathMessage,
@Nullable String deathMessage) |
PlayerDeathEvent(@NotNull Player player,
@NotNull List<ItemStack> drops,
int droppedExp,
int newExp,
int newTotalExp,
int newLevel,
net.kyori.adventure.text.Component adventure$deathMessage,
@Nullable String deathMessage) |
PlayerDeathEvent(@NotNull Player player,
@NotNull List<ItemStack> drops,
int droppedExp,
int newExp,
int newTotalExp,
int newLevel,
net.kyori.adventure.text.Component adventure$deathMessage,
@Nullable String deathMessage,
boolean doExpDrop) |
PlayerDeathEvent(@NotNull Player player,
@NotNull List<ItemStack> drops,
int droppedExp,
int newExp,
int newTotalExp,
int newLevel,
@Nullable String deathMessage)
Deprecated.
|
PlayerDeathEvent(@NotNull Player player,
@NotNull List<ItemStack> drops,
int droppedExp,
int newExp,
int newTotalExp,
int newLevel,
@Nullable String deathMessage,
boolean doExpDrop)
Deprecated.
|
PlayerDeathEvent(@NotNull Player player,
@NotNull List<ItemStack> drops,
int droppedExp,
int newExp,
@Nullable String deathMessage)
Deprecated.
|
PlayerDeathEvent(@NotNull Player player,
@NotNull List<ItemStack> drops,
int droppedExp,
@Nullable String deathMessage) |
Modifier and Type | Method and Description |
---|---|
net.kyori.adventure.text.Component |
deathMessage()
Get the death message that will appear to everyone on the server.
|
void |
deathMessage(net.kyori.adventure.text.Component deathMessage)
Set the death message that will appear to everyone on the server.
|
@Nullable String |
getDeathMessage()
Deprecated.
in favour of
deathMessage() |
@NotNull Player |
getEntity()
Returns the Entity involved in this event
|
@NotNull List<ItemStack> |
getItemsToKeep()
A mutable collection to add items that the player should retain in their inventory on death (Similar to KeepInventory game rule)
You MUST remove the item from the .getDrops() collection too or it will duplicate!
|
boolean |
getKeepInventory()
Gets if the Player keeps inventory on death.
|
boolean |
getKeepLevel()
Gets if the Player should keep all EXP at respawn.
|
int |
getNewExp()
Gets how much EXP the Player should have at respawn.
|
int |
getNewLevel()
Gets the Level the Player should have at respawn.
|
int |
getNewTotalExp()
Gets the Total EXP the Player should have at respawn.
|
void |
setDeathMessage(@Nullable String deathMessage)
Deprecated.
in favour of
deathMessage(net.kyori.adventure.text.Component) |
void |
setKeepInventory(boolean keepInventory)
Sets if the Player keeps inventory on death.
|
void |
setKeepLevel(boolean keepLevel)
Sets if the Player should keep all EXP at respawn.
|
void |
setNewExp(int exp)
Sets how much EXP the Player should have at respawn.
|
void |
setNewLevel(int level)
Sets the Level the Player should have at respawn.
|
void |
setNewTotalExp(int totalExp)
Sets the Total EXP the Player should have at respawn.
|
void |
setShouldDropExperience(boolean doExpDrop) |
boolean |
shouldDropExperience() |
getDeathSound, getDeathSoundCategory, getDeathSoundPitch, getDeathSoundVolume, getDroppedExp, getDrops, getHandlerList, getHandlers, getReviveHealth, isCancelled, setCancelled, setDeathSound, setDeathSoundCategory, setDeathSoundPitch, setDeathSoundVolume, setDroppedExp, setReviveHealth, setShouldPlayDeathSound, shouldPlayDeathSound
getEntityType
callEvent, getEventName, isAsynchronous
public PlayerDeathEvent(@NotNull @NotNull Player player, @NotNull @NotNull List<ItemStack> drops, int droppedExp, @Nullable net.kyori.adventure.text.Component adventure$deathMessage)
public PlayerDeathEvent(@NotNull @NotNull Player player, @NotNull @NotNull List<ItemStack> drops, int droppedExp, int newExp, @Nullable net.kyori.adventure.text.Component adventure$deathMessage, @Nullable @Nullable String deathMessage)
public PlayerDeathEvent(@NotNull @NotNull Player player, @NotNull @NotNull List<ItemStack> drops, int droppedExp, int newExp, int newTotalExp, int newLevel, @Nullable net.kyori.adventure.text.Component adventure$deathMessage, @Nullable @Nullable String deathMessage)
public PlayerDeathEvent(@NotNull @NotNull Player player, @NotNull @NotNull List<ItemStack> drops, int droppedExp, int newExp, int newTotalExp, int newLevel, @Nullable net.kyori.adventure.text.Component adventure$deathMessage, @Nullable @Nullable String deathMessage, boolean doExpDrop)
public PlayerDeathEvent(@NotNull @NotNull Player player, @NotNull @NotNull List<ItemStack> drops, int droppedExp, @Nullable @Nullable String deathMessage)
@Deprecated public PlayerDeathEvent(@NotNull @NotNull Player player, @NotNull @NotNull List<ItemStack> drops, int droppedExp, int newExp, @Nullable @Nullable String deathMessage)
@Deprecated public PlayerDeathEvent(@NotNull @NotNull Player player, @NotNull @NotNull List<ItemStack> drops, int droppedExp, int newExp, int newTotalExp, int newLevel, @Nullable @Nullable String deathMessage)
@NotNull public @NotNull List<ItemStack> getItemsToKeep()
{@literal @EventHandler(ignoreCancelled = true)}
public void onPlayerDeath(PlayerDeathEvent event) {
for (Iterator<ItemStack> iterator = event.getDrops().iterator(); iterator.hasNext(); ) {
ItemStack drop = iterator.next();
List<String> lore = drop.getLore();
if (lore != null && !lore.isEmpty()) {
if (lore.get(0).contains("(SOULBOUND)")) {
iterator.remove();
event.getItemsToKeep().add(drop);
}
}
}
}
Adding an item to this list that the player did not previously have will give them the item on death.
An example case could be a "Note" that "You died at X/Y/Z coordinates"public boolean shouldDropExperience()
public void setShouldDropExperience(boolean doExpDrop)
doExpDrop
- sets if experience should be dropped from this death@NotNull public @NotNull Player getEntity()
EntityEvent
getEntity
in class EntityDeathEvent
public void deathMessage(@Nullable net.kyori.adventure.text.Component deathMessage)
deathMessage
- Message to appear to other players on the server.@Nullable public net.kyori.adventure.text.Component deathMessage()
@Deprecated public void setDeathMessage(@Nullable @Nullable String deathMessage)
deathMessage(net.kyori.adventure.text.Component)
deathMessage
- Message to appear to other players on the server.@Nullable @Deprecated public @Nullable String getDeathMessage()
deathMessage()
public int getNewExp()
This does not indicate how much EXP should be dropped, please see
EntityDeathEvent.getDroppedExp()
for that.
public void setNewExp(int exp)
This does not indicate how much EXP should be dropped, please see
EntityDeathEvent.setDroppedExp(int)
for that.
exp
- New EXP of the respawned playerpublic int getNewLevel()
public void setNewLevel(int level)
level
- New Level of the respawned playerpublic int getNewTotalExp()
public void setNewTotalExp(int totalExp)
totalExp
- New Total EXP of the respawned playerpublic boolean getKeepLevel()
This flag overrides other EXP settings
public void setKeepLevel(boolean keepLevel)
This overrides all other EXP settings
This doesn't prevent the EXP from dropping.
EntityDeathEvent.setDroppedExp(int)
should be used stop the
EXP from dropping.
keepLevel
- True to keep all current value levelspublic void setKeepInventory(boolean keepInventory)
This doesn't prevent the items from dropping.
getDrops().clear()
should be used stop the
items from dropping.
keepInventory
- True to keep the inventorypublic boolean getKeepInventory()
Copyright © 2021. All rights reserved.