Add ability to automatically screenshot friend and cc deaths (#408)

* Shift always anti-drag when toggled off

* Use better vanguards plugin

* Add ability to automatically screenshot friend and cc deaths

* Fixed Checkstyle

* Revert "Shift always anti-drag when toggled off"

This reverts commit ba40d3a0583a43369eb03925739431dd3ced5dd2.

* Added back shitty vangs cause wrong branch

* fixed checkstyle for a vanguards plugin as you would when editing the screenshot plugin
This commit is contained in:
farhan1666
2019-05-27 10:20:24 +01:00
committed by Kyleeld
parent 2d997068dc
commit 967643309e
4 changed files with 341 additions and 234 deletions

View File

@@ -144,21 +144,31 @@ public interface ScreenshotConfig extends Config
} }
@ConfigItem( @ConfigItem(
keyName = "playerDeath", keyName = "friendDeath",
name = "Screenshot Deaths", name = "Friend Deaths",
description = "Configures whether or not screenshots are automatically taken when you die.", description = "Configures whether or not screenshots are automatically taken when a clanmate or a friend near you dies.",
position = 10 position = 10
) )
default boolean screenshotPlayerDeath() default boolean screenshotFriendDeath()
{ {
return false; return false;
} }
@ConfigItem(
keyName = "playerDeath",
name = "Screenshot Deaths",
description = "Configures whether or not screenshots are automatically taken when you die.",
position = 11
)
default boolean screenshotPlayerDeath()
{
return false;
}
@ConfigItem( @ConfigItem(
keyName = "duels", keyName = "duels",
name = "Screenshot Duels", name = "Screenshot Duels",
description = "Configures whether or not screenshots are automatically taken of the duel end screen.", description = "Configures whether or not screenshots are automatically taken of the duel end screen.",
position = 11 position = 12
) )
default boolean screenshotDuels() default boolean screenshotDuels()
{ {
@@ -169,7 +179,7 @@ public interface ScreenshotConfig extends Config
keyName = "valuableDrop", keyName = "valuableDrop",
name = "Screenshot Valuable drops", name = "Screenshot Valuable drops",
description = "Configures whether or not screenshots are automatically taken when you receive a valuable drop.", description = "Configures whether or not screenshots are automatically taken when you receive a valuable drop.",
position = 12 position = 13
) )
default boolean screenshotValuableDrop() default boolean screenshotValuableDrop()
{ {
@@ -180,7 +190,7 @@ public interface ScreenshotConfig extends Config
keyName = "untradeableDrop", keyName = "untradeableDrop",
name = "Screenshot Untradeable drops", name = "Screenshot Untradeable drops",
description = "Configures whether or not screenshots are automatically taken when you receive an untradeable drop.", description = "Configures whether or not screenshots are automatically taken when you receive an untradeable drop.",
position = 13 position = 14
) )
default boolean screenshotUntradeableDrop() default boolean screenshotUntradeableDrop()
{ {
@@ -191,7 +201,7 @@ public interface ScreenshotConfig extends Config
keyName = "hotkey", keyName = "hotkey",
name = "Screenshot hotkey", name = "Screenshot hotkey",
description = "When you press this key a screenshot will be taken", description = "When you press this key a screenshot will be taken",
position = 14 position = 15
) )
default Keybind hotkey() default Keybind hotkey()
{ {

View File

@@ -1,5 +1,6 @@
/* /*
* Copyright (c) 2018, Lotto <https://github.com/devLotto> * Copyright (c) 2018, Lotto <https://github.com/devLotto>
* Modified by Jason <https://github.com/JasonT20015>
* All rights reserved. * All rights reserved.
* *
* Redistribution and use in source and binary forms, with or without * Redistribution and use in source and binary forms, with or without
@@ -46,6 +47,9 @@ import java.text.SimpleDateFormat;
import java.time.LocalDate; import java.time.LocalDate;
import java.util.Date; import java.util.Date;
import java.util.EnumSet; import java.util.EnumSet;
import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;
import java.util.concurrent.ScheduledExecutorService; import java.util.concurrent.ScheduledExecutorService;
import java.util.function.Consumer; import java.util.function.Consumer;
import java.util.regex.Matcher; import java.util.regex.Matcher;
@@ -53,6 +57,7 @@ import java.util.regex.Pattern;
import javax.imageio.ImageIO; import javax.imageio.ImageIO;
import javax.inject.Inject; import javax.inject.Inject;
import javax.swing.SwingUtilities; import javax.swing.SwingUtilities;
import lombok.AccessLevel; import lombok.AccessLevel;
import lombok.Getter; import lombok.Getter;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
@@ -62,11 +67,12 @@ import net.runelite.api.GameState;
import net.runelite.api.Player; import net.runelite.api.Player;
import net.runelite.api.Point; import net.runelite.api.Point;
import net.runelite.api.SpriteID; import net.runelite.api.SpriteID;
import net.runelite.api.Varbits;
import net.runelite.api.WorldType; import net.runelite.api.WorldType;
import net.runelite.api.events.AnimationChanged;
import net.runelite.api.events.ChatMessage; import net.runelite.api.events.ChatMessage;
import net.runelite.api.events.GameStateChanged; import net.runelite.api.events.GameStateChanged;
import net.runelite.api.events.GameTick; import net.runelite.api.events.GameTick;
import net.runelite.api.events.LocalPlayerDeath;
import net.runelite.api.events.WidgetLoaded; import net.runelite.api.events.WidgetLoaded;
import net.runelite.api.widgets.Widget; import net.runelite.api.widgets.Widget;
import static net.runelite.api.widgets.WidgetID.BARROWS_REWARD_GROUP_ID; import static net.runelite.api.widgets.WidgetID.BARROWS_REWARD_GROUP_ID;
@@ -105,6 +111,7 @@ import okhttp3.MediaType;
import okhttp3.Request; import okhttp3.Request;
import okhttp3.RequestBody; import okhttp3.RequestBody;
import okhttp3.Response; import okhttp3.Response;
import org.jetbrains.annotations.Nullable;
@PluginDescriptor( @PluginDescriptor(
name = "Screenshot", name = "Screenshot",
@@ -187,6 +194,8 @@ public class ScreenshotPlugin extends Plugin
@Getter(AccessLevel.PACKAGE) @Getter(AccessLevel.PACKAGE)
private BufferedImage reportButton; private BufferedImage reportButton;
private Map<Player, Integer> dying = new HashMap<Player, Integer>();
private NavigationButton titleBarButton; private NavigationButton titleBarButton;
private final HotkeyListener hotkeyListener = new HotkeyListener(() -> config.hotkey()) private final HotkeyListener hotkeyListener = new HotkeyListener(() -> config.hotkey())
@@ -258,6 +267,23 @@ public class ScreenshotPlugin extends Plugin
@Subscribe @Subscribe
public void onGameTick(GameTick event) public void onGameTick(GameTick event)
{ {
if (config.screenshotFriendDeath())
{
for (Iterator<Player> it = dying.keySet().iterator(); it.hasNext();)
{
Player key = it.next();
if (key.getAnimation() != 836)
{
it.remove();
}
dying.replace(key, dying.get(key) - 1);
if (dying.get(key) == 0)
{
takeScreenshot(key.getName() + " ded " + format(new Date()), "Deaths");
it.remove();
}
}
}
if (!shouldTakeScreenshot) if (!shouldTakeScreenshot)
{ {
return; return;
@@ -288,11 +314,43 @@ public class ScreenshotPlugin extends Plugin
} }
@Subscribe @Subscribe
public void onLocalPlayerDeath(LocalPlayerDeath death) public void onAnimationChanged(AnimationChanged e)
{ {
//this got refactored somewhere, but some things were missing
if (!config.screenshotFriendDeath() || !config.screenshotPlayerDeath())
return;
if (!(e.getActor() instanceof Player))
return;
Player p = (Player) e.getActor();
if (p.getAnimation() != 836)
{
return;
}
if (p.getName().equals(client.getLocalPlayer().getName()))
{
if (config.screenshotPlayerDeath()) if (config.screenshotPlayerDeath())
{ {
takeScreenshot("Death " + format(new Date())); dying.put(p, 3);
return;
}
else
{
return;
}
}
if (config.screenshotFriendDeath())
{
int tob = client.getVar(Varbits.THEATRE_OF_BLOOD);
if (client.getVar(Varbits.IN_RAID) == 1 || tob == 2 || tob == 3 || p.isFriend())
{
//this is the same as the tick counter had, just want to make ss at right timing
dying.put(p, 3);
}
} }
} }
@@ -576,7 +634,7 @@ public class ScreenshotPlugin extends Plugin
Consumer<Image> imageCallback = (img) -> Consumer<Image> imageCallback = (img) ->
{ {
// This callback is on the game thread, move to executor thread // This callback is on the game thread, move to executor thread
executor.submit(() -> takeScreenshot(fileName, img)); executor.submit(() -> takeScreenshot(fileName, img, null));
}; };
if (config.displayDate()) if (config.displayDate())
@@ -589,7 +647,39 @@ public class ScreenshotPlugin extends Plugin
} }
} }
private void takeScreenshot(String fileName, Image image) /**
* Saves a screenshot of the client window to the screenshot folder as a PNG,
* and optionally uploads it to an image-hosting service.
*
* @param fileName Filename to use, without file extension.
* @param subdirectory The subdirectory to save it in
*/
private void takeScreenshot(String fileName, String subdirectory)
{
if (client.getGameState() == GameState.LOGIN_SCREEN)
{
// Prevent the screenshot from being captured
log.info("Login screenshot prevented");
return;
}
Consumer<Image> imageCallback = (img) ->
{
// This callback is on the game thread, move to executor thread
executor.submit(() -> takeScreenshot(fileName, img, subdirectory));
};
if (config.displayDate())
{
screenshotOverlay.queueForTimestamp(imageCallback);
}
else
{
drawManager.requestNextFrameListener(imageCallback);
}
}
private void takeScreenshot(String fileName, Image image, @Nullable String subdirectory)
{ {
BufferedImage screenshot = config.includeFrame() BufferedImage screenshot = config.includeFrame()
? new BufferedImage(clientUi.getWidth(), clientUi.getHeight(), BufferedImage.TYPE_INT_ARGB) ? new BufferedImage(clientUi.getWidth(), clientUi.getHeight(), BufferedImage.TYPE_INT_ARGB)
@@ -644,6 +734,14 @@ public class ScreenshotPlugin extends Plugin
playerFolder.mkdirs(); playerFolder.mkdirs();
if (subdirectory != null)
{
//uhh just tried to do this as workaround, not sure if it's the best idea tho
File actualplayerFolder = new File(playerFolder, subdirectory);
actualplayerFolder.mkdir();
playerFolder = actualplayerFolder;
}
try try
{ {
File screenshotFile = new File(playerFolder, fileName + ".png"); File screenshotFile = new File(playerFolder, fileName + ".png");

View File

@@ -67,4 +67,3 @@ public class VanguardPlugin extends Plugin
} }