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

Commit f98d899

Browse files
committed
fix screenshot actions only affecting the most recent screenshot
1 parent 4d71714 commit f98d899

File tree

6 files changed

+88
-90
lines changed

6 files changed

+88
-90
lines changed

1.16_combat-6/src/main/java/io/github/axolotlclient/modules/screenshotUtils/ScreenshotUtils.java

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -58,37 +58,37 @@ public class ScreenshotUtils extends AbstractModule {
5858
Map<BooleanSupplier, Action> actions = new LinkedHashMap<>();
5959
actions.put(() -> true, new Action("copyAction", Formatting.AQUA,
6060
"copy_image",
61-
new CustomClickEvent(ScreenshotCopying::copy)));
61+
ScreenshotCopying::copy));
6262

6363
actions.put(() -> true, new Action("deleteAction", Formatting.LIGHT_PURPLE,
6464
"delete_image",
65-
new CustomClickEvent((file) -> {
65+
(file) -> {
6666
try {
6767
Files.delete(file);
6868
io.github.axolotlclient.util.Util.sendChatMessage(
6969
new LiteralText(I18n.translate("screenshot_deleted").replace("<name>", file.getFileName().toString())));
7070
} catch (Exception e) {
7171
AxolotlClient.LOGGER.warn("Couldn't delete Screenshot " + file.getFileName().toString());
7272
}
73-
})));
73+
}));
7474

7575
actions.put(() -> true, new Action("openAction", Formatting.WHITE,
7676
"open_image",
77-
new CustomClickEvent((file) -> Util.getOperatingSystem().open(file.toUri()))));
77+
(file) -> Util.getOperatingSystem().open(file.toUri())));
7878

7979
actions.put(() -> true, new Action("viewInGalleryAction", Formatting.LIGHT_PURPLE, "view_in_gallery",
80-
new CustomClickEvent(file -> {
80+
file -> {
8181
try {
8282
ImageInstance instance = new ImageInstance.LocalImpl(file);
8383
MinecraftClient.getInstance().execute(() -> MinecraftClient.getInstance().openScreen(ImageScreen.create(null, CompletableFuture.completedFuture(instance), true)));
8484
} catch (Exception ignored) {
8585
io.github.axolotlclient.util.Util.sendChatMessage(new TranslatableText("screenshot.gallery.view.error"));
8686
}
87-
})));
87+
}));
8888

8989
actions.put(() -> API.getInstance().isAuthenticated(), new Action("uploadAction", Formatting.AQUA,
9090
"upload_image",
91-
new CustomClickEvent(ImageShare.getInstance()::uploadImage)));
91+
ImageShare.getInstance()::uploadImage));
9292

9393
return actions;
9494
});
@@ -123,7 +123,7 @@ public MutableText onScreenshotTaken(MutableText text, File shot) {
123123
if (!autoExec.get().equals("off")) {
124124
actions.forEach((condition, action) -> {
125125
if (condition.getAsBoolean() && autoExec.get().equals(action.getName())) {
126-
action.clickEvent.setFile(file).doAction();
126+
action.getClickEvent(file).doAction();
127127
}
128128
});
129129
return null;
@@ -149,26 +149,31 @@ public static class Action {
149149
private final String translationKey;
150150
private final Formatting formatting;
151151
private final String hoverTextKey;
152-
private final CustomClickEvent clickEvent;
152+
private final OnActionCall clickEvent;
153153

154154
public Text getText(Path file) {
155155
return new TranslatableText(translationKey).setStyle(Style.EMPTY.withFormatting(formatting)
156-
.withClickEvent(clickEvent.setFile(file)).withHoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT, new TranslatableText(hoverTextKey))));
156+
.withClickEvent(getClickEvent(file)).withHoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT, new TranslatableText(hoverTextKey))));
157157
}
158158

159159
public String getName() {
160160
return translationKey;
161161
}
162+
163+
public CustomClickEvent getClickEvent(Path file) {
164+
return new CustomClickEvent(clickEvent, file);
165+
}
162166
}
163167

164168
public static class CustomClickEvent extends ClickEvent {
165169

166170
private final OnActionCall action;
167-
private Path file;
171+
private final Path file;
168172

169-
public CustomClickEvent(OnActionCall action) {
173+
public CustomClickEvent(OnActionCall action, Path file) {
170174
super(Action.byName(""), "");
171175
this.action = action;
176+
this.file = file;
172177
}
173178

174179
public void doAction() {
@@ -179,10 +184,5 @@ public void doAction() {
179184
+ "Now there's a screenshot ClickEvent without a File attached to it!");
180185
}
181186
}
182-
183-
public CustomClickEvent setFile(Path file) {
184-
this.file = file;
185-
return this;
186-
}
187187
}
188188
}

