From 2f10ac86ccc08b44204d1f3a2cb459d0efccee37 Mon Sep 17 00:00:00 2001 From: fullwall Date: Tue, 24 Nov 2020 20:34:22 +0800 Subject: [PATCH] Avoid caching empty paths --- .../trait/waypoint/LinearWaypointProvider.java | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/main/src/main/java/net/citizensnpcs/trait/waypoint/LinearWaypointProvider.java b/main/src/main/java/net/citizensnpcs/trait/waypoint/LinearWaypointProvider.java index aa264af5f..908fae3d3 100644 --- a/main/src/main/java/net/citizensnpcs/trait/waypoint/LinearWaypointProvider.java +++ b/main/src/main/java/net/citizensnpcs/trait/waypoint/LinearWaypointProvider.java @@ -22,6 +22,7 @@ import org.bukkit.event.player.PlayerInteractEntityEvent; import org.bukkit.event.player.PlayerInteractEvent; import org.bukkit.util.Vector; +import com.google.common.collect.Iterables; import com.google.common.collect.Lists; import com.google.common.collect.Maps; @@ -534,7 +535,7 @@ public class LinearWaypointProvider implements EnumerableWaypointProvider { SourceDestinationPair key = new SourceDestinationPair(npcLoc, currentDestination); Iterable cached = cachedPaths.get(key); if (cached != null) { - if (!key.verify(npcLoc.getWorld(), cached)) { + if (Iterables.size(cached) == 0 || !key.verify(npcLoc.getWorld(), cached)) { cachedPaths.remove(key); } else { getNavigator().setTarget(cached); @@ -552,8 +553,10 @@ public class LinearWaypointProvider implements EnumerableWaypointProvider { Setting.DEFAULT_DISTANCE_MARGIN.asDouble() + 1)) { currentDestination.onReach(npc); if (cachePaths && cancelReason == null) { - cachedPaths.put(new SourceDestinationPair(npcLoc, currentDestination), - getNavigator().getPathStrategy().getPath()); + Iterable path = getNavigator().getPathStrategy().getPath(); + if (Iterables.size(path) > 0) { + cachedPaths.put(new SourceDestinationPair(npcLoc, currentDestination), path); + } } } selector.finish();