Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,10 @@ heartsPerNaturalDeath: 1
# The minimal amount of hearts. If a player gets to this amount of hearts, they will be eliminated.
# PLEASE ONLY CHANGE IF YOU KNOW WHAT YOU ARE DOING!
minHearts: 0
# The minimal amount of hearts required for a player to drop or give hearts when dying.
# Players below this threshold will still lose hearts but won't drop/give heart items.
# Set to 0 to disable this feature (players can always drop/give hearts)
minHeartsToSpawnHeartItem: 0
# This option will enforce the heart limit on admin commands like /lifestealz hearts <add, set> <player> <amount>
# Note that this
enforceMaxHeartsOnAdminCommands: false
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,15 @@ public class ZPlayerNaturalDeathEvent extends ZPlayerDeathEventBase {

@Getter @Setter
private String deathMessage;

@Getter @Setter
private boolean heartSpawningBlocked;

public ZPlayerNaturalDeathEvent(PlayerDeathEvent originalEvent, double heartsToLose) {
super(originalEvent);
this.heartsToLose = heartsToLose;
this.shouldDropHearts = false;
this.deathMessage = originalEvent.getDeathMessage();
this.heartSpawningBlocked = false;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,9 @@ public class ZPlayerPvPDeathEvent extends ZPlayerDeathEventBase {

@Getter @Setter
private String deathMessage;

@Getter @Setter
private boolean heartSpawningBlocked;

public ZPlayerPvPDeathEvent(PlayerDeathEvent originalEvent, Player killer, double heartsToLose, double heartsKillerGains) {
super(originalEvent);
Expand All @@ -33,5 +36,6 @@ public ZPlayerPvPDeathEvent(PlayerDeathEvent originalEvent, Player killer, doubl
this.shouldDropHearts = false;
this.killerShouldGainHearts = true;
this.deathMessage = originalEvent.getDeathMessage();
this.heartSpawningBlocked = false;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -92,13 +92,13 @@ private void handleHeartLoss(PlayerDeathEvent event, Player player, Player kille
if (isDeathByPlayer && !killerInGracePeriod) {
if (handleHeartGainCooldown(event, player, killer, healthToLoose)) {
preventKillerGain = true;
if (plugin.getConfig().getBoolean("heartGainCooldown.dropOnCooldown")) {
if (plugin.getConfig().getBoolean("heartGainCooldown.dropOnCooldown") && canSpawnHeartItem(playerData)) {
droppedAtKiller = true;
}
}
if (handleMaxHeartsLimit(event, player, killer, healthToLoose)) {
preventKillerGain = true;
if (plugin.getConfig().getBoolean("dropHeartsIfMax")) {
if (plugin.getConfig().getBoolean("dropHeartsIfMax") && canSpawnHeartItem(playerData)) {
droppedAtKiller = true;
}
}
Expand Down Expand Up @@ -170,10 +170,14 @@ private void handlePvPDeath(PlayerDeathEvent event, Player player, Player killer

ZPlayerPvPDeathEvent pvpEvent = new ZPlayerPvPDeathEvent(event, killer, healthToLoose, healthGain);

boolean shouldDropFromPvP = plugin.getConfig().getBoolean("dropHeartsPlayer") && !droppedAtKiller;
pvpEvent.setShouldDropHearts(shouldDropFromPvP);
// Check if player has enough hearts to spawn heart items
boolean canSpawnHearts = canSpawnHeartItem(playerData);
boolean shouldDropFromPvP = plugin.getConfig().getBoolean("dropHeartsPlayer") && !droppedAtKiller && canSpawnHearts;
boolean killerShouldGainHearts = !preventKillerGain && canSpawnHearts;

pvpEvent.setKillerShouldGainHearts(!preventKillerGain);
pvpEvent.setShouldDropHearts(shouldDropFromPvP);
pvpEvent.setKillerShouldGainHearts(killerShouldGainHearts);
pvpEvent.setHeartSpawningBlocked(!canSpawnHearts);

Bukkit.getPluginManager().callEvent(pvpEvent);

Expand Down Expand Up @@ -201,7 +205,11 @@ private void handlePvPDeath(PlayerDeathEvent event, Player player, Player killer
private void handleNaturalDeath(PlayerDeathEvent event, Player player, PlayerData playerData, double healthToLoose) {
ZPlayerNaturalDeathEvent naturalEvent =
new ZPlayerNaturalDeathEvent(event, healthToLoose);
naturalEvent.setShouldDropHearts(plugin.getConfig().getBoolean("dropHeartsNatural"));

// Check if player has enough hearts to spawn heart items
boolean canSpawnHearts = canSpawnHeartItem(playerData);
naturalEvent.setShouldDropHearts(plugin.getConfig().getBoolean("dropHeartsNatural") && canSpawnHearts);
naturalEvent.setHeartSpawningBlocked(!canSpawnHearts);
Bukkit.getPluginManager().callEvent(naturalEvent);

if (!naturalEvent.isCancelled()) {
Expand Down Expand Up @@ -356,4 +364,10 @@ private boolean restrictedHeartGainByGracePeriod(Player player) {
GracePeriodManager gracePeriodManager = plugin.getGracePeriodManager();
return gracePeriodManager.isInGracePeriod(player) && !gracePeriodManager.getConfig().gainHearts();
}

private boolean canSpawnHeartItem(PlayerData playerData) {
int minHearts = plugin.getConfig().getInt("minHeartsToSpawnHeartItem");
if (minHearts <= 0) return true; // Feature disabled
return playerData.getMaxHealth() >= minHearts * 2;
}
}
4 changes: 4 additions & 0 deletions src/main/resources/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,10 @@ heartsPerNaturalDeath: 1
# The minimal amount of hearts. If a player gets to this amount of hearts, they will be eliminated.
# PLEASE ONLY CHANGE IF YOU KNOW WHAT YOU ARE DOING!
minHearts: 0
# The minimal amount of hearts required for a player to drop or give hearts when dying.
# Players below this threshold will still lose hearts but won't drop/give heart items.
# Set to 0 to disable this feature (players can always drop/give hearts)
minHeartsToSpawnHeartItem: 0
# This option will enforce the heart limit on admin commands like /lifestealz hearts <add, set> <player> <amount>
# Note that this
enforceMaxHeartsOnAdminCommands: false
Expand Down