package tc.oc.tracker.event;

import javax.annotation.Nonnull;

import org.bukkit.entity.Entity;
import org.bukkit.event.Cancellable;
import org.bukkit.event.HandlerList;
import org.bukkit.event.entity.EntityEvent;

import tc.oc.tracker.Damage;
import tc.oc.tracker.Lifetime;

import com.google.common.base.Preconditions;

/**
 * Called when an entity undergoes some type of damage.
 */
public class EntityDamageEvent extends EntityEvent implements Cancellable {
    private final @Nonnull Lifetime lifetime;
    private final @Nonnull Damage damage;
    private int hearts;
    private boolean cancelled = false;

    public EntityDamageEvent(@Nonnull Entity entity, @Nonnull Lifetime lifetime, @Nonnull Damage damage) {
        super(entity);

        Preconditions.checkNotNull(lifetime, "lifetime");
        Preconditions.checkNotNull(damage, "damage");

        this.lifetime = lifetime;
        this.damage = damage;
        this.hearts = damage.getHearts();
    }

    public @Nonnull Lifetime getLifetime() {
        return this.lifetime;
    }

    public @Nonnull Damage getDamage() {
        return this.damage;
    }

    public int getHearts() {
        return this.hearts;
    }

    public void setHearts(int hearts) {
        Preconditions.checkArgument(hearts >= 0, "hearts must be greater than or equal to zero");

        this.hearts = hearts;
    }

    public boolean isCancelled() {
        return this.cancelled;
    }

    public void setCancelled(boolean cancel) {
        this.cancelled = cancel;
    }

    // Bukkit event junk
    public static final HandlerList handlers = new HandlerList();

    @Override
    public HandlerList getHandlers() {
        return handlers;
    }

    public static HandlerList getHandlerList() {
        return handlers;
    }
}

@@ -57,16 +57,44 @@
 nnull;%0A%0A
+import org.bukkit.Location;%0A
 import o
@@ -231,24 +231,54 @@
 EntityEvent;
+%0Aimport org.joda.time.Instant;
 %0A%0Aimport tc.
@@ -294,16 +294,20 @@
 r.Damage
+Info
 ;%0Aimport
@@ -580,35 +580,104 @@
 ate 
-final @Nonnull Damage damag
+int hearts;%0A    private final @Nonnull Location location;%0A    private final @Nonnull Instant tim
 e;%0A 
@@ -683,34 +683,54 @@
     private 
+f
 in
-t hearts
+al @Nonnull DamageInfo info
 ;%0A    privat
@@ -844,30 +844,95 @@
 me, 
-@Nonnull Damage damage
+int hearts, @Nonnull Location location, @Nonnull Instant time, @Nonnull DamageInfo info
 ) %7B%0A
@@ -1044,44 +1044,87 @@
 heck
-NotNull(damage, %22damage
+Argument(hearts %3E= 0, %22hearts must be greater than or equal to zero
 %22);%0A
-%0A
         
 this
@@ -1123,142 +1123,188 @@
     
-this.lifetime = lifetime;%0A        this.damage = damage;%0A        thi
+Preconditions.checkNotNull(location, %22location%22);%0A        Preconditions.checkNotNull(time, %22time%22);%0A        Precondition
 s.
+c
 he
-arts = damage.getHearts(
+ckNotNull(info, %22damage info%22
 );%0A
+%0A
     
-%7D%0A%0A
     
-public @Nonnull L
+this.l
 ifetime 
 getL
@@ -1303,23 +1303,19 @@
 ime 
-getL
+= l
 ifetime
-() %7B
+;
 %0A   
@@ -1323,77 +1323,71 @@
     
-return this.lifetime
+this.hearts = hearts
 ;%0A    
-%7D%0A%0A
     
-public @Nonnull Damage getDamage() %7B
+this.location = location.clone();
 %0A   
@@ -1395,26 +1395,50 @@
     
-return this.damage
+this.time = time;%0A        this.info = info
 ;%0A  
@@ -1674,32 +1674,345 @@
  hearts;%0A    %7D%0A%0A
+    public @Nonnull Location getLocation() %7B%0A        return this.location;%0A    %7D%0A%0A    public @Nonnull Instant getTime() %7B%0A        return this.time;%0A    %7D%0A%0A    public @Nonnull Lifetime getLifetime() %7B%0A        return this.lifetime;%0A    %7D%0A%0A    public @Nonnull DamageInfo getInfo() %7B%0A        return this.info;%0A    %7D%0A%0A
     public boole

Add more information to EntityDamageEvent.