package in.twizmwaz.cardinal.module.modules.deathTracker;

import in.twizmwaz.cardinal.GameHandler;
import in.twizmwaz.cardinal.event.CardinalDeathEvent;
import in.twizmwaz.cardinal.module.Module;
import in.twizmwaz.cardinal.module.modules.tntTracker.TntTracker;
import in.twizmwaz.cardinal.module.modules.tracker.DamageTracker;
import in.twizmwaz.cardinal.module.modules.tracker.SpleefTracker;
import org.bukkit.Bukkit;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.HandlerList;
import org.bukkit.event.entity.EntityDamageByEntityEvent;
import org.bukkit.event.entity.EntityDamageEvent;
import org.bukkit.event.entity.PlayerDeathEvent;

public class DeathTracker implements Module {

    protected DeathTracker() {
    }

    @Override
    public void unload() {
        HandlerList.unregisterAll(this);
    }

    @EventHandler
    public void onPlayerDeath(PlayerDeathEvent event) {
        if (!event.getEntity().hasMetadata("teamChange")) {
            Player killer = null;
            boolean time = DamageTracker.getEvent(event.getEntity()) != null && System.currentTimeMillis() - DamageTracker.getEvent(event.getEntity()).getTime() <= 7500;
            if (time && DamageTracker.getEvent(event.getEntity()).getDamager().getPlayer() != null) {
                killer = DamageTracker.getEvent(event.getEntity()).getDamager().getPlayer();
            }
            /* try {
                EntityDamageEvent.DamageCause cause = event.getEntity().getLastDamageCause().getCause();
                if (cause.equals(EntityDamageEvent.DamageCause.BLOCK_EXPLOSION) || cause.equals(EntityDamageEvent.DamageCause.ENTITY_EXPLOSION)) {
                    if (event.getEntity().getLastDamageCause() instanceof EntityDamageByEntityEvent) {
                        EntityDamageByEntityEvent damageByEntityEvent = (EntityDamageByEntityEvent) event.getEntity().getLastDamageCause();
                        if (TntTracker.getWhoPlaced(damageByEntityEvent.getDamager()) != null) {
                            if (Bukkit.getOfflinePlayer(TntTracker.getWhoPlaced(damageByEntityEvent.getDamager())).isOnline()) {
                                killer = Bukkit.getPlayer(TntTracker.getWhoPlaced(damageByEntityEvent.getDamager()));
                            }
                        }
                    }
                }
            } catch (NullPointerException e) {
            } */
            CardinalDeathEvent deathEvent = new CardinalDeathEvent(event.getEntity(), killer);
            if (time && DamageTracker.getEvent(event.getEntity()).getDamager().getPlayer() != null) {
                deathEvent.setTrackerDamageEvent(DamageTracker.getEvent(event.getEntity()));
            }
            Bukkit.getServer().getPluginManager().callEvent(deathEvent);
        } else {
            event.getEntity().removeMetadata("teamChange", GameHandler.getGameHandler().getPlugin());
        }
        event.setDeathMessage(null);
    }
}
@@ -384,24 +384,158 @@
 eefTracker;%0A
+import in.twizmwaz.cardinal.module.modules.tracker.Type;%0Aimport in.twizmwaz.cardinal.module.modules.tracker.event.TrackerDamageEvent;%0A
 import org.b
@@ -548,16 +548,16 @@
 Bukkit;%0A
-
 import o
@@ -1172,20 +1172,34 @@
     
-boolean time
+TrackerDamageEvent tracker
  = D
@@ -1238,16 +1238,52 @@
 ntity())
+;%0A            boolean time = tracker
  != null
@@ -1319,50 +1319,16 @@
 ) - 
-DamageT
+t
 racker.
-getEvent(event.getEntity()).
 getT
@@ -1362,788 +1362,176 @@
 if (
-time && DamageTracker.getEvent(event.getEntity()).getDamager().getPlayer() != null) %7B%0A                killer = DamageTracker.getEvent(event.getEntity()).getDamager().getPlayer();%0A            %7D%0A            /* try %7B%0A                EntityDamageEvent.DamageCause cause = event.getEntity().getLastDamageCause().getCause();%0A                if (cause.equals(EntityDamageEvent.DamageCause.BLOCK_EXPLOSION) %7C%7C cause.equals(EntityDamageEvent.DamageCause.ENTITY_EXPLOSION)) %7B%0A                    if (event.getEntity().getLastDamageCause() instanceof EntityDamageByEntityEvent) %7B%0A                        EntityDamageByEntityEvent damageByEntityEvent = (EntityDamageByEntityEvent) event.getEntity().getLastDamageCause();%0A                        if (TntTracker.getWhoPlaced(damageByEntityEvent
+(tracker.getType().equals(Type.KNOCKED) %7C%7C tracker.getType().equals(Type.SHOT)) && event.getEntity().getKiller() != null && event.getEntity().getKiller().equals(tracker
 .get
@@ -1540,24 +1540,16 @@
 mager())
- != null
 ) %7B%0A    
@@ -1564,398 +1564,154 @@
     
-            if (Bukkit.getOfflinePlayer(TntTracker.getWhoPlaced(damageByEntityEvent.getDamager())).isOnline()) %7B%0A                                killer = Bukkit.getPlayer(TntTracker.getWhoPlaced(damageByEntityEvent.getDamager()));%0A                            %7D%0A                        %7D%0A                    %7D%0A                %7D%0A            %7D catch (NullPointerException e) %7B%0A            %7D */
+killer = tracker.getDamager().getPlayer();%0A            %7D else if (time) %7B%0A                killer = tracker.getDamager().getPlayer();%0A            %7D
 %0A   

Improve death tracking