mirror of
https://github.com/CitizensDev/Citizens2.git
synced 2024-12-27 11:37:42 +01:00
Remove waypoint provider goal when providers change
This commit is contained in:
parent
a0c6039e8e
commit
7d8389b736
@ -138,6 +138,11 @@ public class GuidedWaypointProvider implements WaypointProvider {
|
||||
rebuildTree();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onRemove() {
|
||||
npc.getDefaultGoalController().removeGoal(currentGoal);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onSpawn(NPC npc) {
|
||||
this.npc = npc;
|
||||
|
@ -86,6 +86,11 @@ public class LinearWaypointProvider implements WaypointProvider {
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onRemove() {
|
||||
npc.getDefaultGoalController().removeGoal(currentGoal);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onSpawn(NPC npc) {
|
||||
this.npc = npc;
|
||||
|
@ -12,6 +12,7 @@ import org.bukkit.entity.Player;
|
||||
|
||||
public class WanderWaypointProvider implements WaypointProvider {
|
||||
private Goal currentGoal;
|
||||
private NPC npc;
|
||||
private volatile boolean paused;
|
||||
@Persist
|
||||
private final int xrange = DEFAULT_XRANGE;
|
||||
@ -42,8 +43,14 @@ public class WanderWaypointProvider implements WaypointProvider {
|
||||
public void load(DataKey key) {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onRemove() {
|
||||
npc.getDefaultGoalController().removeGoal(currentGoal);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onSpawn(NPC npc) {
|
||||
this.npc = npc;
|
||||
if (currentGoal == null) {
|
||||
currentGoal = WanderGoal.createWithNPCAndRange(npc, xrange, yrange);
|
||||
CitizensAPI.registerEvents(currentGoal);
|
||||
@ -61,5 +68,6 @@ public class WanderWaypointProvider implements WaypointProvider {
|
||||
}
|
||||
|
||||
private static final int DEFAULT_XRANGE = 3;
|
||||
|
||||
private static final int DEFAULT_YRANGE = 25;
|
||||
}
|
||||
|
@ -33,6 +33,11 @@ public interface WaypointProvider {
|
||||
*/
|
||||
public void load(DataKey key);
|
||||
|
||||
/**
|
||||
* Called when the provider is removed from the NPC.
|
||||
*/
|
||||
public void onRemove();
|
||||
|
||||
/**
|
||||
* Called when the {@link NPC} attached to this provider is spawned.
|
||||
*
|
||||
|
@ -81,8 +81,9 @@ public class Waypoints extends Trait {
|
||||
|
||||
@Override
|
||||
public void onSpawn() {
|
||||
if (provider != null)
|
||||
if (provider != null) {
|
||||
provider.onSpawn(getNPC());
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -105,14 +106,15 @@ public class Waypoints extends Trait {
|
||||
public boolean setWaypointProvider(String name) {
|
||||
name = name.toLowerCase();
|
||||
Class<? extends WaypointProvider> clazz = providers.get(name);
|
||||
if (clazz == null)
|
||||
return false;
|
||||
provider = create(clazz);
|
||||
if (provider == null)
|
||||
if (provider != null) {
|
||||
provider.onRemove();
|
||||
}
|
||||
if (clazz == null || (provider = create(clazz)) == null)
|
||||
return false;
|
||||
providerName = name;
|
||||
if (npc != null && npc.isSpawned())
|
||||
if (npc != null && npc.isSpawned()) {
|
||||
provider.onSpawn(npc);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user