Merge pull request #13138 from williameschmidt/Issue_13137_Valuable_Drop_Screenshot_Minimum_Value_Threshold

Add independent valuable drop screenshot minimum value threshold
This commit is contained in:
Jordan
2021-02-06 23:15:35 +00:00
committed by GitHub
3 changed files with 48 additions and 9 deletions

View File

@@ -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()
{

View File

@@ -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: <col=ff0000>(\\d+)</col>.");
private static final Pattern VALUABLE_DROP_PATTERN = Pattern.compile(".*Valuable drop: ([^<>]+)(?:</col>)?");
private static final Pattern VALUABLE_DROP_PATTERN = Pattern.compile(".*Valuable drop: ([^<>]+?\\(((?:\\d+,?)+) coins\\))(?:</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 QUEST_PATTERN_1 = Pattern.compile(".+?ve\\.*? (?<verb>been|rebuilt|.+?ed)? ?(?:the )?'?(?<quest>.+?)'?(?: [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");
}
}
}

View File

@@ -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 <col=ff0000>310</col>";
private static final String CHAMBERS_OF_XERIC_CHEST = "Your completed Chambers of Xeric count is: <col=ff0000>489</col>.";
private static final String THEATRE_OF_BLOOD_CHEST = "Your completed Theatre of Blood count is: <col=ff0000>73</col>.";
private static final String VALUABLE_DROP = "<col=ef1020>Valuable drop: 6 x Bronze arrow (42 coins)</col>";
private static final String NOT_SO_VALUABLE_DROP = "<col=ef1020>Valuable drop: 6 x Bronze arrow (42 coins)</col>";
private static final String VALUABLE_DROP = "<col=ef1020>Valuable drop: Rune scimitar (25,600 coins)</col>";
private static final String UNTRADEABLE_DROP = "<col=ef1020>Untradeable drop: Rusty sword";
private static final String BA_HIGH_GAMBLE_REWARD = "Raw shark (x 300)!<br>High level gamble count: <col=7f0000>100</col>";
private static final String HUNTER_LEVEL_2_TEXT = "<col=000080>Congratulations, you've just advanced a Hunter level.<col=000000><br><br>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));