Skip to content
This repository was archived by the owner on Nov 28, 2025. It is now read-only.

Commit d0fc7b5

Browse files
committed
improve API restart timeouts
- Fix a bug on 1.8.9
1 parent 8a74b5b commit d0fc7b5

File tree

2 files changed

+14
-9
lines changed

2 files changed

+14
-9
lines changed

1.8.9/src/main/java/io/github/axolotlclient/mixin/ControlsOptionsScreenMixin.java

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,8 @@
2222

2323
package io.github.axolotlclient.mixin;
2424

25+
import io.github.axolotlclient.modules.hud.HudManager;
26+
import io.github.axolotlclient.modules.hud.gui.hud.KeystrokeHud;
2527
import net.minecraft.client.gui.screen.options.ControlsOptionsScreen;
2628
import net.minecraft.client.gui.widget.ButtonWidget;
2729
import org.spongepowered.asm.mixin.Mixin;
@@ -34,8 +36,8 @@ public abstract class ControlsOptionsScreenMixin {
3436

3537
@Inject(method = "buttonClicked", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/Minecraft;openScreen(Lnet/minecraft/client/gui/screen/Screen;)V"))
3638
public void axolotlclient$updateKeystroke(ButtonWidget button, CallbackInfo ci) {
37-
/*TODO KeystrokeHud hud = (KeystrokeHud) HudManager.getInstance().get(KeystrokeHud.ID);
39+
KeystrokeHud hud = (KeystrokeHud) HudManager.getInstance().get(KeystrokeHud.ID);
3840
if (hud.isEnabled())
39-
hud.setKeystrokes();*/
41+
hud.setKeystrokes();
4042
}
4143
}

common/src/main/java/io/github/axolotlclient/api/API.java

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,7 @@ public class API {
7171
private AccountSettings settings;
7272
private HttpClient client;
7373
private CompletableFuture<?> restartingFuture;
74+
private int nextRestartSecs;
7475
private Future<?> statusUpdateFuture;
7576
private final ScheduledExecutorService statusUpdateExecutor;
7677
private static final List<BiContainer<Runnable, ListenerType>> afterStartupListeners = new ArrayList<>();
@@ -122,11 +123,11 @@ private CompletableFuture<?> authenticate() {
122123
try {
123124
if (!GlobalDataRequest.get(true).get(1, TimeUnit.MINUTES).success()) {
124125
logger.warn("Not trying to start API as it couldn't be reached!");
125-
return scheduleRestart(false);
126+
return scheduleRestart();
126127
}
127128
} catch (InterruptedException | ExecutionException | TimeoutException e) {
128129
logger.warn("Not trying to start API as it couldn't be reached within the timeout of 1 minute!");
129-
return scheduleRestart(false);
130+
return scheduleRestart();
130131
}
131132

132133
logDetailed("Authenticating with Mojang...");
@@ -364,20 +365,22 @@ public void onClose(int statusCode, String reason) {
364365
1014
365366
};
366367
if (Arrays.stream(error_codes).anyMatch(i -> i == statusCode) && apiOptions.enabled.get()) {
367-
scheduleRestart(true);
368+
scheduleRestart();
368369
}
369370
}
370371

371-
private CompletableFuture<?> scheduleRestart(boolean immediate) {
372+
private CompletableFuture<?> scheduleRestart() {
372373
if (restartingFuture != null) {
373374
restartingFuture.cancel(true);
375+
nextRestartSecs = Math.min(nextRestartSecs*2, 60);
376+
} else {
377+
nextRestartSecs = 2;
374378
}
375-
logger.info("Trying restart in " + (immediate ? "10 seconds" : "5 minutes."));
379+
logger.info("Trying restart in " + nextRestartSecs + "seconds.");
376380
restartingFuture = CompletableFuture.supplyAsync(() -> {
377381
logDetailed("Restarting API session...");
378382
return startup(account).join();
379-
}, immediate ? CompletableFuture.delayedExecutor(10, TimeUnit.SECONDS, ThreadExecuter.service()) :
380-
CompletableFuture.delayedExecutor(5, TimeUnit.MINUTES, ThreadExecuter.service()));
383+
}, CompletableFuture.delayedExecutor(nextRestartSecs, TimeUnit.SECONDS, ThreadExecuter.service()));
381384
return restartingFuture;
382385
}
383386

0 commit comments

Comments
 (0)