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,11 +111,12 @@ 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",
description = "Enable the manual and automatic taking of screenshots", description = "Enable the manual and automatic taking of screenshots",
tags = {"external", "images", "imgur", "integration", "notifications"} tags = {"external", "images", "imgur", "integration", "notifications"}
) )
@Slf4j @Slf4j
public class ScreenshotPlugin extends Plugin public class ScreenshotPlugin extends Plugin
@@ -127,8 +134,8 @@ public class ScreenshotPlugin extends Plugin
private static final Pattern UNTRADEABLE_DROP_PATTERN = Pattern.compile(".*Untradeable drop: ([^<>]+)(?:</col>)?"); private static final Pattern UNTRADEABLE_DROP_PATTERN = Pattern.compile(".*Untradeable drop: ([^<>]+)(?:</col>)?");
private static final Pattern DUEL_END_PATTERN = Pattern.compile("You have now (won|lost) ([0-9]+) duels?\\."); private static final Pattern DUEL_END_PATTERN = Pattern.compile("You have now (won|lost) ([0-9]+) duels?\\.");
private static final ImmutableList<String> PET_MESSAGES = ImmutableList.of("You have a funny feeling like you're being followed", private static final ImmutableList<String> PET_MESSAGES = ImmutableList.of("You have a funny feeling like you're being followed",
"You feel something weird sneaking into your backpack", "You feel something weird sneaking into your backpack",
"You have a funny feeling like you would have been followed"); "You have a funny feeling like you would have been followed");
static String format(Date date) static String format(Date date)
{ {
@@ -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())
@@ -214,25 +223,25 @@ public class ScreenshotPlugin extends Plugin
final BufferedImage iconImage = ImageUtil.getResourceStreamFromClass(getClass(), "screenshot.png"); final BufferedImage iconImage = ImageUtil.getResourceStreamFromClass(getClass(), "screenshot.png");
titleBarButton = NavigationButton.builder() titleBarButton = NavigationButton.builder()
.tab(false) .tab(false)
.tooltip("Take screenshot") .tooltip("Take screenshot")
.icon(iconImage) .icon(iconImage)
.onClick(() -> takeScreenshot(format(new Date()))) .onClick(() -> takeScreenshot(format(new Date())))
.popup(ImmutableMap .popup(ImmutableMap
.<String, Runnable>builder() .<String, Runnable>builder()
.put("Open screenshot folder...", () -> .put("Open screenshot folder...", () ->
{ {
try try
{ {
Desktop.getDesktop().open(SCREENSHOT_DIR); Desktop.getDesktop().open(SCREENSHOT_DIR);
} }
catch (IOException ex) catch (IOException ex)
{ {
log.warn("Error opening screenshot dir", ex); log.warn("Error opening screenshot dir", ex);
} }
}) })
.build()) .build())
.build(); .build();
clientToolbar.addNavigation(titleBarButton); clientToolbar.addNavigation(titleBarButton);
} }
@@ -249,7 +258,7 @@ public class ScreenshotPlugin extends Plugin
public void onGameStateChanged(GameStateChanged event) public void onGameStateChanged(GameStateChanged event)
{ {
if (event.getGameState() == GameState.LOGGED_IN if (event.getGameState() == GameState.LOGGED_IN
&& reportButton == null) && reportButton == null)
{ {
reportButton = spriteManager.getSprite(SpriteID.CHATBOX_REPORT_BUTTON, 0); reportButton = spriteManager.getSprite(SpriteID.CHATBOX_REPORT_BUTTON, 0);
} }
@@ -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)
{ {
if (config.screenshotPlayerDeath()) //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)
{ {
takeScreenshot("Death " + format(new Date())); return;
}
if (p.getName().equals(client.getLocalPlayer().getName()))
{
if (config.screenshotPlayerDeath())
{
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);
}
} }
} }
@@ -375,7 +433,7 @@ public class ScreenshotPlugin extends Plugin
takeScreenshot(fileName); takeScreenshot(fileName);
} }
if (config.screenshotBossKills()) if (config.screenshotBossKills() )
{ {
Matcher m = BOSSKILL_MESSAGE_PATTERN.matcher(chatMessage); Matcher m = BOSSKILL_MESSAGE_PATTERN.matcher(chatMessage);
if (m.matches()) if (m.matches())
@@ -562,7 +620,7 @@ public class ScreenshotPlugin extends Plugin
* Saves a screenshot of the client window to the screenshot folder as a PNG, * Saves a screenshot of the client window to the screenshot folder as a PNG,
* and optionally uploads it to an image-hosting service. * and optionally uploads it to an image-hosting service.
* *
* @param fileName Filename to use, without file extension. * @param fileName Filename to use, without file extension.
*/ */
private void takeScreenshot(String fileName) private void takeScreenshot(String fileName)
{ {
@@ -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,11 +647,43 @@ 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)
: new BufferedImage(image.getWidth(null), image.getHeight(null), BufferedImage.TYPE_INT_ARGB); : new BufferedImage(image.getWidth(null), image.getHeight(null), BufferedImage.TYPE_INT_ARGB);
Graphics graphics = screenshot.getGraphics(); Graphics graphics = screenshot.getGraphics();
@@ -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");
@@ -677,10 +775,10 @@ public class ScreenshotPlugin extends Plugin
String json = RuneLiteAPI.GSON.toJson(new ImageUploadRequest(screenshotFile)); String json = RuneLiteAPI.GSON.toJson(new ImageUploadRequest(screenshotFile));
Request request = new Request.Builder() Request request = new Request.Builder()
.url(IMGUR_IMAGE_UPLOAD_URL) .url(IMGUR_IMAGE_UPLOAD_URL)
.addHeader("Authorization", "Client-ID " + IMGUR_CLIENT_ID) .addHeader("Authorization", "Client-ID " + IMGUR_CLIENT_ID)
.post(RequestBody.create(JSON, json)) .post(RequestBody.create(JSON, json))
.build(); .build();
RuneLiteAPI.CLIENT.newCall(request).enqueue(new Callback() RuneLiteAPI.CLIENT.newCall(request).enqueue(new Callback()
{ {
@@ -696,7 +794,7 @@ public class ScreenshotPlugin extends Plugin
try (InputStream in = response.body().byteStream()) try (InputStream in = response.body().byteStream())
{ {
ImageUploadResponse imageUploadResponse = RuneLiteAPI.GSON ImageUploadResponse imageUploadResponse = RuneLiteAPI.GSON
.fromJson(new InputStreamReader(in), ImageUploadResponse.class); .fromJson(new InputStreamReader(in), ImageUploadResponse.class);
if (imageUploadResponse.isSuccess()) if (imageUploadResponse.isSuccess())
{ {

View File

@@ -6,10 +6,10 @@
* modification, are permitted provided that the following conditions are met: * modification, are permitted provided that the following conditions are met:
* *
* 1. Redistributions of source code must retain the above copyright notice, this * 1. Redistributions of source code must retain the above copyright notice, this
* list of conditions and the following disclaimer. * list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright notice, * 2. Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation * this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution. * and/or other materials provided with the distribution.
* *
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED

View File

@@ -6,10 +6,10 @@
* modification, are permitted provided that the following conditions are met: * modification, are permitted provided that the following conditions are met:
* *
* 1. Redistributions of source code must retain the above copyright notice, this * 1. Redistributions of source code must retain the above copyright notice, this
* list of conditions and the following disclaimer. * list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright notice, * 2. Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation * this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution. * and/or other materials provided with the distribution.
* *
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
@@ -31,11 +31,11 @@ import net.runelite.client.plugins.PluginType;
import net.runelite.client.ui.overlay.OverlayManager; import net.runelite.client.ui.overlay.OverlayManager;
@PluginDescriptor( @PluginDescriptor(
name = "Vanguard HP Overlay", name = "Vanguard HP Overlay",
description = "tracks HP of all three vanguards", description = "tracks HP of all three vanguards",
tags = {"overlay", "vangs", "cox"}, tags = {"overlay", "vangs", "cox"},
enabledByDefault = false, enabledByDefault = false,
type = PluginType.PVM type = PluginType.PVM
) )
public class VanguardPlugin extends Plugin public class VanguardPlugin extends Plugin
{ {
@@ -67,4 +67,3 @@ public class VanguardPlugin extends Plugin
} }