1.20/src/main/java/io/github/axolotlclient/modules/screenshotUtils/ScreenshotUtils.java

Lines changed: 17 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -58,37 +58,37 @@ public class ScreenshotUtils extends AbstractModule {
5858
Map<BooleanSupplier, Action> actions = new LinkedHashMap<>();
5959
actions.put(() -> true, new Action("copyAction", Formatting.AQUA,
6060
"copy_image",
61-
new CustomClickEvent(ScreenshotCopying::copy)));
61+
ScreenshotCopying::copy));
6262

6363
actions.put(() -> true, new Action("deleteAction", Formatting.LIGHT_PURPLE,
6464
"delete_image",
65-
new CustomClickEvent((file) -> {
65+
(file) -> {
6666
try {
6767
Files.delete(file);
6868
io.github.axolotlclient.util.Util.sendChatMessage(
6969
Text.literal(I18n.translate("screenshot_deleted").replace("<name>", file.getFileName().toString())));
7070
} catch (Exception e) {
7171
AxolotlClient.LOGGER.warn("Couldn't delete Screenshot " + file.getFileName().toString());
7272
}
73-
})));
73+
}));
7474

7575
actions.put(() -> true, new Action("openAction", Formatting.WHITE,
7676
"open_image",
77-
new CustomClickEvent((file) -> Util.getOperatingSystem().open(file.toUri()))));
77+
(file) -> Util.getOperatingSystem().open(file.toUri())));
7878

7979
actions.put(() -> true, new Action("viewInGalleryAction", Formatting.LIGHT_PURPLE, "view_in_gallery",
80-
new CustomClickEvent(file -> {
80+
file -> {
8181
try {
8282
ImageInstance instance = new ImageInstance.LocalImpl(file);
8383
MinecraftClient.getInstance().execute(() -> MinecraftClient.getInstance().setScreen(ImageScreen.create(null, CompletableFuture.completedFuture(instance), true)));
8484
} catch (Exception ignored) {
8585
io.github.axolotlclient.util.Util.sendChatMessage(Text.translatable("screenshot.gallery.view.error"));
8686
}
87-
})));
87+
}));
8888

8989
actions.put(() -> API.getInstance().isAuthenticated(), new Action("uploadAction", Formatting.AQUA,
9090
"upload_image",
91-
new CustomClickEvent(ImageShare.getInstance()::uploadImage)));
91+
ImageShare.getInstance()::uploadImage));
9292

9393
return actions;
9494
});
@@ -123,7 +123,7 @@ public MutableText onScreenshotTaken(MutableText text, File shot) {
123123
if (!autoExec.get().equals("off")) {
124124
actions.forEach((condition, action) -> {
125125
if (condition.getAsBoolean() && autoExec.get().equals(action.getName())) {
126-
action.clickEvent.setFile(file).doAction();
126+
action.getClickEvent(file).doAction();
127127
}
128128
});
129129
return null;
@@ -149,26 +149,31 @@ public static class Action {
149149
private final String translationKey;
150150
private final Formatting formatting;
151151
private final String hoverTextKey;
152-
private final CustomClickEvent clickEvent;
152+
private final OnActionCall clickEvent;
153153

154154
public Text getText(Path file) {
155155
return Text.translatable(translationKey).setStyle(Style.EMPTY.withFormatting(formatting)
156-
.withClickEvent(clickEvent.setFile(file)).withHoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT, Text.translatable(hoverTextKey))));
156+
.withClickEvent(getClickEvent(file)).withHoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT, Text.translatable(hoverTextKey))));
157157
}
158158

159159
public String getName() {
160160
return translationKey;
161161
}
162+
163+
public CustomClickEvent getClickEvent(Path file) {
164+
return new CustomClickEvent(clickEvent, file);
165+
}
162166
}
163167

164168
public static class CustomClickEvent extends ClickEvent {
165169

166170
private final OnActionCall action;
167-
private Path file;
171+
private final Path file;
168172

169-
public CustomClickEvent(OnActionCall action) {
173+
public CustomClickEvent(OnActionCall action, Path file) {
170174
super(Action.OPEN_FILE, "");
171175
this.action = action;
176+
this.file = file;
172177
}
173178

174179
public void doAction() {
@@ -179,11 +184,5 @@ public void doAction() {
179184
+ "Now there's a screenshot ClickEvent without a File attached to it!");
180185
}
181186
}
182-
183-
184-
public CustomClickEvent setFile(Path file) {
185-
this.file = file;
186-
return this;
187-
}
188187
}
189188
}

