Stop pathfinding on pause

This commit is contained in:
fullwall 2018-10-08 23:25:40 +08:00
parent 1853a6f474
commit 0ecd480790
6 changed files with 24 additions and 22 deletions

View File

@ -37,7 +37,6 @@ import net.citizensnpcs.api.util.Messaging;
import net.citizensnpcs.editor.Editor;
import net.citizensnpcs.trait.waypoint.WaypointProvider.EnumerableWaypointProvider;
import net.citizensnpcs.trait.waypoint.triggers.TriggerEditPrompt;
import net.citizensnpcs.trait.waypoint.triggers.WaypointTrigger;
import net.citizensnpcs.util.Messages;
import net.citizensnpcs.util.Util;
@ -335,11 +334,7 @@ public class LinearWaypointProvider implements EnumerableWaypointProvider {
}
normaliseEditingSlot();
if (conversation != null) {
String base = "";
for (WaypointTrigger trigger : getCurrentWaypoint().getTriggers()) {
base += "\n - " + trigger.description();
}
Messaging.sendTr(player, Messages.WAYPOINT_TRIGGER_LIST, base);
getCurrentWaypoint().describeTriggers(player);
}
Messaging.sendTr(player, Messages.LINEAR_WAYPOINT_EDITOR_EDIT_SLOT_SET, editingSlot,
formatLoc(waypoints.get(editingSlot).getLocation()));
@ -350,11 +345,7 @@ public class LinearWaypointProvider implements EnumerableWaypointProvider {
currentGoal.onProviderChanged();
}
if (conversation != null) {
String base = "";
for (WaypointTrigger trigger : getCurrentWaypoint().getTriggers()) {
base += "\n - " + trigger.description();
}
Messaging.sendTr(player, Messages.WAYPOINT_TRIGGER_LIST, base);
getCurrentWaypoint().describeTriggers(player);
}
}
@ -452,6 +443,9 @@ public class LinearWaypointProvider implements EnumerableWaypointProvider {
public void setPaused(boolean pause) {
if (pause && currentDestination != null) {
selector.finish();
if (npc != null && npc.getNavigator().isNavigating()) {
npc.getNavigator().cancelNavigation();
}
}
paused = pause;
}

View File

@ -5,6 +5,7 @@ import java.util.List;
import org.bukkit.Bukkit;
import org.bukkit.Location;
import org.bukkit.command.CommandSender;
import com.google.common.collect.Lists;
@ -12,9 +13,11 @@ import net.citizensnpcs.api.CitizensAPI;
import net.citizensnpcs.api.npc.NPC;
import net.citizensnpcs.api.persistence.Persist;
import net.citizensnpcs.api.persistence.PersistenceLoader;
import net.citizensnpcs.api.util.Messaging;
import net.citizensnpcs.trait.waypoint.triggers.DelayTrigger;
import net.citizensnpcs.trait.waypoint.triggers.WaypointTrigger;
import net.citizensnpcs.trait.waypoint.triggers.WaypointTriggerRegistry;
import net.citizensnpcs.util.Messages;
public class Waypoint implements Locatable {
@Persist(required = true)
@ -30,11 +33,20 @@ public class Waypoint implements Locatable {
}
public void addTrigger(WaypointTrigger trigger) {
if (triggers == null)
if (triggers == null) {
triggers = Lists.newArrayList();
}
triggers.add(trigger);
}
public void describeTriggers(CommandSender sender) {
String base = "";
for (WaypointTrigger trigger : getTriggers()) {
base += "\n - " + trigger.description();
}
Messaging.sendTr(sender, Messages.WAYPOINT_TRIGGER_LIST, base);
}
public double distance(Waypoint dest) {
return location.distance(dest.location);
}

View File

@ -55,11 +55,7 @@ public class TriggerAddPrompt extends StringPrompt {
context.setSessionData(WaypointTriggerPrompt.CREATED_TRIGGER_KEY, null);
Messaging.sendTr((CommandSender) context.getForWhom(), Messages.WAYPOINT_TRIGGER_ADDED_SUCCESSFULLY,
returned.description());
String base = "";
for (WaypointTrigger trigger : editor.getCurrentWaypoint().getTriggers()) {
base += "\n - " + trigger.description();
}
Messaging.sendTr((CommandSender) context.getForWhom(), Messages.WAYPOINT_TRIGGER_LIST, base);
editor.getCurrentWaypoint().describeTriggers((CommandSender) context.getForWhom());
} else {
Messaging.sendErrorTr((CommandSender) context.getForWhom(), Messages.WAYPOINT_TRIGGER_EDITOR_INACTIVE);
}

View File

@ -56,12 +56,12 @@ public class TriggerRemovePrompt extends StringPrompt {
if (context.getSessionData("said") == Boolean.TRUE)
return "";
context.setSessionData("said", true);
String root = Messaging.tr(Messages.WAYPOINT_TRIGGER_REMOVE_PROMPT);
String root = "";
int i = 1;
for (WaypointTrigger trigger : editor.getCurrentWaypoint().getTriggers()) {
root += String.format("<br> %d. " + trigger.description(), i++);
root += String.format("<br> [[%d]]. " + trigger.description(), i++);
}
Messaging.send((CommandSender) context.getForWhom(), root);
Messaging.sendTr((CommandSender) context.getForWhom(), Messages.WAYPOINT_TRIGGER_REMOVE_PROMPT, root);
return "";
}
}

View File

@ -151,7 +151,7 @@ public class Util {
return false;
if (current.getWorld() != target.getWorld())
return false;
return current.distanceSquared(target) < Math.pow(range, 2);
return current.distanceSquared(target) <= Math.pow(range, 2);
}
public static EntityType matchEntityType(String toMatch) {

View File

@ -270,7 +270,7 @@ citizens.editors.waypoints.triggers.main.exit=<b>Exited the waypoint trigger edi
citizens.editors.waypoints.triggers.main.prompt=<b>- Waypoint Trigger Editor -<br> Type [[add]] or [[remove]] to edit triggers.<br> Type [[triggers]] or [[exit]] to exit this editor.<br> Current triggers are:{0}
citizens.editors.waypoints.triggers.remove.index-out-of-range=Index must be in the range [[1-{0}]].
citizens.editors.waypoints.triggers.remove.not-a-number=Index must be a number.
citizens.editors.waypoints.triggers.remove.prompt=Enter in the index of the trigger to delete or [[back]] to return to the edit prompt. Current triggers are:
citizens.editors.waypoints.triggers.remove.prompt=Enter in the index of the trigger to delete or [[back]] to return to the edit prompt. Current triggers are:{0}
citizens.editors.waypoints.triggers.remove.removed=Successfully removed trigger [[{0}]].
citizens.editors.waypoints.triggers.speed.prompt=Enter the speed modifier as a [[percentage]] of its base speed.
citizens.editors.waypoints.triggers.teleport.invalid-format=Invalid location given. Format is [[world]]:[[x]]:[[y]]:[[z]].