package net.new_liberty.pvpranker;

import net.milkbowl.vault.chat.Chat;
import org.bukkit.ChatColor;
import org.bukkit.Location;
import org.bukkit.Material;
import org.bukkit.entity.Entity;
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.EntityDamageByEntityEvent;
import org.bukkit.event.entity.EntityDeathEvent;
import org.bukkit.event.entity.PlayerDeathEvent;
import org.bukkit.event.player.AsyncPlayerChatEvent;
import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.meta.SkullMeta;
import org.bukkit.plugin.RegisteredServiceProvider;

/**
 * PvPRanker listener
 */
public class PvPListener implements Listener {
    private static class FPlayer {
        public FPlayer() {
        }
    }
    private final PvPRanker plugin;

    private Chat chat;

    public PvPListener(PvPRanker plugin) {
        this.plugin = plugin;
    }

    public boolean setupChat() {
        RegisteredServiceProvider<Chat> chatProvider = plugin.getServer().getServicesManager().getRegistration(Chat.class);
        if (chatProvider != null) {
            chat = chatProvider.getProvider();
        }
        return (chat != null);
    }

    @EventHandler
    public void onAsyncPlayerChat(AsyncPlayerChatEvent event) {
        Player p = event.getPlayer();

        String fprefix = "[{factions_relcolor}" + ChatColor.BOLD + "{factions_roleprefix}"
                + ChatColor.RESET + "{factions_relcolor}{factions_name}" + ChatColor.WHITE + "]";
        String rank = ChatColor.WHITE + "{" + plugin.getPvPer(p.getName()).getRank(plugin.getMilestone()).getName() + ChatColor.WHITE + "}";
        if (p.hasPermission("pvpranker.hiderank")) {
            rank = "";
        }
        String prefix = ChatColor.translateAlternateColorCodes('&', chat.getPlayerPrefix(p));
        String suffix = ChatColor.translateAlternateColorCodes('&', chat.getPlayerSuffix(p));

        String format = fprefix + rank + prefix + " " + p.getName() + ": " + suffix + "%2$s";
        event.setFormat(format);
    }

    @EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true)
    public void onEntityDeath(EntityDeathEvent event) {
        Entity victim = event.getEntity();
        if (!(victim instanceof Player)) {
            return;
        }

        Player player = (Player) victim;
        if (player.getHealth() > 0) {
            return;
        }

        if (!(victim.getLastDamageCause() instanceof EntityDamageByEntityEvent)) {
            return;
        }

        Entity cause = ((EntityDamageByEntityEvent) victim.getLastDamageCause()).getDamager();
        if (!(cause instanceof Player)) {
            return;
        }

        Player killer = (Player) cause;


        final Location loc = player.getLocation();

        // Skull handling
        double chance = plugin.getConfig().getDouble("head-drop-chance", 0.1);
        if (chance > Math.random()) {
            ItemStack skull = new ItemStack(Material.SKULL_ITEM);
            SkullMeta sm = (SkullMeta) skull.getItemMeta();
            sm.setOwner(player.getName());
            skull.setItemMeta(sm);
            loc.getWorld().dropItemNaturally(loc, skull);
        }

        // Our closure
        final String killedName = player.getName();
        final String killerName = killer.getName();

        (new KillUpdateTask(plugin, loc, killerName, killedName)).runTaskAsynchronously(plugin);
    }
}

@@ -29,16 +29,128 @@
 anker;%0A%0A
+import java.text.DateFormat;%0Aimport java.text.SimpleDateFormat;%0Aimport java.util.Arrays;%0Aimport java.util.Date;%0A
 import n
@@ -502,57 +502,8 @@
 nt;%0A
-import org.bukkit.event.entity.EntityDeathEvent;%0A
 impo
@@ -836,66 +836,87 @@
 tic 
-class FPlayer %7B%0A        public FPlayer() %7B%0A        %7D%0A    %7D
+final DateFormat DATE_FORMAT = new SimpleDateFormat(%22MMMM d, yyyy hh:mm aaa%22);%0A
 %0A   
@@ -2299,26 +2299,26 @@
 d on
-EntityDeath(Entity
+PlayerDeath(Player
 Deat
@@ -2345,21 +2345,21 @@
     
-Entity victim
+Player player
  = e
@@ -2380,123 +2380,8 @@
 ();%0A
-        if (!(victim instanceof Player)) %7B%0A            return;%0A        %7D%0A%0A        Player player = (Player) victim;%0A
     
@@ -2459,22 +2459,22 @@
   if (!(
-victim
+player
 .getLast
@@ -2615,14 +2615,14 @@
 nt) 
-victim
+player
 .get
@@ -3129,24 +3129,239 @@
 getName());%0A
+            sm.setLore(Arrays.asList(ChatColor.RESET.toString() + ChatColor.WHITE + %22Killed by %22 + ChatColor.AQUA + killer.getName() + ChatColor.WHITE + %22 on %22 + ChatColor.YELLOW + DATE_FORMAT.format(new Date())));%0A
             

Use PlayerDeathEvent and add lore string to player head