TrackedEntity.java cleanup

This commit is contained in:
bm01 2012-07-03 03:36:49 +02:00
parent 8257fd8e7c
commit 1bbc1f28aa

View File

@ -5,14 +5,15 @@ import org.bukkit.entity.LivingEntity;
import com.gmail.nossr50.mcMMO; import com.gmail.nossr50.mcMMO;
public class TrackedEntity { public class TrackedEntity implements Runnable {
private LivingEntity livingEntity; private LivingEntity livingEntity;
private int arrowCount; private int arrowCount;
private int previousTicksLived; private int previousTicksLived;
private int taskId;
public TrackedEntity(LivingEntity livingEntity) { public TrackedEntity(LivingEntity livingEntity) {
this.livingEntity = livingEntity; this.livingEntity = livingEntity;
new CheckTrackedEntityExistence(this); taskId = Bukkit.getScheduler().scheduleSyncRepeatingTask(mcMMO.p, this, 12000, 12000);
} }
//LivingEntity.isDead() isn't a reliable way to know if an entity is still active //LivingEntity.isDead() isn't a reliable way to know if an entity is still active
@ -23,15 +24,10 @@ public class TrackedEntity {
if (currentTicksLived == previousTicksLived) { if (currentTicksLived == previousTicksLived) {
return false; return false;
} }
else {
previousTicksLived = currentTicksLived; previousTicksLived = currentTicksLived;
return true; return true;
} }
}
public LivingEntity getLivingEntity() {
return livingEntity;
}
public int getArrowCount() { public int getArrowCount() {
return arrowCount; return arrowCount;
@ -41,23 +37,11 @@ public class TrackedEntity {
arrowCount++; arrowCount++;
} }
private class CheckTrackedEntityExistence implements Runnable {
private TrackedEntity trackedEntity;
private int taskId;
public CheckTrackedEntityExistence(TrackedEntity trackedEntity) {
this.trackedEntity = trackedEntity;
//Check if the entity is still active every 10 minutes
taskId = Bukkit.getScheduler().scheduleSyncRepeatingTask(mcMMO.p, this, 12000, 12000);
}
@Override @Override
public void run() { public void run() {
if (!trackedEntity.isActive()) { if (!isActive()) {
Archery.removeFromTracker(trackedEntity); Archery.removeFromTracker(this);
Bukkit.getScheduler().cancelTask(taskId); Bukkit.getScheduler().cancelTask(taskId);
} }
} }
} }
}