From 37838ac836db6d8c98f2c776c1b2e537c83dcd85 Mon Sep 17 00:00:00 2001 From: Liam Schmidt Date: Mon, 1 Feb 2021 21:33:52 -0500 Subject: [PATCH] screenshot: Add valuable drop threshold config --- .../plugins/screenshot/ScreenshotConfig.java | 20 ++++++++++++--- .../plugins/screenshot/ScreenshotPlugin.java | 12 ++++++--- .../screenshot/ScreenshotPluginTest.java | 25 ++++++++++++++++++- 3 files changed, 48 insertions(+), 9 deletions(-) diff --git a/runelite-client/src/main/java/net/runelite/client/plugins/screenshot/ScreenshotConfig.java b/runelite-client/src/main/java/net/runelite/client/plugins/screenshot/ScreenshotConfig.java index 269eb8554a..44d9d58b51 100644 --- a/runelite-client/src/main/java/net/runelite/client/plugins/screenshot/ScreenshotConfig.java +++ b/runelite-client/src/main/java/net/runelite/client/plugins/screenshot/ScreenshotConfig.java @@ -205,11 +205,23 @@ public interface ScreenshotConfig extends Config return false; } + @ConfigItem( + keyName = "valuableDropThreshold", + name = "Valuable Threshold", + description = "The minimum value to save screenshots of valuable drops.", + position = 14, + section = whatSection + ) + default int valuableDropThreshold() + { + return 0; + } + @ConfigItem( keyName = "untradeableDrop", name = "Screenshot Untradeable drops", description = "Configures whether or not screenshots are automatically taken when you receive an untradeable drop.", - position = 14, + position = 15, section = whatSection ) default boolean screenshotUntradeableDrop() @@ -221,7 +233,7 @@ public interface ScreenshotConfig extends Config keyName = "ccKick", name = "Screenshot Kicks from FC", description = "Take a screenshot when you kick a user from a friends chat.", - position = 15, + position = 16, section = whatSection ) default boolean screenshotKick() @@ -233,7 +245,7 @@ public interface ScreenshotConfig extends Config keyName = "baHighGamble", name = "Screenshot BA high gambles", description = "Take a screenshot of your reward from a high gamble at Barbarian Assault.", - position = 16, + position = 17, section = whatSection ) default boolean screenshotHighGamble() @@ -245,7 +257,7 @@ public interface ScreenshotConfig extends Config keyName = "hotkey", name = "Screenshot hotkey", description = "When you press this key a screenshot will be taken", - position = 17 + position = 18 ) default Keybind hotkey() { diff --git a/runelite-client/src/main/java/net/runelite/client/plugins/screenshot/ScreenshotPlugin.java b/runelite-client/src/main/java/net/runelite/client/plugins/screenshot/ScreenshotPlugin.java index b199248c39..0dada91ae6 100644 --- a/runelite-client/src/main/java/net/runelite/client/plugins/screenshot/ScreenshotPlugin.java +++ b/runelite-client/src/main/java/net/runelite/client/plugins/screenshot/ScreenshotPlugin.java @@ -99,7 +99,7 @@ public class ScreenshotPlugin extends Plugin private static final Pattern NUMBER_PATTERN = Pattern.compile("([0-9]+)"); private static final Pattern LEVEL_UP_PATTERN = Pattern.compile(".*Your ([a-zA-Z]+) (?:level is|are)? now (\\d+)\\."); private static final Pattern BOSSKILL_MESSAGE_PATTERN = Pattern.compile("Your (.+) kill count is: (\\d+)."); - private static final Pattern VALUABLE_DROP_PATTERN = Pattern.compile(".*Valuable drop: ([^<>]+)(?:)?"); + private static final Pattern VALUABLE_DROP_PATTERN = Pattern.compile(".*Valuable drop: ([^<>]+?\\(((?:\\d+,?)+) coins\\))(?:)?"); private static final Pattern UNTRADEABLE_DROP_PATTERN = Pattern.compile(".*Untradeable drop: ([^<>]+)(?:)?"); private static final Pattern DUEL_END_PATTERN = Pattern.compile("You have now (won|lost) ([0-9]+) duels?\\."); private static final Pattern QUEST_PATTERN_1 = Pattern.compile(".+?ve\\.*? (?been|rebuilt|.+?ed)? ?(?:the )?'?(?.+?)'?(?: [Qq]uest)?[!.]?$"); @@ -417,9 +417,13 @@ public class ScreenshotPlugin extends Plugin Matcher m = VALUABLE_DROP_PATTERN.matcher(chatMessage); if (m.matches()) { - String valuableDropName = m.group(1); - String fileName = "Valuable drop " + valuableDropName; - takeScreenshot(fileName, "Valuable Drops"); + int valuableDropValue = Integer.parseInt(m.group(2).replaceAll(",", "")); + if (valuableDropValue >= config.valuableDropThreshold()) + { + String valuableDropName = m.group(1); + String fileName = "Valuable drop " + valuableDropName; + takeScreenshot(fileName, "Valuable Drops"); + } } } diff --git a/runelite-client/src/test/java/net/runelite/client/plugins/screenshot/ScreenshotPluginTest.java b/runelite-client/src/test/java/net/runelite/client/plugins/screenshot/ScreenshotPluginTest.java index 5386db8202..edd5101817 100644 --- a/runelite-client/src/test/java/net/runelite/client/plugins/screenshot/ScreenshotPluginTest.java +++ b/runelite-client/src/test/java/net/runelite/client/plugins/screenshot/ScreenshotPluginTest.java @@ -57,6 +57,7 @@ import org.mockito.Mock; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.times; import static org.mockito.Mockito.verify; +import static org.mockito.Mockito.verifyNoInteractions; import static org.mockito.Mockito.when; import org.mockito.junit.MockitoJUnitRunner; @@ -67,7 +68,8 @@ public class ScreenshotPluginTest private static final String BARROWS_CHEST = "Your Barrows chest count is 310"; private static final String CHAMBERS_OF_XERIC_CHEST = "Your completed Chambers of Xeric count is: 489."; private static final String THEATRE_OF_BLOOD_CHEST = "Your completed Theatre of Blood count is: 73."; - private static final String VALUABLE_DROP = "Valuable drop: 6 x Bronze arrow (42 coins)"; + private static final String NOT_SO_VALUABLE_DROP = "Valuable drop: 6 x Bronze arrow (42 coins)"; + private static final String VALUABLE_DROP = "Valuable drop: Rune scimitar (25,600 coins)"; private static final String UNTRADEABLE_DROP = "Untradeable drop: Rusty sword"; private static final String BA_HIGH_GAMBLE_REWARD = "Raw shark (x 300)!
High level gamble count: 100"; private static final String HUNTER_LEVEL_2_TEXT = "Congratulations, you've just advanced a Hunter level.

