-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathScreenshotRunnable.java
More file actions
61 lines (53 loc) · 2.37 KB
/
ScreenshotRunnable.java
File metadata and controls
61 lines (53 loc) · 2.37 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
import java.awt.Toolkit;
import java.awt.datatransfer.Clipboard;
import java.awt.datatransfer.StringSelection;
import java.awt.image.BufferedImage;
import net.minecraft.client.Minecraft;
import net.minecraft.event.ClickEvent;
import net.minecraft.util.ChatComponentStyle;
import net.minecraft.util.ChatComponentText;
import net.minecraft.util.EnumChatFormatting;
import net.minecraft.util.IChatComponent;
public class ScreenshotRunnable implements Runnable
{
private String host;
private BufferedImage screenshot;
private boolean processing;
public ScreenshotRunnable( final String host, final BufferedImage screenshot) {
this.screenshot = screenshot;
this.host = host;
}
public boolean isProcessing() {
return this.processing;
}
public BufferedImage get() {
return this.processing ? null : this.screenshot;
}
@Override
public void run() {
this.processing = true;
// ScreenshotHandler.saveScreenshot(this.screenshot);
if (this.host.equals("imgur")) {
try {
final ImageHost imageHost = ImageHost.imageHosts.get("imgur");
imageHost.upload(this.screenshot,ImageHost.UPLOAD_METHOD.ANON, new String[0]);
final String link = imageHost.getLink();
final ChatComponentText linkChat = new ChatComponentText(EnumChatFormatting.GREEN + "Uploaded screenshot at " + EnumChatFormatting.WHITE.toString() + EnumChatFormatting.UNDERLINE + link);
linkChat.getChatStyle().setChatClickEvent(new ClickEvent(ClickEvent.Action.OPEN_URL, link));
Minecraft.getMinecraft().thePlayer.addChatMessage((IChatComponent)linkChat);
addToClipboard(link);
if (imageHost.upload(this.screenshot, ImageHost.UPLOAD_METHOD.ANON, new String[0])) {
// ScreenshotVisual.instance.setUploadStatus(ScreenshotVisual.Status.UPLOAD_SUCCESS);
}
}
catch (Exception e) {
}
}
this.processing = false;
}
public static void addToClipboard(final String string) {
final StringSelection selection = new StringSelection(string);
final Clipboard clipboard = Toolkit.getDefaultToolkit().getSystemClipboard();
clipboard.setContents(selection, selection);
}
}