mirror of
https://github.com/mcMMO-Dev/mcMMO.git
synced 2024-11-26 23:26:45 +01:00
TrackedEntity.java cleanup
This commit is contained in:
parent
8257fd8e7c
commit
1bbc1f28aa
@ -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);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
Loading…
Reference in New Issue
Block a user