Your Hunter level is now 2."; @@ -121,6 +123,7 @@ public class ScreenshotPluginTest Guice.createInjector(BoundFieldModule.of(this)).injectMembers(this); when(screenshotConfig.screenshotLevels()).thenReturn(true); when(screenshotConfig.screenshotValuableDrop()).thenReturn(true); + when(screenshotConfig.valuableDropThreshold()).thenReturn(1000); when(screenshotConfig.screenshotUntradeableDrop()).thenReturn(true); } @@ -161,10 +164,30 @@ public class ScreenshotPluginTest assertEquals(73, screenshotPlugin.gettheatreOfBloodNumber()); } + @Test + public void testNotSoValuableDrop() + { + ChatMessage chatMessageEvent = new ChatMessage(null, GAMEMESSAGE, "", NOT_SO_VALUABLE_DROP, null, 0); + screenshotPlugin.onChatMessage(chatMessageEvent); + + verifyNoInteractions(drawManager); + + when(screenshotConfig.valuableDropThreshold()).thenReturn(0); + screenshotPlugin.onChatMessage(chatMessageEvent); + + verify(drawManager).requestNextFrameListener(any(Consumer.class)); + } + @Test public void testValuableDrop() { ChatMessage chatMessageEvent = new ChatMessage(null, GAMEMESSAGE, "", VALUABLE_DROP, null, 0); + when(screenshotConfig.valuableDropThreshold()).thenReturn(100_000); + screenshotPlugin.onChatMessage(chatMessageEvent); + + verifyNoInteractions(drawManager); + + when(screenshotConfig.valuableDropThreshold()).thenReturn(1000); screenshotPlugin.onChatMessage(chatMessageEvent); verify(drawManager).requestNextFrameListener(any(Consumer.class));