diff --git a/src/main/java/com/tcoded/playerbountiesplus/listener/DeathListener.java b/src/main/java/com/tcoded/playerbountiesplus/listener/DeathListener.java index 9e81ee3..aa2cb66 100644 --- a/src/main/java/com/tcoded/playerbountiesplus/listener/DeathListener.java +++ b/src/main/java/com/tcoded/playerbountiesplus/listener/DeathListener.java @@ -1,14 +1,19 @@ package com.tcoded.playerbountiesplus.listener; import java.util.UUID; +import java.util.concurrent.ThreadLocalRandom; import org.apache.commons.lang3.StringUtils; import org.bukkit.Bukkit; +import org.bukkit.Material; import org.bukkit.entity.Player; import org.bukkit.event.EventHandler; import org.bukkit.event.EventPriority; import org.bukkit.event.Listener; import org.bukkit.event.entity.PlayerDeathEvent; +import org.bukkit.inventory.ItemStack; +import org.bukkit.inventory.meta.SkullMeta; +import org.bukkit.profile.PlayerProfile; import com.tcoded.playerbountiesplus.PlayerBountiesOG; import com.tcoded.playerbountiesplus.event.BountyClaimEvent; @@ -150,6 +155,8 @@ public class DeathListener implements Listener { } + maybeDropPlayerHead(event, victim); + bountyDataManager.removeBounty(victimId); bountyDataManager.saveBountiesAsync(); @@ -190,6 +197,26 @@ public class DeathListener implements Listener { } + private void maybeDropPlayerHead(PlayerDeathEvent event, Player victim) { + + final double dropChance = Math.max(0D, Math.min(100D, plugin.getConfig().getDouble("bounty-head-drop-chance", 50D))); + if (ThreadLocalRandom.current().nextDouble(100D) >= dropChance) { + + return; + + } + + final ItemStack head = new ItemStack(Material.PLAYER_HEAD, 1); + final SkullMeta headMeta = (SkullMeta) head.getItemMeta(); + + final PlayerProfile profile = Bukkit.createPlayerProfile(victim.getUniqueId()); + headMeta.setPlayerProfile(profile); + head.setItemMeta(headMeta); + + event.getDrops().add(head); + + } + private String getLuckPermsPrefixLegacy(Player player) { if (luckPerms == null) { @@ -270,4 +297,4 @@ public class DeathListener implements Listener { } -} \ No newline at end of file +} diff --git a/src/main/resources/config.yml b/src/main/resources/config.yml index 30fd6c0..618a81f 100644 --- a/src/main/resources/config.yml +++ b/src/main/resources/config.yml @@ -36,9 +36,12 @@ bounty-claim-multiplier: 1.0 # If we should announce that the bounty was claimed bounty-claimed-announce: true +# Chance (0-100) that claiming a bounty drops the victim's player head. +bounty-head-drop-chance: 50.0 + # If we should announce that the bounty was placed bounty-placed-announce: true # Should the bounty money be taken from the player who dies? # This can reduce same-team killing (or the use of alts) to claim the bounty from themselves -bounty-take-from-victim: false \ No newline at end of file +bounty-take-from-victim: false