ScreenshotPlugin extends Plugin { @Subscribe public void onChatMessage(ChatMessage event) { if (event.getType() != ChatMessageType.GAMEMESSAGE && event.getType() != ChatMessageType.SPAM && event.getType() != ChatMessageType.TRADE && event.getType() != ChatMessageType.FRIENDSCHATNOTIFICATION) { return; } String chatMessage = event.getMessage(); if (chatMessage.contains("You have completed") && chatMessage.contains("Treasure")) { Matcher m = NUMBER_PATTERN.matcher(Text.removeTags(chatMessage)); if (m.find()) { clueNumber = Integer.valueOf(m.group()); clueType = chatMessage.substring(chatMessage.lastIndexOf(m.group()) + m.group().length() + 1, chatMessage.indexOf("Treasure") - 1); return; } } if (chatMessage.startsWith("Your Barrows chest count is")) { Matcher m = NUMBER_PATTERN.matcher(Text.removeTags(chatMessage)); if (m.find()) { barrowsNumber = Integer.valueOf(m.group()); return; } } if (chatMessage.startsWith("Your completed Chambers of Xeric count is:")) { Matcher m = NUMBER_PATTERN.matcher(Text.removeTags(chatMessage)); if (m.find()) { chambersOfXericNumber = Integer.valueOf(m.group()); return; } } if (chatMessage.startsWith("Your completed Chambers of Xeric Challenge Mode count is:")) { Matcher m = NUMBER_PATTERN.matcher(Text.removeTags(chatMessage)); if (m.find()) { chambersOfXericChallengeNumber = Integer.valueOf(m.group()); return; } } if (chatMessage.startsWith("Your completed Theatre of Blood count is:")) { Matcher m = NUMBER_PATTERN.matcher(Text.removeTags(chatMessage)); if (m.find()) { theatreOfBloodNumber = Integer.valueOf(m.group()); return; } } if (config.screenshotKick() && chatMessage.equals("Your request to kick/ban this user was successful.")) { if (kickPlayerName == null) { return; } takeScreenshot("Kick " + kickPlayerName, "Friends Chat Kicks"); kickPlayerName = null; } if (config.screenshotPet() && PET_MESSAGES.stream().anyMatch(chatMessage::contains)) { String fileName = "Pet"; takeScreenshot(fileName, "Pets"); } if (config.screenshotBossKills()) { Matcher m = BOSSKILL_MESSAGE_PATTERN.matcher(chatMessage); if (m.matches()) { String bossName = m.group(1); String bossKillcount = m.group(2); String fileName = bossName + "(" + bossKillcount + ")"; takeScreenshot(fileName, "Boss Kills"); } } if (chatMessage.equals(CHEST_LOOTED_MESSAGE) && config.screenshotRewards()) { final int regionID = client.getLocalPlayer().getWorldLocation().getRegionID(); String eventName = CHEST_LOOT_EVENTS.get(regionID); if (eventName != null) { takeScreenshot(eventName, "Chest Loot"); } } if (config.screenshotValuableDrop()) { Matcher m = VALUABLE_DROP_PATTERN.matcher(chatMessage); if (m.matches()) { String valuableDropName = m.group(1); String fileName = "Valuable drop " + valuableDropName; takeScreenshot(fileName, "Valuable Drops"); } } if (config.screenshotUntradeableDrop() && !isInsideGauntlet()) { Matcher m = UNTRADEABLE_DROP_PATTERN.matcher(chatMessage); if (m.matches()) { String untradeableDropName = m.group(1); String fileName = "Untradeable drop " + untradeableDropName; takeScreenshot(fileName, "Untradeable Drops"); } } if (config.screenshotDuels()) { Matcher m = DUEL_END_PATTERN.matcher(chatMessage); if (m.find()) { String result = m.group(1); String count = m.group(2); String fileName = "Duel " + result + " (" + count + ")"; takeScreenshot(fileName, "Duels"); } } }  @Subscribe void onGameTick(GameTick event); @Subscribe void onActorDeath(ActorDeath actorDeath); @Subscribe void onPlayerLootReceived(final PlayerLootReceived playerLootReceived); @Subscribe void onScriptCallbackEvent(ScriptCallbackEvent e); @Subscribe void onChatMessage(ChatMessage event); @Subscribe void onWidgetLoaded(WidgetLoaded event);  }
@Test public void testValuableDrop() { ChatMessage chatMessageEvent = new ChatMessage(null, GAMEMESSAGE, "", VALUABLE_DROP, null, 0); screenshotPlugin.onChatMessage(chatMessageEvent); verify(drawManager).requestNextFrameListener(any(Consumer.class)); }
@Test public void testUntradeableDrop() { ChatMessage chatMessageEvent = new ChatMessage(null, GAMEMESSAGE, "", UNTRADEABLE_DROP, null, 0); screenshotPlugin.onChatMessage(chatMessageEvent); verify(drawManager).requestNextFrameListener(any(Consumer.class)); }