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

Commit 8750ad3

Browse files
committed
clean up
1 parent 1b76dfe commit 8750ad3

File tree

36 files changed

+139
-471
lines changed

36 files changed

+139
-471
lines changed

1.16_combat-6/src/main/java/io/github/axolotlclient/modules/hud/HudManager.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -158,8 +158,8 @@ private void loadCustomEntries() {
158158
entry.onBoundsUpdate();
159159
});
160160
}
161-
} catch (IOException e) {
162-
//TODO notify
161+
} catch (Exception e) {
162+
AxolotlClient.LOGGER.warn("Failed to load custom hud modules!", e);
163163
}
164164
}
165165

@@ -183,7 +183,7 @@ public void saveCustomEntries() {
183183
json.endArray();
184184
json.close();
185185
} catch (IOException e) {
186-
//TODO notify
186+
AxolotlClient.LOGGER.warn("Failed to save custom hud modules!", e);
187187
}
188188
}
189189

@@ -245,7 +245,7 @@ public Optional<HudEntry> getEntryXY(int x, int y) {
245245
}
246246

247247
public List<HudEntry> getMoveableEntries() {
248-
if (entries.size() > 0) {
248+
if (!entries.isEmpty()) {
249249
return entries.values().stream().filter((entry) -> entry.isEnabled() && entry.movable())
250250
.collect(Collectors.toList());
251251
}

1.16_combat-6/src/main/java/io/github/axolotlclient/modules/hud/gui/hud/KeystrokeHud.java

Lines changed: 15 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ public class KeystrokeHud extends TextHudEntry {
7171
private final ColorOption pressedBackgroundColor = new ColorOption("heldbackgroundcolor", new Color(0x64FFFFFF));
7272
private final ColorOption pressedOutlineColor = new ColorOption("heldoutlinecolor", ClientColors.BLACK);
7373

74-
private final KeystrokesGenericOption keystrokesOption = new KeystrokesGenericOption("keystrokes", "keystrokes.configure");
74+
private final GenericOption keystrokesOption = new GenericOption("keystrokes", "keystrokes.configure", () -> client.openScreen(new KeystrokesScreen(KeystrokeHud.this, client.currentScreen)));
7575
private final GenericOption configurePositions = new GenericOption("keystrokes.positions", "keystrokes.positions.configure",
7676
() -> client.openScreen(new KeystrokePositioningScreen(client.currentScreen, this)));
7777
public ArrayList<Keystroke> keystrokes;
@@ -128,7 +128,7 @@ public void setKeystrokes() {
128128
}
129129
keystrokes = new ArrayList<>();
130130
setDefaultKeystrokes();
131-
keystrokesOption.load();
131+
loadKeystrokes();
132132
KeyBinding.unpressAll();
133133
KeyBinding.updatePressedStates();
134134
}
@@ -450,40 +450,28 @@ public boolean isLabelEditable() {
450450
}
451451
}
452452

453-
public class KeystrokesGenericOption extends GenericOption {
454-
455-
public KeystrokesGenericOption(String name, String label) {
456-
super(name, label, () -> client.submit(() -> client.openScreen(new KeystrokesScreen(KeystrokeHud.this, client.currentScreen))));
457-
}
458-
459-
@Override
460-
public String toSerializedValue() {
461-
try {
462-
Files.writeString(KEYSTROKE_SAVE_FILE, GsonHelper.GSON.toJson(keystrokes.stream().map(Keystroke::serialize).toList()));
463-
} catch (Exception e) {
464-
// TODO failed to save keystrokes.
465-
}
466-
return null;
453+
public void saveKeystrokes() {
454+
try {
455+
Files.createDirectories(KEYSTROKE_SAVE_FILE.getParent());
456+
Files.writeString(KEYSTROKE_SAVE_FILE, GsonHelper.GSON.toJson(keystrokes.stream().map(Keystroke::serialize).toList()));
457+
} catch (Exception e) {
458+
AxolotlClient.LOGGER.warn("Failed to save keystroke configuration!", e);
467459
}
460+
}
468461

469-
@SuppressWarnings("unchecked")
470-
public void load() {
471-
try {
462+
@SuppressWarnings("unchecked")
463+
public void loadKeystrokes() {
464+
try {
465+
if (Files.exists(KEYSTROKE_SAVE_FILE)) {
472466
List<?> entries = (List<?>) GsonHelper.read(Files.readString(KEYSTROKE_SAVE_FILE));
473467
var loaded = entries.stream().map(e -> (Map<String, Object>) e)
474468
.map(KeystrokeHud.this::deserializeKey)
475469
.toList();
476470
keystrokes.clear();
477471
keystrokes.addAll(loaded);
478-
} catch (Exception e) {
479-
// TODO failed to load keystrokes, defaults are used.
480-
e.printStackTrace();
481472
}
482-
}
483-
484-
@Override
485-
public String getWidgetIdentifier() {
486-
return "generic-keystrokes";
473+
} catch (Exception e) {
474+
AxolotlClient.LOGGER.warn("Failed to load keystroke configuration, using defaults!", e);
487475
}
488476
}
489477

1.16_combat-6/src/main/java/io/github/axolotlclient/modules/hud/gui/keystrokes/ConfigureKeyBindScreen.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
package io.github.axolotlclient.modules.hud.gui.keystrokes;
22

3-
import io.github.axolotlclient.AxolotlClientCommon;
43
import io.github.axolotlclient.AxolotlClientConfig.api.util.Colors;
54
import io.github.axolotlclient.AxolotlClientConfig.impl.options.IntegerOption;
65
import io.github.axolotlclient.AxolotlClientConfig.impl.ui.vanilla.widgets.IntegerWidget;
@@ -146,7 +145,7 @@ public void render(MatrixStack graphics, int mouseX, int mouseY, float delta) {
146145
@Override
147146
public void onClose() {
148147
client.openScreen(parent);
149-
AxolotlClientCommon.getInstance().saveConfig();
148+
hud.saveKeystrokes();
150149
}
151150

152151
private static AbstractButtonWidget textWidget(int x, int y, int width, int height, Text text, TextRenderer renderer) {

1.16_combat-6/src/main/java/io/github/axolotlclient/modules/hud/gui/keystrokes/KeystrokePositioningScreen.java

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
import java.util.stream.Stream;
66

77
import io.github.axolotlclient.AxolotlClient;
8-
import io.github.axolotlclient.AxolotlClientCommon;
98
import io.github.axolotlclient.AxolotlClientConfig.api.util.Colors;
109
import io.github.axolotlclient.modules.hud.HudEditScreen;
1110
import io.github.axolotlclient.modules.hud.HudManager;
@@ -130,13 +129,13 @@ public boolean mouseClicked(double mouseX, double mouseY, int button) {
130129
@Override
131130
public void onClose() {
132131
client.openScreen(parent);
133-
AxolotlClientCommon.getInstance().saveConfig();
132+
hud.saveKeystrokes();
134133
}
135134

136135
@Override
137136
public boolean mouseReleased(double mouseX, double mouseY, int button) {
138137
if (focused != null) {
139-
AxolotlClientCommon.getInstance().saveConfig();
138+
hud.saveKeystrokes();
140139
}
141140
snap = null;
142141
mouseDown = false;

1.16_combat-6/src/main/java/io/github/axolotlclient/modules/hud/gui/keystrokes/KeystrokesScreen.java

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22

33
import java.util.List;
44

5-
import io.github.axolotlclient.AxolotlClientCommon;
65
import io.github.axolotlclient.modules.hud.gui.hud.KeystrokeHud;
76
import net.minecraft.client.gui.screen.Screen;
87
import net.minecraft.client.gui.screen.ScreenTexts;
@@ -39,7 +38,7 @@ public void init() {
3938
keys.clear();
4039
hud.setDefaultKeystrokes();
4140
keyBindsList.reload(keys);
42-
AxolotlClientCommon.getInstance().saveConfig();
41+
hud.saveKeystrokes();
4342
}));
4443
addDrawableChild(new ButtonWidget(width / 2 + 4, height - 33 / 2 - 10, 150, 20, ScreenTexts.DONE, button -> this.onClose()));
4544

@@ -48,7 +47,7 @@ public void init() {
4847
@Override
4948
public void onClose() {
5049
this.client.openScreen(this.screen);
51-
AxolotlClientCommon.getInstance().saveConfig();
50+
hud.saveKeystrokes();
5251
}
5352

5453
public void removeKey(KeystrokeHud.Keystroke key) {

1.16_combat-6/src/main/java/io/github/axolotlclient/util/options/rounded/KeystrokesGenericWidget.java

Lines changed: 0 additions & 31 deletions
This file was deleted.

1.16_combat-6/src/main/java/io/github/axolotlclient/util/options/vanilla/KeystrokesGenericWidget.java

Lines changed: 0 additions & 31 deletions
This file was deleted.

1.20/src/main/java/io/github/axolotlclient/modules/hud/HudManager.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -153,7 +153,7 @@ private void loadCustomEntries() {
153153
});
154154
}
155155
} catch (IOException e) {
156-
//TODO notify
156+
AxolotlClient.LOGGER.warn("Failed to load custom hud modules!", e);
157157
}
158158
}
159159

@@ -177,7 +177,7 @@ public void saveCustomEntries() {
177177
json.endArray();
178178
json.close();
179179
} catch (IOException e) {
180-
//TODO notify
180+
AxolotlClient.LOGGER.warn("Failed to save custom hud modules!", e);
181181
}
182182
}
183183

@@ -239,7 +239,7 @@ public Optional<HudEntry> getEntryXY(int x, int y) {
239239
}
240240

241241
public List<HudEntry> getMoveableEntries() {
242-
if (entries.size() > 0) {
242+
if (!entries.isEmpty()) {
243243
return entries.values().stream().filter((entry) -> entry.isEnabled() && entry.movable())
244244
.collect(Collectors.toList());
245245
}

1.20/src/main/java/io/github/axolotlclient/modules/hud/gui/hud/KeystrokeHud.java

Lines changed: 19 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ public class KeystrokeHud extends TextHudEntry {
7171
private final ColorOption pressedBackgroundColor = new ColorOption("heldbackgroundcolor", new Color(0x64FFFFFF));
7272
private final ColorOption pressedOutlineColor = new ColorOption("heldoutlinecolor", ClientColors.BLACK);
7373

74-
private final KeystrokesGenericOption keystrokesOption = new KeystrokesGenericOption("keystrokes", "keystrokes.configure");
74+
private final GenericOption keystrokesOption = new GenericOption("keystrokes", "keystrokes.configure", () -> client.setScreen(new KeystrokesScreen(KeystrokeHud.this, client.currentScreen)));
7575
private final GenericOption configurePositions = new GenericOption("keystrokes.positions", "keystrokes.positions.configure",
7676
() -> client.setScreen(new KeystrokePositioningScreen(client.currentScreen, this)));
7777
public ArrayList<Keystroke> keystrokes;
@@ -128,7 +128,7 @@ public void setKeystrokes() {
128128
}
129129
keystrokes = new ArrayList<>();
130130
setDefaultKeystrokes();
131-
keystrokesOption.load();
131+
loadKeystrokes();
132132
KeyBind.resetAll();
133133
KeyBind.updatePressedStates();
134134
}
@@ -450,40 +450,25 @@ public boolean isLabelEditable() {
450450
}
451451
}
452452

453-
public class KeystrokesGenericOption extends GenericOption {
454-
455-
public KeystrokesGenericOption(String name, String label) {
456-
super(name, label, () -> client.submit(() -> client.setScreen(new KeystrokesScreen(KeystrokeHud.this, client.currentScreen))));
457-
}
458-
459-
@Override
460-
public String toSerializedValue() {
461-
try {
462-
Files.writeString(KEYSTROKE_SAVE_FILE, GsonHelper.GSON.toJson(keystrokes.stream().map(Keystroke::serialize).toList()));
463-
} catch (Exception e) {
464-
// TODO failed to save keystrokes.
465-
}
466-
return null;
467-
}
468-
469-
@SuppressWarnings("unchecked")
470-
public void load() {
471-
try {
472-
List<?> entries = (List<?>) GsonHelper.read(Files.readString(KEYSTROKE_SAVE_FILE));
473-
var loaded = entries.stream().map(e -> (Map<String, Object>) e)
474-
.map(KeystrokeHud.this::deserializeKey)
475-
.toList();
476-
keystrokes.clear();
477-
keystrokes.addAll(loaded);
478-
} catch (Exception e) {
479-
// TODO failed to load keystrokes, defaults are used.
480-
e.printStackTrace();
481-
}
453+
public void saveKeystrokes() {
454+
try {
455+
Files.writeString(KEYSTROKE_SAVE_FILE, GsonHelper.GSON.toJson(keystrokes.stream().map(Keystroke::serialize).toList()));
456+
} catch (Exception e) {
457+
AxolotlClient.LOGGER.warn("Failed to save keystroke configuration!", e);
482458
}
459+
}
483460

484-
@Override
485-
public String getWidgetIdentifier() {
486-
return "generic-keystrokes";
461+
@SuppressWarnings("unchecked")
462+
public void loadKeystrokes() {
463+
try {
464+
List<?> entries = (List<?>) GsonHelper.read(Files.readString(KEYSTROKE_SAVE_FILE));
465+
var loaded = entries.stream().map(e -> (Map<String, Object>) e)
466+
.map(KeystrokeHud.this::deserializeKey)
467+
.toList();
468+
keystrokes.clear();
469+
keystrokes.addAll(loaded);
470+
} catch (Exception e) {
471+
AxolotlClient.LOGGER.warn("Failed to load keystroke configuration, using defaults!", e);
487472
}
488473
}
489474

1.20/src/main/java/io/github/axolotlclient/modules/hud/gui/keystrokes/ConfigureKeyBindScreen.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
package io.github.axolotlclient.modules.hud.gui.keystrokes;
22

3-
import io.github.axolotlclient.AxolotlClientCommon;
43
import io.github.axolotlclient.AxolotlClientConfig.api.util.Colors;
54
import io.github.axolotlclient.AxolotlClientConfig.impl.options.IntegerOption;
65
import io.github.axolotlclient.AxolotlClientConfig.impl.ui.vanilla.widgets.IntegerWidget;
@@ -145,6 +144,6 @@ public void render(GuiGraphics graphics, int mouseX, int mouseY, float delta) {
145144
@Override
146145
public void closeScreen() {
147146
client.setScreen(parent);
148-
AxolotlClientCommon.getInstance().saveConfig();
147+
hud.saveKeystrokes();
149148
}
150149
}

0 commit comments

Comments
 (0)