mirror of
https://github.com/CitizensDev/Citizens2.git
synced 2024-11-16 15:46:14 +01:00
Fix to Age, cancel navigation target if npc despawns
This commit is contained in:
parent
6f211403c3
commit
3c5eb390a6
@ -172,7 +172,13 @@ public class CitizensNavigator implements Navigator {
|
||||
}
|
||||
|
||||
public void update() {
|
||||
if (!isNavigating() || !npc.isSpawned() || updateStationaryStatus())
|
||||
if (!isNavigating())
|
||||
return;
|
||||
if (!npc.isSpawned()) {
|
||||
stopNavigating(CancelReason.NPC_DESPAWNED);
|
||||
return;
|
||||
}
|
||||
if (updateStationaryStatus())
|
||||
return;
|
||||
boolean finished = executing.update();
|
||||
if (!finished)
|
||||
|
@ -31,6 +31,11 @@ public class MCNavigationStrategy implements PathStrategy {
|
||||
cancelReason = CancelReason.STUCK;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void clearCancelReason() {
|
||||
cancelReason = null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public CancelReason getCancelReason() {
|
||||
return cancelReason;
|
||||
@ -59,9 +64,4 @@ public class MCNavigationStrategy implements PathStrategy {
|
||||
navigation.a(parameters.speed());
|
||||
return navigation.f();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void clearCancelReason() {
|
||||
cancelReason = null;
|
||||
}
|
||||
}
|
||||
|
@ -39,6 +39,11 @@ public class MCTargetStrategy implements PathStrategy, EntityTarget {
|
||||
&& distanceSquared() <= ATTACK_DISTANCE && handle.l(target);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void clearCancelReason() {
|
||||
cancelReason = null;
|
||||
}
|
||||
|
||||
private double distanceSquared() {
|
||||
return handle.getBukkitEntity().getLocation().distanceSquared(target.getBukkitEntity().getLocation());
|
||||
}
|
||||
@ -101,11 +106,6 @@ public class MCTargetStrategy implements PathStrategy, EntityTarget {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void clearCancelReason() {
|
||||
cancelReason = null;
|
||||
}
|
||||
|
||||
private static final int ATTACK_DELAY_TICKS = 20;
|
||||
private static final double ATTACK_DISTANCE = 1.75 * 1.75;
|
||||
}
|
@ -6,6 +6,8 @@ import net.citizensnpcs.api.ai.event.CancelReason;
|
||||
import org.bukkit.Location;
|
||||
|
||||
public interface PathStrategy {
|
||||
void clearCancelReason();
|
||||
|
||||
CancelReason getCancelReason();
|
||||
|
||||
Location getTargetAsLocation();
|
||||
@ -15,6 +17,4 @@ public interface PathStrategy {
|
||||
void stop();
|
||||
|
||||
boolean update();
|
||||
|
||||
void clearCancelReason();
|
||||
}
|
@ -11,7 +11,6 @@ import org.bukkit.entity.Ageable;
|
||||
|
||||
public class Age extends Trait implements Toggleable {
|
||||
private int age = 0;
|
||||
private boolean ageable = false;
|
||||
private boolean locked = true;
|
||||
|
||||
public Age() {
|
||||
@ -23,6 +22,10 @@ public class Age extends Trait implements Toggleable {
|
||||
StringHelper.wrap(age), StringHelper.wrap(locked ? "is" : "isn't"));
|
||||
}
|
||||
|
||||
private boolean isAgeable() {
|
||||
return npc.getBukkitEntity() instanceof Ageable;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void load(DataKey key) throws NPCLoadException {
|
||||
if (npc.isSpawned() && !(npc.getBukkitEntity() instanceof Ageable))
|
||||
@ -33,18 +36,16 @@ public class Age extends Trait implements Toggleable {
|
||||
|
||||
@Override
|
||||
public void onSpawn() {
|
||||
if (npc instanceof Ageable) {
|
||||
if (isAgeable()) {
|
||||
Ageable entity = (Ageable) npc.getBukkitEntity();
|
||||
entity.setAge(age);
|
||||
entity.setAgeLock(locked);
|
||||
ageable = true;
|
||||
} else
|
||||
ageable = false;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
if (!locked && ageable)
|
||||
if (!locked && isAgeable())
|
||||
age = ((Ageable) npc.getBukkitEntity()).getAge();
|
||||
}
|
||||
|
||||
@ -56,14 +57,14 @@ public class Age extends Trait implements Toggleable {
|
||||
|
||||
public void setAge(int age) {
|
||||
this.age = age;
|
||||
if (ageable)
|
||||
if (isAgeable())
|
||||
((Ageable) npc.getBukkitEntity()).setAge(age);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean toggle() {
|
||||
locked = !locked;
|
||||
if (ageable)
|
||||
if (isAgeable())
|
||||
((Ageable) npc.getBukkitEntity()).setAgeLock(locked);
|
||||
return locked;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user