From c11f563776e3272aafecbec572e75cb44d8dd3ab Mon Sep 17 00:00:00 2001 From: RappyTV Date: Mon, 18 Dec 2023 01:22:57 +0100 Subject: [PATCH 1/6] Only pass uploader to ApiRequest --- core/src/main/java/com/rappytv/uploader/api/ApiRequest.java | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/core/src/main/java/com/rappytv/uploader/api/ApiRequest.java b/core/src/main/java/com/rappytv/uploader/api/ApiRequest.java index 5e5e598..1e74186 100644 --- a/core/src/main/java/com/rappytv/uploader/api/ApiRequest.java +++ b/core/src/main/java/com/rappytv/uploader/api/ApiRequest.java @@ -1,6 +1,5 @@ package com.rappytv.uploader.api; -import com.rappytv.uploader.UploaderAddon; import java.io.File; import java.net.URI; import java.net.http.HttpClient; @@ -17,8 +16,8 @@ public class ApiRequest { private final Uploader uploader; private final File file; - public ApiRequest(UploaderAddon addon, File file) { - this.uploader = addon.configuration().uploader(); + public ApiRequest(Uploader uploader, File file) { + this.uploader = uploader; this.file = file; } From f14fdfbf58ae61caef3c578c4a0857a1c9bccd67 Mon Sep 17 00:00:00 2001 From: RappyTV Date: Mon, 18 Dec 2023 01:30:19 +0100 Subject: [PATCH 2/6] Rename listeners package --- .../uploader/listener/ScreenshotListener.java | 29 +++++++++ .../listeners/ScreenshotListener.java | 60 ------------------- 2 files changed, 29 insertions(+), 60 deletions(-) create mode 100644 core/src/main/java/com/rappytv/uploader/listener/ScreenshotListener.java delete mode 100644 core/src/main/java/com/rappytv/uploader/listeners/ScreenshotListener.java diff --git a/core/src/main/java/com/rappytv/uploader/listener/ScreenshotListener.java b/core/src/main/java/com/rappytv/uploader/listener/ScreenshotListener.java new file mode 100644 index 0000000..e8ee560 --- /dev/null +++ b/core/src/main/java/com/rappytv/uploader/listener/ScreenshotListener.java @@ -0,0 +1,29 @@ +package com.rappytv.uploader.listener; + +import com.rappytv.uploader.UploaderAddon; +import net.labymod.api.Laby; +import net.labymod.api.client.component.Component; +import net.labymod.api.client.component.event.ClickEvent; +import net.labymod.api.client.component.event.HoverEvent; +import net.labymod.api.client.component.format.NamedTextColor; +import net.labymod.api.client.component.format.Style; +import net.labymod.api.event.Subscribe; +import net.labymod.api.event.client.misc.WriteScreenshotEvent; + +public class ScreenshotListener { + + @Subscribe + public void onScreenshot(WriteScreenshotEvent event) { + Component component = UploaderAddon.prefix.copy().append( + Component.translatable( + "uploader.upload.upload", + Style.empty() + .color(NamedTextColor.AQUA) + .hoverEvent(HoverEvent.showText(Component.translatable("uploader.upload.hover").color(NamedTextColor.GREEN))) + .clickEvent(ClickEvent.runCommand("/supload " + event.getDestination().getName())) + ) + ); + + Laby.references().chatExecutor().displayClientMessage(component); + } +} diff --git a/core/src/main/java/com/rappytv/uploader/listeners/ScreenshotListener.java b/core/src/main/java/com/rappytv/uploader/listeners/ScreenshotListener.java deleted file mode 100644 index f489bbb..0000000 --- a/core/src/main/java/com/rappytv/uploader/listeners/ScreenshotListener.java +++ /dev/null @@ -1,60 +0,0 @@ -package com.rappytv.uploader.listeners; - -import com.rappytv.uploader.UploaderAddon; -import com.rappytv.uploader.api.ApiRequest; -import net.labymod.api.Laby; -import net.labymod.api.client.component.Component; -import net.labymod.api.client.component.event.ClickEvent; -import net.labymod.api.client.component.event.HoverEvent; -import net.labymod.api.client.component.format.NamedTextColor; -import net.labymod.api.client.component.format.Style; -import net.labymod.api.client.component.format.TextDecoration; -import net.labymod.api.event.Subscribe; -import net.labymod.api.event.client.misc.WriteScreenshotEvent; - -public class ScreenshotListener { - - private final UploaderAddon addon; - - public ScreenshotListener(UploaderAddon addon) { - this.addon = addon; - } - - @Subscribe - public void onScreenshot(WriteScreenshotEvent event) { - ApiRequest uploader = new ApiRequest(addon, event.getDestination()); - uploader.sendAsyncRequest().thenAccept((result) -> { - if(uploader.isSuccessful()) { - Component copy = Component.translatable( - "uploader.upload.copy", - Style.builder() - .color(NamedTextColor.AQUA) - .decorate(TextDecoration.BOLD) - .hoverEvent(HoverEvent.showText(Component.translatable("uploader.upload.hover").color(NamedTextColor.AQUA))).build() - .clickEvent(ClickEvent.copyToClipboard(!uploader.getUploadLink().isBlank() ? uploader.getUploadLink() : "")) - ); - Component component = Component.translatable( - "uploader.upload.msg", - !uploader.getUploadLink().isBlank() ? copy : Component.text("") - ).color(NamedTextColor.GRAY); - - Laby.references().chatExecutor().displayClientMessage(UploaderAddon.prefix.copy().append(component)); - } else { - Laby.references().chatExecutor().displayClientMessage( - UploaderAddon.prefix.copy().append(Component.text( - uploader.getError(), - NamedTextColor.RED - )) - ); - } - }).exceptionally((e) -> { - Laby.references().chatExecutor().displayClientMessage( - UploaderAddon.prefix.copy().append(Component.text( - e.getMessage(), - NamedTextColor.RED - )) - ); - return null; - }); - } -} From 04119f651facdcd01fd3fa561b34c8969c35a061 Mon Sep 17 00:00:00 2001 From: RappyTV Date: Mon, 18 Dec 2023 01:32:06 +0100 Subject: [PATCH 3/6] Add command to upload screenshot --- .../uploader/command/UploadCommand.java | 77 +++++++++++++++++++ 1 file changed, 77 insertions(+) create mode 100644 core/src/main/java/com/rappytv/uploader/command/UploadCommand.java diff --git a/core/src/main/java/com/rappytv/uploader/command/UploadCommand.java b/core/src/main/java/com/rappytv/uploader/command/UploadCommand.java new file mode 100644 index 0000000..3af5f4f --- /dev/null +++ b/core/src/main/java/com/rappytv/uploader/command/UploadCommand.java @@ -0,0 +1,77 @@ +package com.rappytv.uploader.command; + +import com.rappytv.uploader.UploaderAddon; +import com.rappytv.uploader.api.ApiRequest; +import com.rappytv.uploader.api.Uploader; +import net.labymod.api.client.chat.command.Command; +import net.labymod.api.client.component.Component; +import net.labymod.api.client.component.event.ClickEvent; +import net.labymod.api.client.component.event.HoverEvent; +import net.labymod.api.client.component.format.NamedTextColor; +import net.labymod.api.client.component.format.Style; +import net.labymod.api.client.component.format.TextDecoration; +import java.io.File; + +public class UploadCommand extends Command { + + private final UploaderAddon addon; + + public UploadCommand(UploaderAddon addon) { + super("supload"); + this.addon = addon; + } + + @Override + public boolean execute(String prefix, String[] args) { + Uploader uploader = addon.configuration().uploader(); + if(uploader.getAuth()[1].isBlank()) { + displayMessage(UploaderAddon.prefix.copy().append(Component.translatable("uploader.upload.noToken", NamedTextColor.RED))); + return true; + } + if(args.length < 1) { + displayMessage(UploaderAddon.prefix.copy().append(Component.translatable("uploader.upload.file", NamedTextColor.RED))); + return true; + } + File file = new File(System.getProperty("user.dir") + "/screenshots/" + args[0]); + if(!file.exists()) { + displayMessage(UploaderAddon.prefix.copy().append(Component.translatable("uploader.upload.file", NamedTextColor.RED))); + return true; + } + displayMessage(UploaderAddon.prefix.copy().append(Component.translatable("uploader.upload.uploading", NamedTextColor.GRAY))); + ApiRequest request = new ApiRequest(uploader, file); + request.sendAsyncRequest().thenAccept((result) -> { + if(request.isSuccessful()) { + Component copy = Component.translatable( + "uploader.upload.copy", + Style.empty() + .color(NamedTextColor.AQUA) + .decorate(TextDecoration.BOLD) + .hoverEvent(HoverEvent.showText(Component.translatable("uploader.upload.hover").color(NamedTextColor.GREEN))) + .clickEvent(ClickEvent.copyToClipboard(!request.getUploadLink().isBlank() ? request.getUploadLink() : "")) + ); + Component component = Component.translatable( + "uploader.upload.uploaded", + !request.getUploadLink().isBlank() ? copy : Component.text("") + ).color(NamedTextColor.GRAY); + + displayMessage(UploaderAddon.prefix.copy().append(component)); + } else { + displayMessage( + UploaderAddon.prefix.copy().append(Component.text( + request.getError(), + NamedTextColor.RED + )) + ); + } + }).exceptionally((e) -> { + displayMessage( + UploaderAddon.prefix.copy().append(Component.text( + e.getMessage(), + NamedTextColor.RED + )) + ); + return null; + }); + return true; + } +} From 033a4b027a88aeff14876197a1142fd070fafe44 Mon Sep 17 00:00:00 2001 From: RappyTV Date: Mon, 18 Dec 2023 01:32:28 +0100 Subject: [PATCH 4/6] Register command --- core/src/main/java/com/rappytv/uploader/UploaderAddon.java | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/core/src/main/java/com/rappytv/uploader/UploaderAddon.java b/core/src/main/java/com/rappytv/uploader/UploaderAddon.java index 2c60eda..f4ed5c3 100644 --- a/core/src/main/java/com/rappytv/uploader/UploaderAddon.java +++ b/core/src/main/java/com/rappytv/uploader/UploaderAddon.java @@ -4,8 +4,9 @@ import com.rappytv.uploader.api.uploaders.ImgurUploader; import com.rappytv.uploader.api.uploaders.XBackBoneUploader; import com.rappytv.uploader.api.uploaders.ZiplineUploader; +import com.rappytv.uploader.command.UploadCommand; import com.rappytv.uploader.config.UploaderConfig; -import com.rappytv.uploader.listeners.ScreenshotListener; +import com.rappytv.uploader.listener.ScreenshotListener; import net.labymod.api.addon.LabyAddon; import net.labymod.api.client.component.Component; import net.labymod.api.client.component.format.NamedTextColor; @@ -23,7 +24,8 @@ public class UploaderAddon extends LabyAddon { @Override protected void enable() { registerSettingCategory(); - registerListener(new ScreenshotListener(this)); + registerCommand(new UploadCommand(this)); + registerListener(new ScreenshotListener()); loadUploaders(); } From fd6688f0129efa856af10df961244154870b7b65 Mon Sep 17 00:00:00 2001 From: RappyTV Date: Mon, 18 Dec 2023 01:32:37 +0100 Subject: [PATCH 5/6] Add new translations --- core/src/main/resources/assets/uploader/i18n/en_us.json | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/core/src/main/resources/assets/uploader/i18n/en_us.json b/core/src/main/resources/assets/uploader/i18n/en_us.json index 7d1cc99..1a5389e 100644 --- a/core/src/main/resources/assets/uploader/i18n/en_us.json +++ b/core/src/main/resources/assets/uploader/i18n/en_us.json @@ -50,7 +50,11 @@ } }, "upload": { - "msg": "Screenshot uploaded! %s", + "noToken": "Please provide the API Key for your uploader in the addon config.", + "file": "File not found!", + "upload": "Click here to upload the screenshot!", + "uploading": "Uploading screenshot...", + "uploaded": "Screenshot uploaded! %s", "hover": "Clickable", "copy": "[COPY URL]", "emptyError": "Empty error!", From 69aa036febd0f503d3d1b487cddace2c40f41393 Mon Sep 17 00:00:00 2001 From: RappyTV Date: Mon, 18 Dec 2023 01:34:00 +0100 Subject: [PATCH 6/6] Bump version --- build.gradle.kts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/build.gradle.kts b/build.gradle.kts index 3bbdb6c..1265ee7 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -17,7 +17,7 @@ labyMod { author = "RappyTV" description = "Upload your minecraft screenshots to your custom destinations." minecraftVersion = "*" - version = System.getenv().getOrDefault("VERSION", "1.0.0") + version = System.getenv().getOrDefault("VERSION", "1.0.1") } minecraft {