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

Commit ff5cdaa

Browse files
committed
check for api auth token expiration
1 parent 2eb5f6e commit ff5cdaa

File tree

14 files changed

+136
-76
lines changed

14 files changed

+136
-76
lines changed

1.16_combat-6/src/main/java/io/github/axolotlclient/api/APIOptions.java

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
package io.github.axolotlclient.api;
2424

2525
import java.nio.file.Path;
26+
import java.util.concurrent.CompletableFuture;
2627
import java.util.function.Consumer;
2728

2829
import io.github.axolotlclient.AxolotlClient;
@@ -56,8 +57,11 @@ public void init() {
5657
super.init();
5758
MinecraftClient client = MinecraftClient.getInstance();
5859

59-
openPrivacyNoteScreen = n ->
60-
client.execute(() -> client.openScreen(new PrivacyNoticeScreen(client.currentScreen, n)));
60+
openPrivacyNoteScreen = () -> {
61+
var fut = new CompletableFuture<Boolean>();
62+
client.execute(() -> client.openScreen(new PrivacyNoticeScreen(client.currentScreen, fut)));
63+
return fut;
64+
};
6165
KeyBinding binding = new KeyBinding("api.chats.sidebar.open", GLFW.GLFW_KEY_O, "category.axolotlclient");
6266
KeyBindingHelper.registerKeyBinding(binding);
6367
ClientTickEvents.END_CLIENT_TICK.register(c -> {

1.16_combat-6/src/main/java/io/github/axolotlclient/api/PrivacyNoticeScreen.java

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
package io.github.axolotlclient.api;
2424

2525
import java.net.URI;
26-
import java.util.function.Consumer;
26+
import java.util.concurrent.CompletableFuture;
2727

2828
import io.github.axolotlclient.util.OSUtil;
2929
import net.minecraft.class_5489;
@@ -38,10 +38,10 @@ public class PrivacyNoticeScreen extends Screen {
3838
private static final URI TERMS_URI = URI.create(Constants.TERMS);
3939

4040
private final Screen parent;
41-
private final Consumer<Boolean> accepted;
41+
private final CompletableFuture<Boolean> accepted;
4242
private class_5489 message;
4343

44-
protected PrivacyNoticeScreen(Screen parent, Consumer<Boolean> accepted) {
44+
protected PrivacyNoticeScreen(Screen parent, CompletableFuture<Boolean> accepted) {
4545
super(new TranslatableText("api.privacyNotice"));
4646
this.parent = parent;
4747
this.accepted = accepted;
@@ -74,14 +74,14 @@ private void addButtons(int y) {
7474
new TranslatableText("api.privacyNotice.accept"), buttonWidget -> {
7575
client.openScreen(parent);
7676
APIOptions.getInstance().privacyAccepted.set(Options.PrivacyPolicyState.ACCEPTED);
77-
accepted.accept(true);
77+
accepted.complete(true);
7878
}));
7979
addButton(new ButtonWidget(width / 2 + 55, y, 100, 20,
8080
new TranslatableText("api.privacyNotice.deny"), buttonWidget -> {
8181
client.openScreen(parent);
8282
APIOptions.getInstance().enabled.set(false);
8383
APIOptions.getInstance().privacyAccepted.set(Options.PrivacyPolicyState.DENIED);
84-
accepted.accept(false);
84+
accepted.complete(false);
8585
}));
8686
addButton(new ButtonWidget(width / 2 - 155, y, 100, 20,
8787
new TranslatableText("api.privacyNotice.openPolicy"), buttonWidget -> {

1.20/src/main/java/io/github/axolotlclient/api/APIOptions.java

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
package io.github.axolotlclient.api;
2424

2525
import java.nio.file.Path;
26+
import java.util.concurrent.CompletableFuture;
2627
import java.util.function.Consumer;
2728

2829
import com.mojang.blaze3d.platform.InputUtil;
@@ -55,8 +56,11 @@ public void init() {
5556
super.init();
5657
MinecraftClient client = MinecraftClient.getInstance();
5758

58-
openPrivacyNoteScreen = n ->
59-
client.execute(() -> client.setScreen(new PrivacyNoticeScreen(client.currentScreen, n)));
59+
openPrivacyNoteScreen = () -> {
60+
var fut = new CompletableFuture<Boolean>();
61+
client.execute(() -> client.setScreen(new PrivacyNoticeScreen(client.currentScreen, fut)));
62+
return fut;
63+
};
6064
KeyBinds.getInstance().registerWithSimpleAction(new KeyBind("api.chats.sidebar.open",
6165
InputUtil.KEY_O_CODE, "category.axolotlclient"),
6266
() -> {

1.20/src/main/java/io/github/axolotlclient/api/PrivacyNoticeScreen.java

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
package io.github.axolotlclient.api;
2424

2525
import java.net.URI;
26-
import java.util.function.Consumer;
26+
import java.util.concurrent.CompletableFuture;
2727

2828
import io.github.axolotlclient.util.OSUtil;
2929
import net.minecraft.client.font.MultilineText;
@@ -39,10 +39,10 @@ public class PrivacyNoticeScreen extends Screen {
3939
private static final URI TERMS_URI = URI.create(Constants.TERMS);
4040

4141
private final Screen parent;
42-
private final Consumer<Boolean> accepted;
42+
private final CompletableFuture<Boolean> accepted;
4343
private MultilineText message;
4444

45-
protected PrivacyNoticeScreen(Screen parent, Consumer<Boolean> accepted) {
45+
protected PrivacyNoticeScreen(Screen parent, CompletableFuture<Boolean> accepted) {
4646
super(Text.translatable("api.privacyNotice"));
4747
this.parent = parent;
4848
this.accepted = accepted;
@@ -75,13 +75,13 @@ private void addButtons(int y) {
7575
addDrawableChild(ButtonWidget.builder(Text.translatable("api.privacyNotice.accept"), buttonWidget -> {
7676
client.setScreen(parent);
7777
APIOptions.getInstance().privacyAccepted.set(Options.PrivacyPolicyState.ACCEPTED);
78-
accepted.accept(true);
78+
accepted.complete(true);
7979
}).positionAndSize(width / 2 - 50, y, 100, 20).build());
8080
addDrawableChild(ButtonWidget.builder(Text.translatable("api.privacyNotice.deny"), buttonWidget -> {
8181
client.setScreen(parent);
8282
APIOptions.getInstance().enabled.set(false);
8383
APIOptions.getInstance().privacyAccepted.set(Options.PrivacyPolicyState.DENIED);
84-
accepted.accept(false);
84+
accepted.complete(false);
8585
}).positionAndSize(width / 2 - 50 + 105, y, 100, 20).build());
8686
addDrawableChild(ButtonWidget.builder(Text.translatable("api.privacyNotice.openPolicy"), buttonWidget -> {
8787
OSUtil.getOS().open(TERMS_URI);

1.21.5/src/main/java/io/github/axolotlclient/api/APIOptions.java

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
package io.github.axolotlclient.api;
2424

2525
import java.nio.file.Path;
26+
import java.util.concurrent.CompletableFuture;
2627
import java.util.function.Consumer;
2728

2829
import com.mojang.blaze3d.platform.InputConstants;
@@ -55,7 +56,11 @@ public void init() {
5556
super.init();
5657
Minecraft client = Minecraft.getInstance();
5758

58-
openPrivacyNoteScreen = n -> client.execute(() -> client.setScreen(new PrivacyNoticeScreen(client.screen, n)));
59+
openPrivacyNoteScreen = () -> {
60+
var fut = new CompletableFuture<Boolean>();
61+
client.execute(() -> client.setScreen(new PrivacyNoticeScreen(client.screen, fut)));
62+
return fut;
63+
};
5964
KeyBinds.getInstance().registerWithSimpleAction(
6065
new KeyMapping("api.chats.sidebar.open", InputConstants.KEY_O, "category.axolotlclient"), () -> {
6166
if (API.getInstance().isAuthenticated()) {

1.21.5/src/main/java/io/github/axolotlclient/api/PrivacyNoticeScreen.java

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
package io.github.axolotlclient.api;
2424

2525
import java.net.URI;
26-
import java.util.function.Consumer;
26+
import java.util.concurrent.CompletableFuture;
2727

2828
import io.github.axolotlclient.util.OSUtil;
2929
import net.minecraft.client.gui.GuiGraphics;
@@ -39,10 +39,10 @@ public class PrivacyNoticeScreen extends Screen {
3939
private static final URI TERMS_URI = URI.create(Constants.TERMS);
4040

4141
private final Screen parent;
42-
private final Consumer<Boolean> accepted;
42+
private final CompletableFuture<Boolean> accepted;
4343
private MultiLineLabel message;
4444

45-
protected PrivacyNoticeScreen(Screen parent, Consumer<Boolean> accepted) {
45+
protected PrivacyNoticeScreen(Screen parent, CompletableFuture<Boolean> accepted) {
4646
super(Component.translatable("api.privacyNotice"));
4747
this.parent = parent;
4848
this.accepted = accepted;
@@ -74,13 +74,13 @@ private void addButtons(int y) {
7474
addRenderableWidget(Button.builder(Component.translatable("api.privacyNotice.accept"), buttonWidget -> {
7575
minecraft.setScreen(parent);
7676
APIOptions.getInstance().privacyAccepted.set(Options.PrivacyPolicyState.ACCEPTED);
77-
accepted.accept(true);
77+
accepted.complete(true);
7878
}).bounds(width / 2 - 50, y, 100, 20).build());
7979
addRenderableWidget(Button.builder(Component.translatable("api.privacyNotice.deny"), buttonWidget -> {
8080
minecraft.setScreen(parent);
8181
APIOptions.getInstance().enabled.set(false);
8282
APIOptions.getInstance().privacyAccepted.set(Options.PrivacyPolicyState.DENIED);
83-
accepted.accept(false);
83+
accepted.complete(false);
8484
}).bounds(width / 2 - 50 + 105, y, 100, 20).build());
8585
addRenderableWidget(Button.builder(Component.translatable("api.privacyNotice.openPolicy"), buttonWidget -> {
8686
OSUtil.getOS().open(TERMS_URI);

1.21/src/main/java/io/github/axolotlclient/api/APIOptions.java

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
package io.github.axolotlclient.api;
2424

2525
import java.nio.file.Path;
26+
import java.util.concurrent.CompletableFuture;
2627
import java.util.function.Consumer;
2728
import java.util.function.Function;
2829

@@ -56,8 +57,11 @@ public void init() {
5657
super.init();
5758
MinecraftClient client = MinecraftClient.getInstance();
5859

59-
openPrivacyNoteScreen = n ->
60-
client.execute(() -> client.setScreen(new PrivacyNoticeScreen(client.currentScreen, n)));
60+
openPrivacyNoteScreen = () -> {
61+
var fut = new CompletableFuture<Boolean>();
62+
client.execute(() -> client.setScreen(new PrivacyNoticeScreen(client.currentScreen, fut)));
63+
return fut;
64+
};
6165
KeyBinds.getInstance().registerWithSimpleAction(new KeyBind("api.chats.sidebar.open",
6266
InputUtil.KEY_O_CODE, "category.axolotlclient"),
6367
() -> {

1.21/src/main/java/io/github/axolotlclient/api/PrivacyNoticeScreen.java

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
package io.github.axolotlclient.api;
2424

2525
import java.net.URI;
26-
import java.util.function.Consumer;
26+
import java.util.concurrent.CompletableFuture;
2727

2828
import io.github.axolotlclient.util.OSUtil;
2929
import net.minecraft.client.font.MultilineText;
@@ -39,10 +39,10 @@ public class PrivacyNoticeScreen extends Screen {
3939
private static final URI TERMS_URI = URI.create(Constants.TERMS);
4040

4141
private final Screen parent;
42-
private final Consumer<Boolean> accepted;
42+
private final CompletableFuture<Boolean> accepted;
4343
private MultilineText message;
4444

45-
protected PrivacyNoticeScreen(Screen parent, Consumer<Boolean> accepted) {
45+
protected PrivacyNoticeScreen(Screen parent, CompletableFuture<Boolean> accepted) {
4646
super(Text.translatable("api.privacyNotice"));
4747
this.parent = parent;
4848
this.accepted = accepted;
@@ -75,13 +75,13 @@ private void addButtons(int y) {
7575
addDrawableSelectableElement(ButtonWidget.builder(Text.translatable("api.privacyNotice.accept"), buttonWidget -> {
7676
client.setScreen(parent);
7777
APIOptions.getInstance().privacyAccepted.set(Options.PrivacyPolicyState.ACCEPTED);
78-
accepted.accept(true);
78+
accepted.complete(true);
7979
}).positionAndSize(width / 2 - 50, y, 100, 20).build());
8080
addDrawableSelectableElement(ButtonWidget.builder(Text.translatable("api.privacyNotice.deny"), buttonWidget -> {
8181
client.setScreen(parent);
8282
APIOptions.getInstance().enabled.set(false);
8383
APIOptions.getInstance().privacyAccepted.set(Options.PrivacyPolicyState.DENIED);
84-
accepted.accept(false);
84+
accepted.complete(false);
8585
}).positionAndSize(width / 2 - 50 + 105, y, 100, 20).build());
8686
addDrawableSelectableElement(ButtonWidget.builder(Text.translatable("api.privacyNotice.openPolicy"), buttonWidget -> {
8787
OSUtil.getOS().open(TERMS_URI);

1.21/src/main/resources/fabric.mod.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@
4141
},
4242
"depends": {
4343
"fabricloader": ">=0.15.11",
44-
"minecraft": "1.21.1",
44+
"minecraft": "1.21 1.21.1",
4545
"fabric-api": "*",
4646
"axolotlclientconfig": "*",
4747
"axolotlclient-common": "*"

1.8.9/src/main/java/io/github/axolotlclient/api/APIOptions.java

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
package io.github.axolotlclient.api;
2424

2525
import java.nio.file.Path;
26+
import java.util.concurrent.CompletableFuture;
2627
import java.util.function.Consumer;
2728

2829
import io.github.axolotlclient.AxolotlClient;
@@ -56,8 +57,11 @@ public void init() {
5657
super.init();
5758
Minecraft client = Minecraft.getInstance();
5859

59-
openPrivacyNoteScreen = n ->
60-
client.openScreen(new PrivacyNoticeScreen(client.screen, n));
60+
openPrivacyNoteScreen = () -> {
61+
var fut = new CompletableFuture<Boolean>();
62+
client.submit(() -> client.openScreen(new PrivacyNoticeScreen(client.screen, fut)));
63+
return fut;
64+
};
6165
KeyBinding openSidebar = new KeyBinding("api.chats.sidebar.open", Keyboard.KEY_O, "category.axolotlclient");
6266
KeyBindingEvents.REGISTER_KEYBINDS.register(registry -> registry.register(openSidebar));
6367
MinecraftClientEvents.TICK_END.register(minecraft -> {

0 commit comments

Comments
 (0)