mirror of
https://github.com/mcMMO-Dev/mcMMO.git
synced 2024-11-23 05:36:46 +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,14 +24,9 @@ public class TrackedEntity {
|
|||||||
if (currentTicksLived == previousTicksLived) {
|
if (currentTicksLived == previousTicksLived) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
else {
|
|
||||||
previousTicksLived = currentTicksLived;
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public LivingEntity getLivingEntity() {
|
previousTicksLived = currentTicksLived;
|
||||||
return livingEntity;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
public int getArrowCount() {
|
public int getArrowCount() {
|
||||||
@ -41,23 +37,11 @@ public class TrackedEntity {
|
|||||||
arrowCount++;
|
arrowCount++;
|
||||||
}
|
}
|
||||||
|
|
||||||
private class CheckTrackedEntityExistence implements Runnable {
|
@Override
|
||||||
private TrackedEntity trackedEntity;
|
public void run() {
|
||||||
private int taskId;
|
if (!isActive()) {
|
||||||
|
Archery.removeFromTracker(this);
|
||||||
public CheckTrackedEntityExistence(TrackedEntity trackedEntity) {
|
Bukkit.getScheduler().cancelTask(taskId);
|
||||||
this.trackedEntity = trackedEntity;
|
|
||||||
|
|
||||||
//Check if the entity is still active every 10 minutes
|
|
||||||
taskId = Bukkit.getScheduler().scheduleSyncRepeatingTask(mcMMO.p, this, 12000, 12000);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void run() {
|
|
||||||
if (!trackedEntity.isActive()) {
|
|
||||||
Archery.removeFromTracker(trackedEntity);
|
|
||||||
Bukkit.getScheduler().cancelTask(taskId);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user