diff --git a/runelite-client/src/main/java/net/runelite/client/plugins/puzzlesolver/PuzzleSolverOverlay.java b/runelite-client/src/main/java/net/runelite/client/plugins/puzzlesolver/PuzzleSolverOverlay.java index b6833e371c..9069ddfd53 100644 --- a/runelite-client/src/main/java/net/runelite/client/plugins/puzzlesolver/PuzzleSolverOverlay.java +++ b/runelite-client/src/main/java/net/runelite/client/plugins/puzzlesolver/PuzzleSolverOverlay.java @@ -332,7 +332,8 @@ public class PuzzleSolverOverlay extends Overlay } // Solve the puzzle if we don't have an up to date solution - if (solver == null || cachedItems == null || (!shouldCache && !Arrays.equals(cachedItems, itemIds))) + if (solver == null || cachedItems == null + || (!shouldCache && solver.hasExceededWaitDuration() && !Arrays.equals(cachedItems, itemIds))) { solve(itemIds); shouldCache = true; diff --git a/runelite-client/src/main/java/net/runelite/client/plugins/puzzlesolver/solver/PuzzleSolver.java b/runelite-client/src/main/java/net/runelite/client/plugins/puzzlesolver/solver/PuzzleSolver.java index 5d063828b0..03ed1e73d8 100644 --- a/runelite-client/src/main/java/net/runelite/client/plugins/puzzlesolver/solver/PuzzleSolver.java +++ b/runelite-client/src/main/java/net/runelite/client/plugins/puzzlesolver/solver/PuzzleSolver.java @@ -25,6 +25,8 @@ */ package net.runelite.client.plugins.puzzlesolver.solver; +import com.google.common.base.Stopwatch; +import java.time.Duration; import java.util.List; import net.runelite.client.plugins.puzzlesolver.solver.pathfinding.Pathfinder; @@ -33,11 +35,14 @@ public class PuzzleSolver implements Runnable public static final int DIMENSION = 5; public static final int BLANK_TILE_VALUE = -1; + private static final Duration MAX_WAIT_DURATION = Duration.ofMillis(1500); + private Pathfinder pathfinder; private PuzzleState startState; private List solution; private int position; + private Stopwatch stopwatch; private boolean failed = false; public PuzzleSolver(Pathfinder pathfinder, PuzzleState startState) @@ -71,6 +76,11 @@ public class PuzzleSolver implements Runnable this.position = position; } + public boolean hasExceededWaitDuration() + { + return stopwatch.elapsed().compareTo(MAX_WAIT_DURATION) > 0; + } + public boolean hasFailed() { return failed; @@ -79,6 +89,7 @@ public class PuzzleSolver implements Runnable @Override public void run() { + stopwatch = Stopwatch.createStarted(); solution = pathfinder.computePath(startState); failed = solution == null; }