Skip to content
This repository has been archived by the owner on Mar 15, 2024. It is now read-only.

Commit

Permalink
Merge pull request #102 from rettichlp/bug/UCAB-92-Automatic-screensh…
Browse files Browse the repository at this point in the history
…ot-+-upload-in-chat

bug/UCAB-92-Automatic-screenshot-+-upload-in-chat
  • Loading branch information
rettichlp authored Aug 4, 2022
2 parents a11a7fb + 282a6a6 commit ed87275
Showing 1 changed file with 8 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -13,18 +13,22 @@
import net.minecraftforge.client.event.GuiScreenEvent;
import net.minecraftforge.fml.common.eventhandler.SubscribeEvent;
import net.minecraftforge.fml.common.gameevent.InputEvent;
import org.lwjgl.input.Keyboard;

import javax.imageio.ImageIO;
import java.awt.image.BufferedImage;
import java.io.File;
import java.io.IOException;
import java.util.concurrent.TimeUnit;

/**
* @author RettichLP
* @see <a href="https://github.com/paulzhng/UCUtils/blob/master/src/main/java/de/fuzzlemann/ucutils/events/AlternateScreenshotEventHandler.java">UCUtils by paulzhng</a>
*/
public class ScreenshotEventHandler {

private static long lastScreenshot;

@SubscribeEvent
public void onKeyInput(InputEvent.KeyInputEvent e) {
handleScreenshot();
Expand All @@ -36,7 +40,8 @@ public void onKeyboardInput(GuiScreenEvent.KeyboardInputEvent e) {
}

private void handleScreenshot() {
if (!KeyBindRegistry.addonScreenshot.isPressed()) return;
if (!Keyboard.isKeyDown(KeyBindRegistry.addonScreenshot.getKeyCode())) return;
if (System.currentTimeMillis() - lastScreenshot < TimeUnit.SECONDS.toMillis(1)) return;

try {
File newImageFile = FileManager.getNewImageFile();
Expand All @@ -57,6 +62,8 @@ private void handleScreenshot() {
} catch (IOException e) {
throw new RuntimeException(e);
}

lastScreenshot = System.currentTimeMillis();
}

private void uploadScreenshot(File screenshotFile) {
Expand Down

0 comments on commit ed87275

Please sign in to comment.