1.21.4/src/main/java/io/github/axolotlclient/modules/screenshotUtils/ScreenshotUtils.java

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -58,37 +58,37 @@ public class ScreenshotUtils extends AbstractModule {
5858
Map<BooleanSupplier, Action> actions = new LinkedHashMap<>();
5959
actions.put(() -> true, new Action("copyAction", ChatFormatting.AQUA,
6060
"copy_image",
61-
new CustomClickEvent(ScreenshotCopying::copy)));
61+
ScreenshotCopying::copy));
6262

6363
actions.put(() -> true, new Action("deleteAction", ChatFormatting.LIGHT_PURPLE,
6464
"delete_image",
65-
new CustomClickEvent((file) -> {
65+
(file) -> {
6666
try {
6767
Files.delete(file);
6868
io.github.axolotlclient.util.Util.sendChatMessage(
6969
Component.literal(I18n.get("screenshot_deleted").replace("<name>", file.getFileName().toString())));
7070
} catch (Exception e) {
7171
AxolotlClient.LOGGER.warn("Couldn't delete Screenshot " + file.getFileName().toString());
7272
}
73-
})));
73+
}));
7474

7575
actions.put(() -> true, new Action("openAction", ChatFormatting.WHITE,
7676
"open_image",
77-
new CustomClickEvent((file) -> Util.getPlatform().openUri(file.toUri()))));
77+
(file) -> Util.getPlatform().openUri(file.toUri())));
7878

7979
actions.put(() -> true, new Action("viewInGalleryAction", ChatFormatting.LIGHT_PURPLE, "view_in_gallery",
80-
new CustomClickEvent(file -> {
80+
file -> {
8181
try {
8282
ImageInstance instance = new ImageInstance.LocalImpl(file);
8383
Minecraft.getInstance().execute(() -> Minecraft.getInstance().setScreen(ImageScreen.create(null, CompletableFuture.completedFuture(instance), true)));
8484
} catch (Exception ignored) {
8585
io.github.axolotlclient.util.Util.sendChatMessage(Component.translatable("screenshot.gallery.view.error"));
8686
}
87-
})));
87+
}));
8888

8989
actions.put(() -> API.getInstance().isAuthenticated(), new Action("uploadAction", ChatFormatting.AQUA,
9090
"upload_image",
91-
new CustomClickEvent(ImageShare.getInstance()::uploadImage)));
91+
ImageShare.getInstance()::uploadImage));
9292

9393
return actions;
9494
});
@@ -122,7 +122,7 @@ public MutableComponent onScreenshotTaken(MutableComponent text, File shot) {
122122
if (!autoExec.get().equals("off")) {
123123
actions.forEach((condition, action) -> {
124124
if (condition.getAsBoolean() && autoExec.get().equals(action.getName())) {
125-
action.clickEvent.setFile(file).doAction();
125+
action.getClickEvent(file).doAction();
126126
}
127127
});
128128
return null;
@@ -148,26 +148,31 @@ public static class Action {
148148
private final String translationKey;
149149
private final ChatFormatting formatting;
150150
private final String hoverTextKey;
151-
private final CustomClickEvent clickEvent;
151+
private final OnActionCall clickEvent;
152152

153153
public Component getText(Path file) {
154154
return Component.translatable(translationKey).setStyle(Style.EMPTY.withColor(formatting)
155-
.withClickEvent(clickEvent.setFile(file)).withHoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT, Component.translatable(hoverTextKey))));
155+
.withClickEvent(getClickEvent(file)).withHoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT, Component.translatable(hoverTextKey))));
156156
}
157157

158158
public String getName() {
159159
return translationKey;
160160
}
161+
162+
public CustomClickEvent getClickEvent(Path file) {
163+
return new CustomClickEvent(clickEvent, file);
164+
}
161165
}
162166

163167
public static class CustomClickEvent extends ClickEvent {
164168

165169
private final OnActionCall action;
166-
private Path file;
170+
private final Path file;
167171

168-
public CustomClickEvent(OnActionCall action) {
172+
public CustomClickEvent(OnActionCall action, Path file) {
169173
super(Action.OPEN_FILE, "");
170174
this.action = action;
175+
this.file = file;
171176
}
172177

173178
public void doAction() {
@@ -178,10 +183,5 @@ public void doAction() {
178183
+ "Now there's a screenshot ClickEvent without a File attached to it!");
179184
}
180185
}
181-
182-
public CustomClickEvent setFile(Path file) {
183-
this.file = file;
184-
return this;
185-
}
186186
}
187187
}

0 commit comments

Comments
 (0)