generated from LabyMod/addon-template
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1 from RappyLabyAddons/feat/uploadConfirmation
Add upload confirmation
- Loading branch information
Showing
7 changed files
with
118 additions
and
67 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
77 changes: 77 additions & 0 deletions
77
core/src/main/java/com/rappytv/uploader/command/UploadCommand.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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; | ||
} | ||
} |
29 changes: 29 additions & 0 deletions
29
core/src/main/java/com/rappytv/uploader/listener/ScreenshotListener.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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); | ||
} | ||
} |
60 changes: 0 additions & 60 deletions
60
core/src/main/java/com/rappytv/uploader/listeners/ScreenshotListener.java
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters