|
| 1 | +local DROP_PERCENTAGE = 100 -- Always drop heads |
| 2 | +local ItemStack = import "org.bukkit.inventory.ItemStack" |
| 3 | +local Material = import "org.bukkit.Material" |
| 4 | +local MiniMessage = import "net.kyori.adventure.text.minimessage.MiniMessage":miniMessage() |
| 5 | + |
| 6 | +local function GetDateTime() |
| 7 | + local currentDateTime = os.date("*t") |
| 8 | + |
| 9 | + local month = string.format("%02d", currentDateTime.month) |
| 10 | + local day = string.format("%02d", currentDateTime.day) |
| 11 | + local year = currentDateTime.year |
| 12 | + local hour = string.format("%02d", currentDateTime.hour) |
| 13 | + local minute = string.format("%02d", currentDateTime.min) |
| 14 | + |
| 15 | + return string.format("%s/%s/%d | %s:%s", month, day, year, hour, minute) |
| 16 | +end |
| 17 | + |
| 18 | +local function GetPlayerSkull(player, killer) |
| 19 | + local item = ItemStack.new(Material.PLAYER_HEAD) |
| 20 | + local meta = item:getItemMeta() |
| 21 | + meta:displayName(MiniMessage:deserialize("<yellow>"..player:getName().."'s head")) |
| 22 | + local date = os.date('*t') |
| 23 | + local time = os.date("*t") |
| 24 | + |
| 25 | + local lore = { |
| 26 | + MiniMessage:deserialize("<green>Date: "..GetDateTime()) |
| 27 | + } |
| 28 | + if killer ~= nil then |
| 29 | + table.insert(lore, MiniMessage:deserialize("<red>Killed by: "..killer:getName())) |
| 30 | + end |
| 31 | + meta:lore(tolist(lore)) |
| 32 | + meta:setOwningPlayer(player) |
| 33 | + |
| 34 | + item:setItemMeta(meta) |
| 35 | + return item |
| 36 | +end |
| 37 | + |
| 38 | +script.hook("org.bukkit.event.entity.PlayerDeathEvent", function(event) |
| 39 | + local player = event:getEntity() |
| 40 | + local killer = player:getKiller() |
| 41 | + local item = GetPlayerSkull(player, killer) |
| 42 | + local inv = player:getInventory() |
| 43 | + if math.random(100) <= DROP_PERCENTAGE then |
| 44 | + player:getWorld():dropItemNaturally(player:getLocation(), item) |
| 45 | + end |
| 46 | +end) |
| 47 | + |
| 48 | +script.registerSimpleCommand(function(sender, args) |
| 49 | + local item = GetPlayerSkull(sender, sender) |
| 50 | + print(item) |
| 51 | + local inv = sender:getInventory() |
| 52 | + inv:setItemInMainHand(item) |
| 53 | +end, { |
| 54 | + name = "testskull", |
| 55 | + permission = "server.test" |
| 56 | +}) |
0 commit comments