Skip to content

Commit

Permalink
Revert "Improve cancelling calculation"
Browse files Browse the repository at this point in the history
This reverts commit 4a4b4c5.
  • Loading branch information
AlexProgrammerDE committed Oct 13, 2024
1 parent 4a4b4c5 commit 6473b9d
Showing 1 changed file with 2 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -63,8 +63,6 @@ public static CompletableFuture<Void> executePathfinding(BotConnection bot, Goal
var dataManager = bot.dataManager();
var clientEntity = dataManager.clientEntity();

var pathCompletionFuture = new CompletableFuture<Void>();

Boolean2ObjectFunction<List<WorldAction>> findPath =
requiresRepositioning -> {
var level = dataManager.currentLevel()
Expand All @@ -80,21 +78,14 @@ public static CompletableFuture<Void> executePathfinding(BotConnection bot, Goal
logger.info("Starting calculations at: {}", start.formatXYZ());
var actionsFuture = routeFinder.findRouteFuture(NodeState.forInfo(start, inventory), requiresRepositioning);
bot.shutdownHooks().add(() -> actionsFuture.cancel(true));
while (!actionsFuture.isDone()) {
if (pathCompletionFuture.isDone()) {
actionsFuture.cancel(true);
return List.of();
}

TimeUtil.waitTime(1, TimeUnit.MILLISECONDS);
}

var actions = actionsFuture.join();
logger.info("Calculated path with {} actions: {}", actions.size(), actions);

return actions;
};

var pathCompletionFuture = new CompletableFuture<Void>();

// Cancel the path if the bot is disconnected
bot.shutdownHooks().add(() -> pathCompletionFuture.cancel(true));

Expand Down

0 comments on commit 6473b9d

Please sign in to comment.